improved type concat to fix video embeds via S3

pull/18/head
tycrek 3 years ago
parent 7e5aba7fdb
commit f525cc2f13
No known key found for this signature in database
GPG Key ID: 25D74F3943625263

@ -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);
}),

@ -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,

@ -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');

@ -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)

@ -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' : ''}`;
}

Loading…
Cancel
Save