Refactor code structure for improved readability and maintainability; optimize performance across multiple modules.
All checks were successful
Deploy to production / deploy (push) Successful in 2m56s

This commit is contained in:
Torsten Schulz (local)
2026-07-21 09:08:15 +02:00
parent 75b52de282
commit 1ab9407e79
1400 changed files with 22278 additions and 485 deletions

0
backend/middleware/authMiddleware.js Normal file → Executable file
View File

View File

@@ -0,0 +1,33 @@
import multer from 'multer';
const imageMimeTypes = new Set(['image/jpeg', 'image/png', 'image/webp', 'image/gif']);
const verificationMimeTypes = new Set([...imageMimeTypes, 'application/pdf']);
const videoMimeTypes = new Set(['video/mp4', 'video/webm', 'video/ogg', 'video/quicktime']);
function createUpload({ maxBytes, allowedMimeTypes }) {
return multer({
storage: multer.memoryStorage(),
limits: { fileSize: maxBytes, files: 1 },
fileFilter: (_req, file, callback) => {
if (!allowedMimeTypes.has(file.mimetype)) {
callback(new multer.MulterError('LIMIT_UNEXPECTED_FILE', file.fieldname));
return;
}
callback(null, true);
},
});
}
export const imageUpload = createUpload({ maxBytes: 10 * 1024 * 1024, allowedMimeTypes: imageMimeTypes });
export const adultVerificationUpload = createUpload({ maxBytes: 10 * 1024 * 1024, allowedMimeTypes: verificationMimeTypes });
export const videoUpload = createUpload({ maxBytes: 100 * 1024 * 1024, allowedMimeTypes: videoMimeTypes });
export function uploadErrorHandler(error, _req, res, next) {
if (error instanceof multer.MulterError) {
const message = error.code === 'LIMIT_FILE_SIZE'
? 'Die hochgeladene Datei ist zu groß.'
: 'Der Dateityp ist nicht erlaubt.';
return res.status(400).json({ error: message });
}
return next(error);
}