From f525cc2f133d72f6b4b44eff8ffc7db0f322a5ff Mon Sep 17 00:00:00 2001 From: tycrek Date: Thu, 17 Jun 2021 01:07:00 -0600 Subject: [PATCH] improved type concat to fix video embeds via S3 --- ass.js | 2 +- ogp.js | 2 +- storage.js | 2 +- thumbnails.js | 2 +- utils.js | 6 +++--- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ass.js b/ass.js index 37308be..211ce59 100755 --- a/ass.js +++ b/ass.js @@ -225,7 +225,7 @@ function startup() { // Return the file differently depending on what storage option was used let uploaders = { - s3: () => fetch(getS3url(fileData.randomId)).then((file) => { + s3: () => fetch(getS3url(fileData.randomId, fileData.mimetype)).then((file) => { file.headers.forEach((value, header) => res.setHeader(header, value)); file.body.pipe(res); }), diff --git a/ogp.js b/ogp.js index ea8ea1d..e0972fd 100644 --- a/ogp.js +++ b/ogp.js @@ -41,7 +41,7 @@ class OpenGraph { } build() { - let resourceUrl = !s3enabled ? (this.http + this.domain + "/" + this.resourceId + (this.type.includes('video') ? '.mp4' : this.type.includes('gif') ? '.gif' : '')) : getS3url(this.randomId); + let resourceUrl = !s3enabled ? (this.http + this.domain + "/" + this.resourceId + (this.type.includes('video') ? '.mp4' : this.type.includes('gif') ? '.gif' : '')) : getS3url(this.randomId, this.type); return Mustache.render(html, { homepage, version, diff --git a/storage.js b/storage.js index 8addc20..30a9cb2 100644 --- a/storage.js +++ b/storage.js @@ -17,7 +17,7 @@ const uploadS3 = multer({ s3: s3, bucket: s3bucket, acl: 'public-read', - key: (req, _file, cb) => cb(null, req.randomId), + key: (req, file, cb) => cb(null, req.randomId.concat(file.mimetype.includes('video') ? '.mp4' : file.mimetype.includes('gif') ? '.gif' : '')), contentType: (_req, file, cb) => cb(null, file.mimetype) }) }).single('file'); diff --git a/thumbnails.js b/thumbnails.js index 981035f..e4dac1c 100644 --- a/thumbnails.js +++ b/thumbnails.js @@ -25,7 +25,7 @@ function getVideoThumbnail(file) { function getResizedThumbnail(file) { return new Promise((resolve, reject) => - Jimp.read(s3enabled ? getS3url(file.randomId) : path(file.path)) + Jimp.read(s3enabled ? getS3url(file.randomId, file.mimetype) : path(file.path)) .then((image) => image .quality(THUMBNAIL_QUALITY) .resize(THUMBNAIL_SIZE, THUMBNAIL_SIZE, Jimp.RESIZE_BICUBIC) diff --git a/utils.js b/utils.js index f112ebd..beab62d 100755 --- a/utils.js +++ b/utils.js @@ -41,12 +41,12 @@ module.exports = { }, arrayEquals: (arr1, arr2) => arr1.length === arr2.length && arr1.slice().sort().every((value, index) => value === arr2.slice().sort()[index]), downloadTempS3: (file) => new Promise((resolve, reject) => - fetch(getS3url(file.randomId)) + fetch(getS3url(file.randomId, file.mimetype)) .then((f2) => f2.body.pipe(fs.createWriteStream(Path.join(__dirname, 'uploads/', file.originalname)).on('close', () => resolve()))) .catch(reject)), getS3url, } -function getS3url(s3key) { - return `https://${s3bucket}.${s3endpoint}/${s3key}`; +function getS3url(s3key, type) { + return `https://${s3bucket}.${s3endpoint}/${s3key}${type.includes('video') ? '.mp4' : type.includes('gif') ? '.gif' : ''}`; }