- aggiornamento di tante cose...

- generazione Volantini
- pagina RIS
This commit is contained in:
Surya Paolo
2025-12-17 10:07:51 +01:00
parent 037ff6f7f9
commit 3d87c336de
43 changed files with 7123 additions and 518 deletions

42
src/middleware/upload.js Normal file
View File

@@ -0,0 +1,42 @@
const multer = require('multer');
const path = require('path');
const crypto = require('crypto');
const UPLOAD_DIR = process.env.UPLOAD_DIR || './uploads';
const storage = multer.diskStorage({
destination: (req, file, cb) => {
cb(null, UPLOAD_DIR);
},
filename: (req, file, cb) => {
const uniqueId = crypto.randomBytes(8).toString('hex');
const ext = path.extname(file.originalname);
cb(null, `${Date.now()}_${uniqueId}${ext}`);
}
});
const fileFilter = (req, file, cb) => {
const allowedTypes = [
'image/jpeg',
'image/png',
'image/gif',
'image/webp',
'image/svg+xml'
];
if (allowedTypes.includes(file.mimetype)) {
cb(null, true);
} else {
cb(new Error('Tipo file non supportato'), false);
}
};
const upload = multer({
storage,
fileFilter,
limits: {
fileSize: 20 * 1024 * 1024 // 20MB max
}
});
module.exports = upload;