initial commit

This commit is contained in:
root
2026-05-13 14:20:41 +00:00
commit 6e178d2012
6022 changed files with 399872 additions and 0 deletions
+51
View File
@@ -0,0 +1,51 @@
const ALLOWED_MIME_TYPES = new Set([
'image/jpeg',
'image/jpg',
'image/png',
'image/gif',
'image/webp',
]);
const MAX_FILE_SIZE = 10 * 1024 * 1024; // 10 MB
export function validateImage(req, res, next) {
const file = req.file;
if (!file) {
return res.status(400).json({
ok: false,
error: 'BAD_REQUEST',
message: 'Файл не предоставлен',
});
}
if (!ALLOWED_MIME_TYPES.has(file.mimetype)) {
return res.status(400).json({
ok: false,
error: 'INVALID_FILE_TYPE',
message: `Недопустимый тип файла. Разрешены: JPEG, PNG, GIF, WebP`,
});
}
if (file.size > MAX_FILE_SIZE) {
return res.status(400).json({
ok: false,
error: 'FILE_TOO_LARGE',
message: `Файл слишком большой. Максимум: ${MAX_FILE_SIZE / 1024 / 1024}MB`,
});
}
const filename = file.originalname || file.filename;
const ext = filename.split('.').pop().toLowerCase();
const validExtensions = ['jpg', 'jpeg', 'png', 'gif', 'webp'];
if (!validExtensions.includes(ext)) {
return res.status(400).json({
ok: false,
error: 'INVALID_EXTENSION',
message: 'Недопустимое расширение файла',
});
}
next();
}