- DB: messenger_rooms/participants/messages/reactions/files 테이블 생성 - Backend: REST API 9개 엔드포인트 + Socket.IO 실시간 핸들러 - Frontend: Gmail 스타일 FAB + 모달, 채팅방 목록, 채팅 패널 - 기능: DM/그룹/채널, 파일 첨부, 이모지 리액션, 멘션, 스레드 - 알림: 토스트 on/off 토글, FAB 읽지 않은 배지 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> [RAPID-fix] 메신저 API snake_case→camelCase 변환 및 Socket.IO URL 수정 - useRooms/useMessages/useCompanyUsers 훅에서 DB 응답 camelCase 변환 - Socket.IO 기본 연결 URL 3001 → 8080 수정 - runMigration.ts 마이그레이션 파일 경로 수정 (../../ → ../../../) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> [RAPID-fix] 방 생성 API camelCase/snake_case 호환 처리 - createRoom 컨트롤러에서 participantIds/type/name (camelCase) fallback 추가 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> [RAPID-fix] 메시지 전송 API 추가 (sendMessage 라우트/컨트롤러 누락) - POST /api/messenger/rooms/:roomId/messages 라우트 등록 - MessengerController.sendMessage 메서드 추가 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
64 lines
1.7 KiB
TypeScript
64 lines
1.7 KiB
TypeScript
import multer from 'multer';
|
|
import path from 'path';
|
|
import fs from 'fs';
|
|
|
|
// Upload directory
|
|
const UPLOAD_DIR = process.env.NODE_ENV === 'production'
|
|
? '/app/uploads/messenger-files'
|
|
: path.join(process.cwd(), 'uploads', 'messenger-files');
|
|
|
|
// Create directory if not exists
|
|
try {
|
|
if (!fs.existsSync(UPLOAD_DIR)) {
|
|
fs.mkdirSync(UPLOAD_DIR, { recursive: true });
|
|
}
|
|
} catch (error) {
|
|
console.error('Messenger file upload directory creation failed:', error);
|
|
}
|
|
|
|
// File storage config
|
|
const storage = multer.diskStorage({
|
|
destination: (req, file, cb) => {
|
|
cb(null, UPLOAD_DIR);
|
|
},
|
|
filename: (req, file, cb) => {
|
|
try {
|
|
file.originalname = file.originalname.normalize('NFC');
|
|
const uniqueId = Date.now() + '-' + Math.round(Math.random() * 1e9);
|
|
const ext = path.extname(file.originalname);
|
|
cb(null, `${uniqueId}${ext}`);
|
|
} catch (error) {
|
|
console.error('Filename processing error:', error);
|
|
cb(null, `${Date.now()}-${Math.round(Math.random() * 1e9)}_error.tmp`);
|
|
}
|
|
},
|
|
});
|
|
|
|
// File filter - block dangerous extensions
|
|
const fileFilter = (req: any, file: Express.Multer.File, cb: multer.FileFilterCallback) => {
|
|
try {
|
|
file.originalname = file.originalname.normalize('NFC');
|
|
} catch (error) {
|
|
// ignore normalization failure
|
|
}
|
|
|
|
const dangerousExtensions = ['.exe', '.bat', '.cmd', '.sh', '.ps1', '.msi'];
|
|
const ext = path.extname(file.originalname).toLowerCase();
|
|
|
|
if (dangerousExtensions.includes(ext)) {
|
|
cb(new Error(`Security: ${ext} files are not allowed.`));
|
|
return;
|
|
}
|
|
|
|
cb(null, true);
|
|
};
|
|
|
|
export const uploadMessengerFile = multer({
|
|
storage,
|
|
fileFilter,
|
|
limits: {
|
|
fileSize: 20 * 1024 * 1024, // 20MB
|
|
files: 10,
|
|
},
|
|
});
|