fix(Media): don't resize videos

This commit is contained in:
Matthieu Bessat 2020-09-02 22:56:42 +02:00
parent 89819885d6
commit e6383d64c8

View file

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