Removed these again

pull/125/head
tycrek 3 years ago
parent a37577bb35
commit 5b88d5e585
No known key found for this signature in database
GPG Key ID: 25D74F3943625263

@ -34,7 +34,7 @@ function getDatedDirname() {
} }
function getLocalFilename(req: Request) { function getLocalFilename(req: Request) {
return `${getDatedDirname()}/${saveAsOriginal ? req.file!.originalname : req.file.sha1}`; return `${getDatedDirname()}/${saveAsOriginal ? req.file.originalname : req.file.sha1}`;
} }
export function processUploaded(req: Request, res: Response, next: Function) { // skipcq: JS-0045 export function processUploaded(req: Request, res: Response, next: Function) { // skipcq: JS-0045
@ -42,9 +42,9 @@ export function processUploaded(req: Request, res: Response, next: Function) { /
req.file = req.files.file; req.file = req.files.file;
// Other fixes // Other fixes
req.file!.ext = '.'.concat((req.file.filename ?? '').split('.').pop() ?? ''); req.file.ext = '.'.concat((req.file.filename ?? '').split('.').pop() ?? '');
req.file!.originalname = req.file.filename ?? ''; req.file.originalname = req.file.filename ?? '';
req.file!.path = req.file.file ?? ''; req.file.path = req.file.file ?? '';
req.file.randomId = generateId('random', ID_GEN_LENGTH, 0, ''); req.file.randomId = generateId('random', ID_GEN_LENGTH, 0, '');
req.file.deleteId = generateId('random', ID_GEN_LENGTH, 0, ''); req.file.deleteId = generateId('random', ID_GEN_LENGTH, 0, '');
@ -57,13 +57,13 @@ export function processUploaded(req: Request, res: Response, next: Function) { /
}; };
// Specify correct type // Specify correct type
const isType = req.file!.mimetype.includes('image') ? 'image' : req.file!.mimetype.includes('video') ? 'video' : req.file.mimetype.includes('audio') ? 'audio' : 'other'; const isType = req.file!.mimetype.includes('image') ? 'image' : req.file.mimetype.includes('video') ? 'video' : req.file.mimetype.includes('audio') ? 'audio' : 'other';
req.file.is[isType] = true; req.file.is[isType] = true;
// Block the resource if the mimetype is not an image or video // Block the resource if the mimetype is not an image or video
if (mediaStrict && !ALLOWED_MIMETYPES.test(req.file.mimetype)) if (mediaStrict && !ALLOWED_MIMETYPES.test(req.file.mimetype))
return log return log
.warn('Upload blocked', req.file!.originalname, req.file.mimetype) .warn('Upload blocked', req.file.originalname, req.file.mimetype)
.warn('Strict media mode', 'only images, videos, & audio are file permitted') .warn('Strict media mode', 'only images, videos, & audio are file permitted')
.callback(() => .callback(() =>
fs.remove(req.file.path) fs.remove(req.file.path)
@ -105,7 +105,7 @@ export function processUploaded(req: Request, res: Response, next: Function) { /
// Upload to Amazon S3 // Upload to Amazon S3
if (s3enabled) return s3.putObject({ if (s3enabled) return s3.putObject({
Bucket: s3bucket, Bucket: s3bucket,
Key: req.file!.randomId.concat(req.file.ext), Key: req.file.randomId.concat(req.file.ext),
ACL: 'public-read', ACL: 'public-read',
ContentType: req.file.mimetype, ContentType: req.file.mimetype,
Body: fs.createReadStream(req.file.path) Body: fs.createReadStream(req.file.path)

Loading…
Cancel
Save