mail-attachment 로직 수정

This commit is contained in:
dohyeons
2025-10-13 16:11:51 +09:00
parent 7a10b2652c
commit b6eaaed85e
3 changed files with 17 additions and 8 deletions

View File

@@ -2,12 +2,19 @@ import multer from 'multer';
import path from 'path';
import fs from 'fs';
// 업로드 디렉토리 경로
const UPLOAD_DIR = path.join(__dirname, '../../uploads/mail-attachments');
// 업로드 디렉토리 경로 (운영: /app/uploads/mail-attachments, 개발: 프로젝트 루트)
const UPLOAD_DIR = process.env.NODE_ENV === 'production'
? '/app/uploads/mail-attachments'
: path.join(process.cwd(), 'uploads', 'mail-attachments');
// 디렉토리 생성 (없으면)
if (!fs.existsSync(UPLOAD_DIR)) {
fs.mkdirSync(UPLOAD_DIR, { recursive: true });
// 디렉토리 생성 (없으면) - try-catch로 권한 에러 방지
try {
if (!fs.existsSync(UPLOAD_DIR)) {
fs.mkdirSync(UPLOAD_DIR, { recursive: true });
}
} catch (error) {
console.error('메일 첨부파일 디렉토리 생성 실패:', error);
// 디렉토리가 이미 존재하거나 권한이 없어도 서비스는 계속 실행
}
// 간단한 파일명 정규화 함수 (한글-분석.txt 방식)