thanks 7666

This commit is contained in:
localhost 2023-07-17 23:46:47 +03:00
parent 8e85f9b8b5
commit 3804b519ba
1 changed files with 14 additions and 14 deletions

View File

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