- 사이트 서버: 앱 로그인(/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>
126 lines
5.4 KiB
TypeScript
126 lines
5.4 KiB
TypeScript
// 겜녹이 설정 창 렌더러 진입점. 라우팅: #/wizard[/단계] · #/settings/<탭>
|
|
import { useEffect, useState, type ReactNode } from 'react';
|
|
import { createRoot } from 'react-dom/client';
|
|
import { ROLE_LABEL, isAdminRole } from '../core/roles';
|
|
import tray from './assets/tray@2x.png';
|
|
import { AuthGate } from './auth/Login';
|
|
import { AppProvider, isMock, useApp } from './store';
|
|
import './styles.css';
|
|
import { AdminTab } from './tabs/AdminTab';
|
|
import { AudioTab } from './tabs/AudioTab';
|
|
import { DiagTab } from './tabs/DiagTab';
|
|
import { DictTab } from './tabs/DictTab';
|
|
import { DiscordTab } from './tabs/DiscordTab';
|
|
import { GamesTab } from './tabs/GamesTab';
|
|
import { GeneralTab } from './tabs/GeneralTab';
|
|
import { StorageTab } from './tabs/StorageTab';
|
|
import { SttTab } from './tabs/SttTab';
|
|
import { Avatar, Dot } from './ui';
|
|
import { go } from './util';
|
|
import { Wizard } from './wizard/Wizard';
|
|
|
|
const TABS: { id: string; icon: string; label: string; el: () => ReactNode }[] = [
|
|
{ id: 'discord', icon: '🤖', label: '디스코드', el: () => <DiscordTab /> },
|
|
{ id: 'games', icon: '🎯', label: '게임 연동', el: () => <GamesTab /> },
|
|
{ id: 'stt', icon: '🧠', label: 'STT 모델', el: () => <SttTab /> },
|
|
{ id: 'audio', icon: '🔊', label: '음성 처리', el: () => <AudioTab /> },
|
|
{ id: 'dict', icon: '📖', label: '단어사전', el: () => <DictTab /> },
|
|
{ id: 'storage', icon: '💾', label: '저장 · 사이트', el: () => <StorageTab /> },
|
|
{ id: 'diag', icon: '🔬', label: '진단', el: () => <DiagTab /> },
|
|
{ id: 'general', icon: '⚙️', label: '일반', el: () => <GeneralTab /> },
|
|
];
|
|
/** 관리자 · 최고 관리자에게만 보이는 탭 */
|
|
const ADMIN_TAB = { id: 'admin', icon: '🛡️', label: '관리자', el: () => <AdminTab /> };
|
|
const tabsFor = (role: string | null) => (isAdminRole(role as never) ? [...TABS, ADMIN_TAB] : TABS);
|
|
|
|
function useHash(): string {
|
|
const [h, setH] = useState(location.hash);
|
|
useEffect(() => {
|
|
const on = () => setH(location.hash);
|
|
window.addEventListener('hashchange', on);
|
|
return () => window.removeEventListener('hashchange', on);
|
|
}, []);
|
|
return h;
|
|
}
|
|
|
|
function Router() {
|
|
const { settings, state } = useApp();
|
|
const hash = useHash();
|
|
const parts = hash.replace(/^#\/?/, '').split('/');
|
|
|
|
// 첫 실행이면 마법사로, 주소가 비었으면 디스코드 탭으로
|
|
useEffect(() => {
|
|
if (!hash || hash === '#' || hash === '#/') go(settings.firstRunDone ? '#/settings/discord' : '#/wizard');
|
|
}, [hash, settings.firstRunDone]);
|
|
|
|
const isWizard = parts[0] === 'wizard';
|
|
useEffect(() => {
|
|
document.title = isWizard ? '겜녹이 · 첫 실행 설정' : '겜녹이 · 설정';
|
|
}, [isWizard]);
|
|
|
|
if (isWizard) return <Wizard step={Math.max(1, Math.min(5, Number(parts[1]) || 1))} />;
|
|
const tabs = tabsFor(state.account.role);
|
|
const tab = tabs.find((t) => t.id === parts[1]) ?? tabs[0]!;
|
|
return (
|
|
<div className="app">
|
|
<Nav current={tab.id} tabs={tabs} />
|
|
<main className="content" key={tab.id}>
|
|
{tab.el()}
|
|
</main>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function Nav({ current, tabs }: { current: string; tabs: typeof TABS }) {
|
|
const { state } = useApp();
|
|
const acc = state.account;
|
|
const bot = state.bot.status;
|
|
const botTone = bot === 'ready' ? 'ok' : bot === 'connecting' ? 'warn' : bot === 'error' ? 'err' : 'off';
|
|
const botText = bot === 'ready' ? (state.bot.recording.active ? '녹음 중' : '정상') : bot === 'connecting' ? '연결 중' : bot === 'error' ? '오류' : '꺼짐';
|
|
const r = state.relay.state;
|
|
const relayTone = r === 'online' ? 'ok' : r === 'connecting' ? 'warn' : r === 'error' ? 'err' : 'off';
|
|
const relayText = r === 'online' ? '연결됨' : r === 'connecting' ? '연결 중' : r === 'error' ? '오류' : '미등록';
|
|
return (
|
|
<nav className="side">
|
|
{tabs.map((t) => (
|
|
<a key={t.id} href={`#/settings/${t.id}`} className={`tab ${t.id === current ? 'on' : ''}`}>
|
|
<span className="ic">{t.icon}</span>
|
|
{t.label}
|
|
</a>
|
|
))}
|
|
<div className="nav-status">
|
|
{acc.user && (
|
|
<a href="#/settings/general" className="nav-account" title={acc.offline ? '사이트 서버에 연결되지 않아 마지막 확인 결과로 쓰는 중' : acc.user.id}>
|
|
<Avatar name={acc.user.name} src={acc.user.avatar} size={18} />
|
|
{acc.user.name}
|
|
{acc.role && <span className={`role ${acc.role}`}>{ROLE_LABEL[acc.role]}</span>}
|
|
{acc.offline && <span className="t-warn">·오프라인</span>}
|
|
</a>
|
|
)}
|
|
<div className="brand-mini">
|
|
<img src={tray} alt="" />
|
|
겜녹이 v{state.version}
|
|
{isMock && <span className="badge mock">MOCK</span>}
|
|
</div>
|
|
<div title={state.bot.error ?? ''}>
|
|
봇: <Dot tone={botTone} /> <span className={`t-${botTone}`}>{botText}</span>
|
|
</div>
|
|
<div title={state.relay.error ?? ''}>
|
|
사이트 서버: <Dot tone={relayTone} /> <span className={`t-${relayTone}`}>{relayText}</span>
|
|
</div>
|
|
<div>
|
|
STT 대기열 {state.stt.queue}건{state.stt.worker !== 'ready' && <span className="t-warn"> · 엔진 {state.stt.worker === 'starting' ? '시작 중' : '꺼짐'}</span>}
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
);
|
|
}
|
|
|
|
createRoot(document.getElementById('root')!).render(
|
|
<AuthGate>
|
|
<AppProvider>
|
|
<Router />
|
|
</AppProvider>
|
|
</AuthGate>,
|
|
);
|