Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports = function uploadValidation(req, res, next) {
const extensions = ['.zip'];
const contentTypes = ['application/zip', 'application/x-zip-compressed', 'application/octet-stream'];
req.file = req.file || {};
req.file.name = req.file.originalname;
req.file.type = req.file.mimetype;
if (!checkFileExists(req.file)) {
return next(new errors.ValidationError({
message: `"Please select a zip file.`
}));
}
req.file.ext = path.extname(req.file.name).toLowerCase();
if (!checkFileIsValid(req.file, contentTypes, extensions)) {
return next(new errors.UnsupportedMediaTypeError({
message: 'Please select a valid zip file.'
}));
}
next();
};