From 54713eeadf50beed6bb05cb1fa94674d83a4ba67 Mon Sep 17 00:00:00 2001 From: localhost Date: Mon, 17 Jul 2023 23:20:49 +0300 Subject: [PATCH] thanks 7666 --- utils/upload.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/utils/upload.js b/utils/upload.js index 070d5bd..ee3acef 100644 --- a/utils/upload.js +++ b/utils/upload.js @@ -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 } }