- 사이트 서버: 앱 로그인(/auth/app/begin·start·poll, 기존 OAuth 콜백 재사용), 앱 토큰(/app/me, 해시 저장), 유저 등록 API(/app/admin/users, 등록·역할·해제는 최고 관리자만, 목록은 관리자도). 최고 관리자 2명 고정 - 앱: 등록된 계정으로 로그인해야 코어(봇·녹음·사이트 연결)를 띄운다. 미등록이면 "등록되지 않은 아이디" + 아이디 표시. 10분마다 재확인, 등록 해제 시 즉시 잠금. 서버 연결 실패 시 마지막 확인 후 3일 유예 - 겜녹이 봇 토큰을 exe 에 넣지 않고 로그인한 등록 유저에게 서버가 내려준다 (잠기면 삭제). win-ci 토큰 주입 제거 - 관리자 탭(유저 등록·목록·접속 기록), 관리자 전용 설정(봇 변경·TTS 안내·보관 기간·사이트·학습 데이터·파인튜닝)은 일반 유저에게 잠금 표시 + 메인 프로세스에서 차단 - 테스트: 서버 앱 로그인 2건, 앱↔서버 통합 3건, Electron 로그인 E2E 스크립트(scripts/login-e2e.mts) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
76 lines
2.7 KiB
TypeScript
76 lines
2.7 KiB
TypeScript
// 렌더러 공용 유틸 (포맷 · 병합)
|
|
|
|
export function deepMerge<T>(base: T, over: unknown): T {
|
|
if (over === undefined || over === null || typeof base !== 'object' || base === null || Array.isArray(base)) {
|
|
return (over ?? base) as T;
|
|
}
|
|
const out: Record<string, unknown> = { ...(base as Record<string, unknown>) };
|
|
for (const [k, v] of Object.entries(over as Record<string, unknown>)) {
|
|
const b = out[k];
|
|
out[k] = b && typeof b === 'object' && !Array.isArray(b) ? deepMerge(b, v) : v;
|
|
}
|
|
return out as T;
|
|
}
|
|
|
|
export function errMsg(e: unknown): string {
|
|
const m = e instanceof Error ? e.message : String(e);
|
|
// IPC 오류는 "Error invoking remote method 'gvr:x': Error: 메시지" 로 온다
|
|
return m.replace(/^Error invoking remote method '[^']+': (?:\w*Error: )?/, '');
|
|
}
|
|
|
|
/** "3분 전" · "2시간 전" · "4일 전" */
|
|
export function fmtAgo(ts: number | null | undefined): string {
|
|
if (!ts) return '-';
|
|
const s = Math.max(0, (Date.now() - ts) / 1000);
|
|
if (s < 60) return '방금';
|
|
if (s < 3600) return `${Math.floor(s / 60)}분 전`;
|
|
if (s < 86400) return `${Math.floor(s / 3600)}시간 전`;
|
|
return `${Math.floor(s / 86400)}일 전`;
|
|
}
|
|
|
|
/** MB → "1.6GB" / "464MB" */
|
|
export function fmtMb(mb: number, digits = 1): string {
|
|
if (mb >= 1000) return `${(mb / 1024).toFixed(digits)}GB`;
|
|
return `${Math.round(mb)}MB`;
|
|
}
|
|
|
|
export function fmtBytes(b: number | null | undefined): string {
|
|
if (b === null || b === undefined) return '-';
|
|
if (b >= 1024 ** 3) return `${(b / 1024 ** 3).toFixed(1)}GB`;
|
|
if (b >= 1024 ** 2) return `${(b / 1024 ** 2).toFixed(0)}MB`;
|
|
if (b >= 1024) return `${(b / 1024).toFixed(0)}KB`;
|
|
return `${b}B`;
|
|
}
|
|
|
|
export function fmtEta(sec: number | undefined): string {
|
|
if (sec === undefined || !isFinite(sec)) return '';
|
|
const s = Math.max(0, Math.round(sec));
|
|
if (s < 60) return `${s}초`;
|
|
const m = Math.floor(s / 60);
|
|
if (m < 60) return `${m}분 ${s % 60}초`;
|
|
return `${Math.floor(m / 60)}시간 ${m % 60}분`;
|
|
}
|
|
|
|
export function fmtClock(ts: number): string {
|
|
const d = new Date(ts);
|
|
return `${String(d.getHours()).padStart(2, '0')}:${String(d.getMinutes()).padStart(2, '0')}`;
|
|
}
|
|
|
|
export function fmtDuration(ms: number): string {
|
|
const s = Math.max(0, Math.floor(ms / 1000));
|
|
const h = Math.floor(s / 3600);
|
|
const m = Math.floor((s % 3600) / 60);
|
|
return h ? `${h}시간 ${m}분` : `${m}분 ${s % 60}초`;
|
|
}
|
|
|
|
export function fmtDate(ts: number): string {
|
|
const d = new Date(ts);
|
|
return `${d.getMonth() + 1}/${d.getDate()} ${fmtClock(ts)}`;
|
|
}
|
|
|
|
export const sleep = (ms: number) => new Promise<void>((r) => setTimeout(r, ms));
|
|
|
|
export function go(hash: string) {
|
|
if (location.hash !== hash) location.hash = hash;
|
|
}
|