First Commit

This commit is contained in:
DATAEXPRESS\4734
2026-01-06 18:24:42 +08:00
commit 65f033adbc
37 changed files with 3010 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
const multer = require('multer');
const fs = require('fs');
const path = require('path');
const storage = multer.diskStorage({
destination: (req, file, cb) => {
const { dbname, typeid } = req.params;
const uploadPath = path.join(__dirname, `../../public/upload/${dbname}/${typeid}`);
fs.mkdirSync(uploadPath, { recursive: true });
cb(null, uploadPath);
},
filename: (req, file, cb) => {
const dateStr = new Date().toISOString().replace(/[:.]/g, '-');
cb(null, `${dateStr}-${file.originalname}`);
}
});
const upload = multer({
storage,
limits: { fileSize: parseInt(process.env.MAX_FILE_SIZE) || 50 * 1024 * 1024 },
fileFilter: (req, file, cb) => {
// 禁止上傳危險副檔名
const forbiddenExtensions = ['.exe', '.sh', '.php', '.js', '.bat'];
const ext = path.extname(file.originalname).toLowerCase();
if (forbiddenExtensions.includes(ext)) {
return cb(new Error('File type not allowed'), false);
}
cb(null, true);
}
});
module.exports = upload;