From e6383d64c8f5dbf670f3381b2069d65df30d346b Mon Sep 17 00:00:00 2001 From: Matthieu Bessat Date: Wed, 2 Sep 2020 22:56:42 +0200 Subject: [PATCH] fix(Media): don't resize videos --- src/MediaService.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/MediaService.ts b/src/MediaService.ts index 88911f5..ee98829 100644 --- a/src/MediaService.ts +++ b/src/MediaService.ts @@ -46,6 +46,9 @@ export default class MediaService { } static multer(type: string, multiple: boolean = false) { + // I whished I had a more simple a reliable way to do it + // it's a global variable + let isVideo: boolean = false let instance = multer({ storage: multerS3({ s3: MediaService.getS3(), @@ -53,6 +56,8 @@ export default class MediaService { acl: 'public-read', contentType: multerS3.AUTO_CONTENT_TYPE, transforms: () => { + // don't transform a video + if (isVideo) { return null } let transformOptions = {} let quality = 80 if (type === 'media') { @@ -76,7 +81,9 @@ export default class MediaService { key: (_: any, file: any, cb: any) => { // generate a random id for this image let r = Math.random().toString(36).substring(4).toUpperCase() - console.log(r, file) + // special string from the frontend to kown if it is a video + isVideo = file.originalname.indexOf('||%_FORMAT_VIDEO_%||') !== -1 + console.log(r, file, isVideo) cb(null, r + '_' + type) } }) @@ -94,8 +101,9 @@ export default class MediaService { location: file.location.replace('http://', 'https://'), // @ts-ignore size: file.size, + // we will remove the special substr from the front end // @ts-ignore - originalFileName: file.originalname, + originalFileName: file.originalname.replace('||%_FORMAT_VIDEO_%||', ''), type: type === 'media' ? file.contentType.split('/')[0] : type } }