forked from UKSOURCE/cms.hailearning.edu.vn
first commit
This commit is contained in:
@@ -155,8 +155,44 @@ async function convertToWebp(req, res, next) {
|
||||
}
|
||||
|
||||
|
||||
// Storage cho degree images — lưu ngoài public/ để không serve trực tiếp
|
||||
const degreeStorage = multer.diskStorage({
|
||||
destination: function (req, file, cb) {
|
||||
const uploadPath = path.join(__dirname, '../private/uploads/degree');
|
||||
if (!fs.existsSync(uploadPath)) {
|
||||
fs.mkdirSync(uploadPath, { recursive: true });
|
||||
}
|
||||
cb(null, uploadPath);
|
||||
},
|
||||
filename: function (req, file, cb) {
|
||||
const ext = path.extname(file.originalname);
|
||||
cb(null, `degree-${Date.now()}-${Math.round(Math.random() * 1e9)}${ext}`);
|
||||
}
|
||||
});
|
||||
|
||||
// Lọc file chỉ cho phép ảnh degree
|
||||
const degreeFileFilter = (req, file, cb) => {
|
||||
const allowedMimes = ['image/jpeg', 'image/png', 'image/webp'];
|
||||
if (allowedMimes.includes(file.mimetype)) {
|
||||
cb(null, true);
|
||||
} else {
|
||||
cb(new Error('Only image/jpeg, image/png, image/webp files are allowed!'));
|
||||
}
|
||||
};
|
||||
|
||||
// Cấu hình upload degree
|
||||
const uploadDegree = multer({
|
||||
storage: degreeStorage,
|
||||
limits: { fileSize: 5 * 1024 * 1024 }, // 5MB per file
|
||||
fileFilter: degreeFileFilter
|
||||
}).fields([
|
||||
{ name: 'degree_image', maxCount: 1 },
|
||||
{ name: 'certificate_image', maxCount: 1 }
|
||||
]);
|
||||
|
||||
module.exports = {
|
||||
upload,
|
||||
uploadVideo,
|
||||
convertToWebp
|
||||
};
|
||||
convertToWebp,
|
||||
uploadDegree
|
||||
};
|
||||
Reference in New Issue
Block a user