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:
@@ -225,14 +225,14 @@ const createRoom = async (req, res, next) => {
|
||||
}
|
||||
|
||||
let imagePath = null
|
||||
const imageFile = req.files?.room_image
|
||||
const imageFile = req.file
|
||||
if (imageFile) {
|
||||
const uploadDir = path.join(__dirname, '../../../storage/chat-rooms')
|
||||
if (!fs.existsSync(uploadDir)) {
|
||||
fs.mkdirSync(uploadDir, { recursive: true })
|
||||
}
|
||||
// اسمِ فایل هیچوقت مستقیم از ورودیِ کاربر (imageFile.name) گرفته نمیشه — فقط پسوندش
|
||||
const uniqueFileName = `${Date.now()}-${crypto.randomUUID()}${path.extname(imageFile.name || '')}`
|
||||
// اسمِ فایل هیچوقت مستقیم از ورودیِ کاربر (imageFile.originalname) گرفته نمیشه — فقط پسوندش
|
||||
const uniqueFileName = `${Date.now()}-${crypto.randomUUID()}${path.extname(imageFile.originalname || '')}`
|
||||
const filePath = path.join(uploadDir, uniqueFileName)
|
||||
await fs.move(imageFile.path, filePath)
|
||||
await optimizeImageFile(filePath, { maxDimension: 800 })
|
||||
|
||||
Reference in New Issue
Block a user