fix: parse multipart uploads for shop-chat files and chat-room images

Same root cause as the shop logo fix: these two routes still expected
req.files.<field> (the removed express-form-data pattern) with no
multer middleware in front of them, so:
- POST /shop-chat/:shopId/messages/file always rejected with "فایل
  الزامی است" even when a valid image/video was sent.
- POST /chat-rooms room creation silently dropped room_image, and
  would lose all text fields (title, visibility, ...) whenever the
  request was multipart (i.e. whenever an image was attached).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
payacom
2026-10-28 17:01:43 +03:30
parent 6e25e1a38a
commit 0cfec31f52
4 changed files with 46 additions and 8 deletions

View File

@@ -36,8 +36,25 @@ const roomMessageUpload = multer({
limits: { fileSize: 200 * 1024 * 1024 }
}).single('file')
// همون باگ: createRoom منتظرِ req.files.room_image بود ولی این روت هیچ parserِ
// multipart نداشت — پس ساختِ اتاق با عکس همیشه شکست می‌خورد (یا حتی بدونِ عکس،
// اگه کلاینت همون درخواستِ multipart رو بدونِ فایل هم بفرسته، عنوانِ اتاق هم گم می‌شد)
const roomImageTmpDir = '/tmp/modstagram-uploads'
if (!fs.existsSync(roomImageTmpDir)) {
fs.mkdirSync(roomImageTmpDir, { recursive: true })
}
const roomImageUpload = multer({
storage: multer.diskStorage({
destination: (req, file, cb) => cb(null, roomImageTmpDir),
filename: (req, file, cb) => {
cb(null, `${Date.now()}-${crypto.randomUUID()}${path.extname(file.originalname || '')}`)
}
}),
limits: { fileSize: 20 * 1024 * 1024 }
}).single('room_image')
router.get('/', listRooms)
router.post('/', createRoom)
router.post('/', roomImageUpload, createRoom)
router.get('/:roomId', getRoomDetail)
router.post('/:roomId/join', joinRoom)
router.post('/:roomId/members', addRoomMembers)