e2ee
This commit is contained in:
@@ -371,7 +371,7 @@ const sendRoomMessage = async (req, res, next) => {
|
||||
}
|
||||
|
||||
const textContent = content != null ? String(content).trim() : ''
|
||||
const uploaded = req.files?.file
|
||||
const uploaded = req.file
|
||||
const resolvedFileType = fileType || undefined
|
||||
|
||||
if (!textContent && !uploaded) {
|
||||
@@ -409,22 +409,16 @@ const sendRoomMessage = async (req, res, next) => {
|
||||
|
||||
let fileUrl = null
|
||||
if (uploaded) {
|
||||
const uploadDir = path.join(__dirname, '../../../storage/chat-rooms/messages')
|
||||
if (!fs.existsSync(uploadDir)) {
|
||||
fs.mkdirSync(uploadDir, { recursive: true })
|
||||
}
|
||||
// اسمِ فایل هیچوقت مستقیم از ورودیِ کاربر (uploaded.name) گرفته نمیشه — فقط پسوندش
|
||||
const uniqueFileName = `${Date.now()}-${crypto.randomUUID()}${path.extname(uploaded.name || '')}`
|
||||
const filePath = path.join(uploadDir, uniqueFileName)
|
||||
await fs.move(uploaded.path, filePath)
|
||||
if (resolvedFileType === 'image' || (uploaded.type || '').startsWith('image/')) {
|
||||
await optimizeImageFile(filePath)
|
||||
} else if (resolvedFileType === 'video' || (uploaded.type || '').startsWith('video/')) {
|
||||
optimizeVideoFaststart(filePath).catch((err) => {
|
||||
// multer (roomMessageUpload توی routes) از قبل فایل رو مستقیماً روی پوشهی
|
||||
// نهایی نوشته — دیگه نیازی به fs.move جداگانه نیست
|
||||
if (resolvedFileType === 'image' || (uploaded.mimetype || '').startsWith('image/')) {
|
||||
await optimizeImageFile(uploaded.path)
|
||||
} else if (resolvedFileType === 'video' || (uploaded.mimetype || '').startsWith('video/')) {
|
||||
optimizeVideoFaststart(uploaded.path).catch((err) => {
|
||||
console.error('[chatRoomController] video optimize background error:', err.message)
|
||||
})
|
||||
}
|
||||
fileUrl = `/chat-rooms/messages/${uniqueFileName}`
|
||||
fileUrl = `/chat-rooms/messages/${uploaded.filename}`
|
||||
}
|
||||
|
||||
room.lastActivityAt = new Date()
|
||||
|
||||
Reference in New Issue
Block a user