const fs = require('fs'); const path = require('path'); const multer = require('multer'); const { v4: uuidv4 } = require('uuid'); const uploadDir = path.join(__dirname, '..', '..', 'uploads'); if (!fs.existsSync(uploadDir)) { fs.mkdirSync(uploadDir, { recursive: true }); } const storage = multer.diskStorage({ destination: (_req, _file, cb) => cb(null, uploadDir), filename: (_req, file, cb) => cb(null, `${Date.now()}-${uuidv4()}-${file.originalname}`) }); function fileFilter(_req, file, cb) { const allowed = [ 'application/pdf', 'image/jpeg', 'image/png', 'image/jpg' ]; if (!allowed.includes(file.mimetype)) { return cb(new Error('Only PDF/JPG/PNG files are allowed')); } return cb(null, true); } const upload = multer({ storage, fileFilter, limits: { fileSize: 5 * 1024 * 1024 } }); module.exports = upload;