diff --git a/.env.example b/.env.example index 3ea3ff4..aa086ea 100644 --- a/.env.example +++ b/.env.example @@ -4,3 +4,4 @@ ADMIN_EMAIL=admin@norostudio.ir ADMIN_PASSWORD=admin123 API_PUBLIC_URL=http://localhost:4000 CORS_ORIGIN=http://localhost:5173,http://localhost:3000 +MAX_UPLOAD_MB=200 diff --git a/server/index.js b/server/index.js index a1fd417..657b006 100644 --- a/server/index.js +++ b/server/index.js @@ -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(',') || ['http://localhost:5173'] @@ -320,6 +333,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, () => { console.log(`Noro CMS API running at http://localhost:${PORT}`) }) diff --git a/src/api/client.ts b/src/api/client.ts index 125fcef..3d8c31b 100644 --- a/src/api/client.ts +++ b/src/api/client.ts @@ -24,6 +24,7 @@ export interface Project { year?: string featured?: boolean imageUrl?: string + videoUrl?: string galleryUrls?: string[] client?: string deliverables?: string[] diff --git a/src/components/ImageGalleryField.vue b/src/components/ImageGalleryField.vue index 5b3dd9a..3e7a973 100644 --- a/src/components/ImageGalleryField.vue +++ b/src/components/ImageGalleryField.vue @@ -6,11 +6,11 @@

{{ description }}