Public Source Viewer

비나래아카이브 개발자 포털

실제 서비스 구조를 살펴볼 수 있는 공개용 코드 뷰어입니다. 인증, 세션, 외부 연동, 토큰, 관리자 식별 등 보안상 민감한 구현은 파일 단위 또는 줄 단위로 검열됩니다.

Redacted View
src/config/multer.config.ts
공개 가능
1 import multer from 'multer';
2 import path from 'path';
3 import { PUBLIC_DIR } from '../utils/paths';
4
5 export const storage = multer.diskStorage({
6 destination: function (req, file, cb) {
7 cb(null, path.join(PUBLIC_DIR, 'uploads'));
8 },
9 filename: function (req, file, cb) {
10 cb(null, Date.now() + path.extname(file.originalname));
11 }
12 });
13
14 export const upload = multer({ storage: storage });
15
16 const profileStorage = multer.diskStorage({
17 destination: function (req, file, cb) {
18 cb(null, path.join(PUBLIC_DIR, 'uploads', 'profiles'));
19 },
20 filename: function (req, file, cb) {
21 const username = (req as any).session?.username || 'unknown';
22 cb(null, `${username}_${Date.now()}${path.extname(file.originalname)}`);
23 }
24 });
25
26 export const profileUpload = multer({
27 storage: profileStorage,
28 fileFilter: (req, file, cb) => {
29 if (/\.(jpg|jpeg|png|gif|webp)$/i.test(path.extname(file.originalname))) {
30 cb(null, true);
31 } else {
32 cb(new Error('이미지 파일만 업로드 가능합니다.'));
33 }
34 },
35 limits: { fileSize: 2 * 1024 * 1024 }
36 });
37
38 export const memoryUpload = multer({
39 storage: multer.memoryStorage(),
40 fileFilter: (req, file, cb) => {
41 if (/\.(jpg|jpeg|png|gif|webp)$/i.test(path.extname(file.originalname))) {
42 cb(null, true);
43 } else {
44 cb(new Error('이미지 파일만 업로드 가능합니다.'));
45 }
46 },
47 limits: { fileSize: 10 * 1024 * 1024 }
48 });
49