Public Source Viewer
비나래아카이브 개발자 포털
실제 서비스 구조를 살펴볼 수 있는 공개용 코드 뷰어입니다. 인증, 세션, 외부 연동, 토큰, 관리자 식별 등 보안상 민감한 구현은 파일 단위 또는 줄 단위로 검열됩니다.
src/routes/monitoring.routes.ts
공개 가능
1
import { Router, Request, Response } from 'express';
2
import { Settings } from '../types/models';
3
import { readSettings, writeSettings } from '../services/settings.service';
4
import { getMonitoringSnapshot } from '../services/monitoring.service';
5
import { recordSecurityLog } from '../services/security-log.service';
6
7
const router = Router();
8
9
[SECURITY REDACTED] 민감한 설정/인증/토큰 관련 코드입니다.
10
const TOGGLE_KEYS: (keyof Settings)[] = [
11
'isSignupEnabled',
12
'isAnonymousPostingEnabled',
13
'isGptEnabled',
14
'isSubwayApiEnabled',
15
'isPushEnabled',
16
'isDiscordShareEnabled',
17
'isDiscordPersonaCommandEnabled',
18
'isDiscordAiCommandEnabled',
19
'isDiscordSearchCommandEnabled'
20
];
21
22
function requireAdmin(req: Request, res: Response, next: () => void): void {
23
[SECURITY REDACTED] 민감한 설정/인증/토큰 관련 코드입니다.
24
return res.redirect('/hinana/lounge');
25
}
26
next();
27
}
28
29
router.get('/hinana/monitor', requireAdmin, (req: Request, res: Response) => {
30
res.render('./hinana/monitor', {
31
username: req.session.username,
32
theme: req.session.theme || req.cookies.theme || 'light',
33
snapshot: getMonitoringSnapshot()
34
});
35
});
36
37
router.get('/api/admin/monitoring', requireAdmin, (_req: Request, res: Response) => {
38
res.json({ success: true, snapshot: getMonitoringSnapshot() });
39
});
40
41
router.post('/api/admin/features/:key/toggle', requireAdmin, (req: Request, res: Response) => {
42
const key = req.params.key as keyof Settings;
43
if (!TOGGLE_KEYS.includes(key)) {
44
return res.status(400).json({ success: false, message: 'Unknown feature flag' });
45
}
46
47
const settings = readSettings();
48
const nextValue = !(settings[key] !== false);
49
(settings as any)[key] = nextValue;
50
writeSettings(settings);
51
52
recordSecurityLog(req, {
53
type: 'admin_action',
54
action: `Feature flag changed: ${String(key)}`,
55
detail: nextValue ? 'enabled' : 'disabled'
56
});
57
58
res.json({ success: true, key, enabled: nextValue, snapshot: getMonitoringSnapshot() });
59
});
60
61
export default router;
62