Raise upload limits for video files in API and nginx.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-13 12:11:34 +03:30
co-authored by Cursor
parent 25a6fe67b7
commit 732e93f1bc
2 changed files with 37 additions and 4 deletions
+29 -1
View File
@@ -22,7 +22,20 @@ const storage = multer.diskStorage({
cb(null, `${randomUUID()}${ext}`)
},
})
const upload = multer({ storage })
const MAX_UPLOAD_BYTES = Number(process.env.MAX_UPLOAD_MB || 200) * 1024 * 1024
const upload = multer({
storage,
limits: { fileSize: MAX_UPLOAD_BYTES },
fileFilter: (_req, file, cb) => {
const allowed =
file.mimetype.startsWith('image/') ||
file.mimetype.startsWith('video/') ||
file.mimetype === 'application/pdf' ||
file.mimetype === 'image/svg+xml'
if (allowed) return cb(null, true)
cb(new Error('فقط تصویر، ویدیو یا PDF مجاز است'))
},
})
const app = express()
const corsOrigin = process.env.CORS_ORIGIN?.split(',').map((o) => o.trim()) || [
@@ -327,6 +340,21 @@ app.delete('/api/media/:id', authMiddleware, (req, res) => {
res.status(204).end()
})
app.use((err, _req, res, next) => {
if (err instanceof multer.MulterError) {
if (err.code === 'LIMIT_FILE_SIZE') {
return res.status(400).json({
error: `حجم فایل بیش از حد مجاز است (حداکثر ${Number(process.env.MAX_UPLOAD_MB || 200)} مگابایت)`,
})
}
return res.status(400).json({ error: err.message })
}
if (err) {
return res.status(400).json({ error: err.message || 'خطای آپلود' })
}
next()
})
app.listen(PORT, '127.0.0.1', () => {
console.log(`Studio Noro API running at http://127.0.0.1:${PORT}`)
})