thanks 7666

This commit is contained in:
localhost 2023-07-17 23:20:49 +03:00
parent e643c68f7f
commit 54713eeadf
1 changed files with 13 additions and 13 deletions

View File

@ -4,38 +4,38 @@ const fs = require('node:fs')
const keys = require('../s3.json')
async function uploadVideo(video) {
const items = keys.videos
const key = items[Math.floor(Math.random() * items.length)]
const key = keys.videos[0]
const s3 = new AWS.S3({
accessKeyId: key.access,
secretAccessKey: key.secret,
endpoint: 'https://gateway.storjshare.io'
endpoint: keys.endpoint,
s3ForcePathStyle: true
})
const videoFile = fs.createReadStream(video)
await s3.upload({
Bucket: 'video',
const uploaded = await s3.upload({
Bucket: key.bucket,
Key: video.split('/')[2],
Body: videoFile,
ContentType: 'video/webm',
}).promise()
return `${key.url}${video.split('/')[2]}`
return uploaded.Location
}
async function uploadImage(id, url) {
const items = keys.images
const key = items[Math.floor(Math.random() * items.length)]
const key = keys.images[0]
const s3 = new AWS.S3({
accessKeyId: key.access,
secretAccessKey: key.secret,
endpoint: 'https://gateway.storjshare.io'
endpoint: keys.endpoint,
s3ForcePathStyle: true
})
const exists = await checkIfFileExists({
Bucket: 'media',
Bucket: key.bucket,
Key: `${id}.webp`
}, s3)
@ -45,14 +45,14 @@ async function uploadImage(id, url) {
const response = await fetch(url)
const buffer = Buffer.from(await response.arrayBuffer())
await s3.upload({
Bucket: 'media',
const uploaded = await s3.upload({
Bucket: key.bucket,
Key: `${id}.webp`,
Body: buffer,
ContentType: 'video/webp',
}).promise()
return `${key.url}${id}.webp`
return uploaded.Location
}
}