first commit

This commit is contained in:
2026-04-11 14:08:27 +07:00
parent e86e5d2c46
commit 6b7655aa16
389 changed files with 5387 additions and 60861 deletions

View File

@@ -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
};