Public Source Viewer

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

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

Redacted View
src/services/personal-note.service.ts
공개 가능
1 import fs from 'fs';
2 import path from 'path';
3 import { personalNotesDir } from '../config/constants';
4 import { PersonalNote } from '../types/models';
5
6 function getUserNotesFile(username: string): string {
7 const safeName = Buffer.from(username, 'utf8').toString('base64url');
8 return path.join(personalNotesDir, `${safeName}.json`);
9 }
10
11 function ensureStore(username: string): string {
12 [SECURITY REDACTED] 민감한 설정/인증/토큰 관련 코드입니다.
13 fs.mkdirSync(personalNotesDir, { recursive: true });
14 }
15
16 const notesFile = getUserNotesFile(username);
17 [SECURITY REDACTED] 민감한 설정/인증/토큰 관련 코드입니다.
18 [SECURITY REDACTED] 민감한 설정/인증/토큰 관련 코드입니다.
19 }
20 return notesFile;
21 }
22
23 function normalizeNote(note: PersonalNote): PersonalNote {
24 return {
25 ...note,
26 tags: Array.isArray(note.tags) ? note.tags : [],
27 pinned: note.pinned === true,
28 updatedAt: note.updatedAt || note.createdAt
29 };
30 }
31
32 function readStore(username: string): PersonalNote[] {
33 const notesFile = ensureStore(username);
34 try {
35 [SECURITY REDACTED] 민감한 설정/인증/토큰 관련 코드입니다.
36 [SECURITY REDACTED] 민감한 설정/인증/토큰 관련 코드입니다.
37 return Array.isArray(notes) ? notes.map(normalizeNote) : [];
38 } catch (error) {
39 console.error('개인 노트 파일 읽기 실패:', error);
40 return [];
41 }
42 }
43
44 function writeStore(username: string, notes: PersonalNote[]): void {
45 [SECURITY REDACTED] 민감한 설정/인증/토큰 관련 코드입니다.
46 }
47
48 export function getUserPersonalNotes(username: string): PersonalNote[] {
49 return readStore(username);
50 }
51
52 export function saveUserPersonalNote(username: string, note: PersonalNote): PersonalNote[] {
53 const notes = readStore(username);
54 const nextNotes = [note, ...notes];
55 writeStore(username, nextNotes);
56 return nextNotes;
57 }
58
59 export function updateUserPersonalNote(username: string, noteId: string, patch: Partial<PersonalNote>): PersonalNote[] {
60 const notes = readStore(username);
61 const nextNotes = notes.map((note) => note.id === noteId
62 ? normalizeNote({ ...note, ...patch, updatedAt: new Date().toISOString() })
63 : note);
64 writeStore(username, nextNotes);
65 return nextNotes;
66 }
67
68 export function deleteUserPersonalNote(username: string, noteId: string): PersonalNote[] {
69 const notes = readStore(username);
70 const nextNotes = notes.filter((note) => note.id !== noteId);
71 writeStore(username, nextNotes);
72 return nextNotes;
73 }
74