앱 v1.2.0: exe 디스코드 로그인 · 유저 등록 · 관리자 페이지
- 사이트 서버: 앱 로그인(/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>
This commit is contained in:
@@ -2,19 +2,22 @@ import { app, BrowserWindow, dialog, ipcMain, shell } from 'electron';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { toUser } from '../core/api/server.js';
|
||||
import type { AppAuth, AuthState } from '../core/auth.js';
|
||||
import { runDiagnostics } from '../core/diagnostics.js';
|
||||
import { synthesize } from '../core/discord/tts.js';
|
||||
import type { Core } from '../core/index.js';
|
||||
import { registerDevice } from '../core/relay/client.js';
|
||||
import { dirSize } from '../core/retention.js';
|
||||
import type { AppState, DownloadProgress, GvrApi } from './api-types.js';
|
||||
import { ADMIN_ONLY_ACTIONS, ADMIN_ONLY_MESSAGE, adminOnlyPaths, isAdminRole } from '../core/roles.js';
|
||||
import type { AppState, AuthView, DownloadProgress, GvrApi } from './api-types.js';
|
||||
import type { Finetuner } from './finetune.js';
|
||||
|
||||
type Handlers = { [K in keyof GvrApi]?: (...args: any[]) => any };
|
||||
|
||||
export function buildState(core: Core, opts: { dataDir: string; portable: boolean }): AppState {
|
||||
export function buildState(core: Core, opts: { dataDir: string; portable: boolean; auth: AuthState }): AppState {
|
||||
const s = core.settings.get();
|
||||
return {
|
||||
account: { user: opts.auth.user, role: opts.auth.role, offline: opts.auth.offline },
|
||||
version: core.version,
|
||||
dataDir: opts.dataDir,
|
||||
portable: opts.portable,
|
||||
@@ -36,15 +39,51 @@ export function buildState(core: Core, opts: { dataDir: string; portable: boolea
|
||||
};
|
||||
}
|
||||
|
||||
/** 설정 창의 window.gvr 요청 처리 (api-types.ts GvrApi) */
|
||||
export function registerIpc(core: Core, ft: Finetuner, ctx: { dataDir: string; portable: boolean; win: () => BrowserWindow | null; finishWizard: () => void; quit: () => void }) {
|
||||
export interface IpcContext {
|
||||
dataDir: string;
|
||||
portable: boolean;
|
||||
win: () => BrowserWindow | null;
|
||||
finishWizard: () => void;
|
||||
quit: () => void;
|
||||
auth: AppAuth;
|
||||
/** 로그인해서 코어가 떠 있으면 코어 · 파인튜너 */
|
||||
current: () => { core: Core; ft: Finetuner } | null;
|
||||
authView: () => AuthView;
|
||||
/** 로그인 화면에서 다시 확인 (서버 연결 실패 후 재시도) */
|
||||
recheck: () => Promise<void>;
|
||||
}
|
||||
|
||||
/** 설정 창의 window.gvr 요청 처리 (api-types.ts GvrApi). 로그인 · 관리자 요청은 코어 없이도 받는다 */
|
||||
export function registerIpc(ctx: IpcContext) {
|
||||
const send = (ch: string, payload: unknown) => ctx.win()?.webContents.send(ch, payload);
|
||||
const progress = (p: DownloadProgress) => send('gvr:progress', p);
|
||||
const role = () => (ctx.auth.ok ? ctx.auth.state.role : null);
|
||||
|
||||
// 로그인해야 쓰는 요청은 지금 떠 있는 코어로 보낸다 (로그아웃 후 다시 로그인하면 코어가 새로 뜬다)
|
||||
const live = () => {
|
||||
const c = ctx.auth.ok ? ctx.current() : null;
|
||||
if (!c) throw new Error('로그인이 필요합니다');
|
||||
return c;
|
||||
};
|
||||
const core = new Proxy({} as Core, { get: (_t, k) => (live().core as any)[k] });
|
||||
const ft = new Proxy({} as Finetuner, {
|
||||
get: (_t, k) => {
|
||||
const f = live().ft as any;
|
||||
return typeof f[k] === 'function' ? f[k].bind(f) : f[k];
|
||||
},
|
||||
});
|
||||
|
||||
const h: Handlers = {
|
||||
getState: () => buildState(core, ctx),
|
||||
updateSettings: (patch) => core.settings.update(patch),
|
||||
setSecret: (key, value) => core.settings.setSecret(key, value),
|
||||
getState: () => buildState(core, { ...ctx, auth: ctx.auth.state }),
|
||||
updateSettings: (patch) => {
|
||||
if (!isAdminRole(role()) && adminOnlyPaths(patch).length) throw new Error(ADMIN_ONLY_MESSAGE);
|
||||
return core.settings.update(patch);
|
||||
},
|
||||
setSecret: (key, value) => {
|
||||
if (key !== 'botToken' && key !== 'riotApiKey') throw new Error('바꿀 수 없는 값입니다');
|
||||
if (key === 'botToken' && !isAdminRole(role())) throw new Error(ADMIN_ONLY_MESSAGE);
|
||||
return core.settings.setSecret(key, value);
|
||||
},
|
||||
|
||||
testBotToken: async (token?: string) => {
|
||||
const t = token || core.settings.activeBotToken();
|
||||
@@ -283,7 +322,26 @@ export function registerIpc(core: Core, ft: Finetuner, ctx: { dataDir: string; p
|
||||
quit: () => ctx.quit(),
|
||||
};
|
||||
|
||||
const authHandlers: Handlers = {
|
||||
authState: () => ctx.authView(),
|
||||
authLogin: () => ctx.auth.login().then(() => ctx.authView()),
|
||||
authCancel: () => ctx.auth.cancelLogin(),
|
||||
authLogout: () => ctx.auth.logout(),
|
||||
authRecheck: () => ctx.recheck().then(() => ctx.authView()),
|
||||
adminUsers: () => ctx.auth.adminUsers(),
|
||||
adminAddUser: (id: string, r: 'admin' | 'user') => ctx.auth.adminAddUser(id, r),
|
||||
adminSetRole: (id: string, r: 'admin' | 'user') => ctx.auth.adminSetRole(id, r),
|
||||
adminRemoveUser: (id: string) => ctx.auth.adminRemoveUser(id),
|
||||
openExternal: h.openExternal,
|
||||
quit: h.quit,
|
||||
};
|
||||
for (const [name, fn] of Object.entries(authHandlers)) ipcMain.handle(`gvr:${name}`, async (_e, ...args) => fn!(...args));
|
||||
for (const [name, fn] of Object.entries(h)) {
|
||||
ipcMain.handle(`gvr:${name}`, async (_e, ...args) => fn!(...args));
|
||||
if (name in authHandlers) continue;
|
||||
ipcMain.handle(`gvr:${name}`, async (_e, ...args) => {
|
||||
live();
|
||||
if (ADMIN_ONLY_ACTIONS.has(name) && !isAdminRole(role())) throw new Error('관리자만 쓸 수 있는 기능입니다');
|
||||
return fn!(...args);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user