✨ 주요 변경사항: - 프로젝트 이름: kumamoto-travel-planner → travel-planner - 버전 업그레이드: v1.0.0 → v2.0.0 - 멀티유저 시스템 구현 (JWT 인증) - PostgreSQL 마이그레이션 시스템 추가 - Docker 컨테이너 이름 변경 - UI 브랜딩 업데이트 (Travel Planner) - API 서버 및 인증 시스템 추가 - 여행 공유 기능 구현 - 템플릿 시스템 추가 🔧 기술 스택: - Frontend: React + TypeScript + Vite - Backend: Node.js + Express + JWT - Database: PostgreSQL + 마이그레이션 - Infrastructure: Docker + Docker Compose 🌟 새로운 기능: - 사용자 인증 및 권한 관리 - 다중 여행 계획 관리 - 여행 템플릿 시스템 - 공유 링크 및 댓글 시스템 - 관리자 대시보드
89 lines
2.4 KiB
JavaScript
89 lines
2.4 KiB
JavaScript
const express = require('express');
|
|
const multer = require('multer');
|
|
const path = require('path');
|
|
const fs = require('fs');
|
|
|
|
const router = express.Router();
|
|
|
|
// uploads 디렉토리 생성
|
|
const uploadsDir = path.join(__dirname, '../uploads');
|
|
if (!fs.existsSync(uploadsDir)) {
|
|
fs.mkdirSync(uploadsDir, { recursive: true });
|
|
}
|
|
|
|
// Multer 설정: 파일 저장 위치와 파일명 설정
|
|
const storage = multer.diskStorage({
|
|
destination: (req, file, cb) => {
|
|
cb(null, uploadsDir);
|
|
},
|
|
filename: (req, file, cb) => {
|
|
const uniqueSuffix = Date.now() + '-' + Math.round(Math.random() * 1E9);
|
|
const ext = path.extname(file.originalname);
|
|
cb(null, file.fieldname + '-' + uniqueSuffix + ext);
|
|
}
|
|
});
|
|
|
|
// 파일 필터: 이미지만 허용
|
|
const fileFilter = (req, file, cb) => {
|
|
const allowedTypes = /jpeg|jpg|png|gif|webp/;
|
|
const extname = allowedTypes.test(path.extname(file.originalname).toLowerCase());
|
|
const mimetype = allowedTypes.test(file.mimetype);
|
|
|
|
if (mimetype && extname) {
|
|
return cb(null, true);
|
|
} else {
|
|
cb(new Error('이미지 파일만 업로드 가능합니다 (jpeg, jpg, png, gif, webp)'));
|
|
}
|
|
};
|
|
|
|
const upload = multer({
|
|
storage: storage,
|
|
limits: {
|
|
fileSize: 5 * 1024 * 1024 // 5MB 제한
|
|
},
|
|
fileFilter: fileFilter
|
|
});
|
|
|
|
// 다중 이미지 업로드 (최대 5개)
|
|
router.post('/', upload.array('images', 5), (req, res) => {
|
|
try {
|
|
if (!req.files || req.files.length === 0) {
|
|
return res.status(400).json({ error: '파일이 업로드되지 않았습니다' });
|
|
}
|
|
|
|
// 업로드된 파일의 URL 배열 생성
|
|
const fileUrls = req.files.map(file => `/uploads/${file.filename}`);
|
|
|
|
res.json({
|
|
success: true,
|
|
files: fileUrls,
|
|
message: `${req.files.length}개의 파일이 업로드되었습니다`
|
|
});
|
|
} catch (error) {
|
|
console.error('이미지 업로드 오류:', error);
|
|
res.status(500).json({ error: error.message });
|
|
}
|
|
});
|
|
|
|
// 단일 이미지 업로드
|
|
router.post('/single', upload.single('image'), (req, res) => {
|
|
try {
|
|
if (!req.file) {
|
|
return res.status(400).json({ error: '파일이 업로드되지 않았습니다' });
|
|
}
|
|
|
|
const fileUrl = `/uploads/${req.file.filename}`;
|
|
|
|
res.json({
|
|
success: true,
|
|
file: fileUrl,
|
|
message: '파일이 업로드되었습니다'
|
|
});
|
|
} catch (error) {
|
|
console.error('이미지 업로드 오류:', error);
|
|
res.status(500).json({ error: error.message });
|
|
}
|
|
});
|
|
|
|
module.exports = router;
|