12 lines
No EOL
551 B
JavaScript
12 lines
No EOL
551 B
JavaScript
function validateFile(file) {
|
|
const MAX_SIZE = 50 * 1024 * 1024; // 50MiB
|
|
const filenameRegex = /^(?!\s)(?!.*\s$)[^<>:"/\\|?*\x00-\x1F]+\.(?!\.)[^<>:"/\\|?*\x00-\x1F]{1,4}$|^(?!\s)(?!.*\s$)[^<>:"/\\|?*\x00-\x1F]+$/;
|
|
|
|
if (!file) return { valid: false, reason: 'No file provided' };
|
|
if (file.size > MAX_SIZE) return { valid: false, reason: 'The file is too big. (Max is 50MiB)' };
|
|
if (!filenameRegex.test(file.originalname)) return { valid: false, reason: 'Invalid filename.' };
|
|
|
|
return { valid: true };
|
|
}
|
|
|
|
module.exports = { validateFile }; |