Add full project files

This commit is contained in:
root
2026-07-04 19:24:56 +03:30
parent d54f5441a3
commit b245e7b71a
835 changed files with 30149 additions and 0 deletions

24
middlewares/upload.js Normal file
View File

@@ -0,0 +1,24 @@
const multer = require('multer');
const path = require('path');
const fs = require('fs-extra');
const uploadDir = path.join(__dirname, '../storage/posts');
fs.ensureDirSync(uploadDir); // مطمئن میشه مسیر وجود داره
const storage = multer.diskStorage({
destination: (req, file, cb) => cb(null, uploadDir),
filename: (req, file, cb) => {
const ext = path.extname(file.originalname);
const name = file.originalname.replace(ext, '').replace(/\s/g, '_');
cb(null, `${Date.now()}-${name}${ext}`);
}
});
const fileFilter = (req, file, cb) => {
if (!file.mimetype.startsWith('image/')) return cb(new Error('فقط تصاویر مجاز است'));
cb(null, true);
};
const upload = multer({ storage, fileFilter, limits: { files: 10 } }); // حداکثر ۱۰ فایل
module.exports = upload;