앱 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:
EJClaw
2026-10-15 08:08:44 +09:00
parent 4d31cfc16a
commit c2a5547a68
41 changed files with 2096 additions and 237 deletions

View File

@@ -5,6 +5,7 @@ import crypto from 'node:crypto';
import fs from 'node:fs';
import path from 'node:path';
import type { Config } from './config.js';
import { registerAppAuth } from './app-auth.js';
import { avatarUrl, DiscordApi } from './discord.js';
import { RelayHub } from './relay.js';
import { ServerStore, type Session } from './store.js';
@@ -19,6 +20,7 @@ export async function buildServer(cfg: Config) {
const discord = new DiscordApi(cfg);
await app.register(cookie, { secret: cfg.sessionSecret });
const secure = cfg.publicUrl.startsWith('https://');
const appAuth = registerAppAuth(app, { cfg, store, discord, secure });
const allowedGuilds = (): string[] => {
const g = new Set(cfg.allowedGuilds);
@@ -70,6 +72,8 @@ export async function buildServer(cfg: Config) {
app.get<{ Querystring: { code?: string; state?: string; error?: string } }>('/auth/discord/callback', async (req, reply) => {
const st = req.cookies.gvr_state ? req.unsignCookie(req.cookies.gvr_state) : null;
reply.clearCookie('gvr_state', { path: '/auth' });
// 앱(exe) 로그인: 같은 콜백을 쓰고 state 가 "app." 으로 시작한다 (app-auth.ts)
if (st?.valid && st.value && st.value === req.query.state && st.value.startsWith('app.')) return appAuth.completeLogin(st.value, req.query.code, req.query.error, reply, req.log);
if (req.query.error) return reply.redirect('/?login=cancelled');
if (!req.query.code || !st?.valid || st.value !== req.query.state) return reply.redirect('/?login=invalid');
try {
@@ -175,7 +179,7 @@ export async function buildServer(cfg: Config) {
if (fs.existsSync(cfg.webDir)) {
await app.register(fastifyStatic, { root: cfg.webDir, wildcard: false, index: ['index.html'] });
app.setNotFoundHandler((req, reply) => {
if (req.method === 'GET' && !req.url.startsWith('/api/') && !req.url.startsWith('/auth/') && !req.url.startsWith('/game-assets/'))
if (req.method === 'GET' && !req.url.startsWith('/api/') && !req.url.startsWith('/auth/') && !req.url.startsWith('/app/') && !req.url.startsWith('/game-assets/'))
return reply.type('text/html').send(fs.readFileSync(path.join(cfg.webDir, 'index.html')));
return reply.code(404).send({ error: 'not_found' });
});