b6b345f245
- Refactor email verification and password reset utilities to use new email service. - Introduce email delivery queue and notification delivery model for better tracking. - Enhance file validation and storage services for improved security and ownership management. - Add cron job for cleaning inactive notifications with retention policy. - Update document worker to handle document generation and storage more efficiently. - Implement logging improvements in activity and log workers. - Create comprehensive documentation for new API endpoints and services. - Add unit tests for file validation and notification policies to ensure robustness.
54 lines
1.3 KiB
JavaScript
54 lines
1.3 KiB
JavaScript
/**
|
|
* Copyright (c) 2026 Niolla
|
|
* All rights reserved.
|
|
*
|
|
* This source code is proprietary and confidential.
|
|
* Unauthorized copying, modification, distribution, or use
|
|
* of this file, via any medium, is strictly prohibited.
|
|
*/
|
|
|
|
// app/middlewares/upload.middleware.js
|
|
|
|
const multer = require("multer");
|
|
|
|
// Use memory storage (required for S3 upload)
|
|
const storage = multer.memoryStorage();
|
|
|
|
// File filter (only images + PDFs)
|
|
const fileFilter = (req, file, cb) => {
|
|
const isValid = ["image/jpeg", "image/png", "image/webp", "application/pdf", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"].includes(file.mimetype);
|
|
|
|
if (isValid) {
|
|
cb(null, true);
|
|
} else {
|
|
cb(new Error("Only JPEG, PNG, WebP, PDF, and XLSX files are allowed"), false);
|
|
}
|
|
};
|
|
|
|
// Multer instance
|
|
const upload = multer({
|
|
storage,
|
|
fileFilter,
|
|
limits: {
|
|
fileSize: Number(process.env.S3_MAX_UPLOAD_BYTES || 5 * 1024 * 1024),
|
|
},
|
|
});
|
|
|
|
// Middleware wrappers
|
|
|
|
// Single file upload
|
|
const uploadSingle = (fieldName) => upload.single(fieldName);
|
|
|
|
// Multiple files (same field)
|
|
const uploadMultiple = (fieldName, maxCount = 5) =>
|
|
upload.array(fieldName, maxCount);
|
|
|
|
// Multiple fields (advanced)
|
|
const uploadFields = (fields) => upload.fields(fields);
|
|
|
|
module.exports = {
|
|
uploadSingle,
|
|
uploadMultiple,
|
|
uploadFields,
|
|
};
|