v1.6.0: 사이트 '내 정보'(표시 이름 · 색 · 라이엇 ID · 녹음 제외) · 관리 페이지
- 사이트 오른쪽 위 내 이름 → 내 정보: 표시 이름 바꾸기/되돌리기, 색, 라이엇 ID, 녹음 제외, 로그아웃 - 관리 페이지 /admin (관리자): 게임 PC 상태 · 앱 새 버전 안내, 유저별 표시 이름 · 색 · 라이엇 ID · 녹음 제외, 앱 등록 · 역할 · 해제(최고 관리자). /site/admin/* 는 /app/admin/* 와 같은 처리 - 서버: 표시 이름 검사(길이 · 보이지 않는 글자 · 다른 사람과 겹침), 지우면 디스코드 이름으로 되돌림, 바뀌면 게임 PC 앱에 바로 보냄 (PUT /api/internal/names) - 앱: PATCH /api/users/:id (본인 또는 관리자, 남의 라이엇 ID 는 관리자만), PUT /api/internal/names - 테스트: 앱 user-settings 3개, 사이트 서버 profile-admin 3개 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -18,6 +18,7 @@ import { CulpritPage } from './pages/CulpritPage';
|
||||
import { MatchesPage, UserPage, UsersPage } from './pages/UserPages';
|
||||
import { LogsPage } from './pages/LogsPage';
|
||||
import { RecordsPage } from './pages/RecordsPage';
|
||||
import { AdminPage } from './pages/AdminPage';
|
||||
import { installErrorReporting } from './lib/report';
|
||||
import { useLocation } from 'react-router';
|
||||
|
||||
@@ -75,6 +76,7 @@ function Shell() {
|
||||
<Route path="/dictionary" element={<DictionaryPage />} />
|
||||
<Route path="/culprit" element={<CulpritPage />} />
|
||||
<Route path="/culprit/:id" element={<CulpritPage />} />
|
||||
<Route path="/admin" element={<AdminPage />} />
|
||||
<Route path="*" element={<Navigate to="/" replace />} />
|
||||
</Routes>
|
||||
</div>
|
||||
|
||||
@@ -6,7 +6,8 @@ import { settings, useSettings, type SfxKind } from '../store/settings';
|
||||
import { sfx, SFX_LABEL } from '../lib/sfx';
|
||||
import { resumeAudio } from '../lib/audio';
|
||||
import { Avatar, Brand } from './common';
|
||||
import { IGear, ILogout, ISearch } from './Icons';
|
||||
import { IGear, ISearch } from './Icons';
|
||||
import { ProfilePopover } from './UserEdit';
|
||||
import { GAME_NAME, liveGameLine, liveGameRows } from '@gvr/shared';
|
||||
|
||||
function SettingsPopover({ onClose }: { onClose: () => void }) {
|
||||
@@ -165,10 +166,11 @@ export function SearchBox() {
|
||||
}
|
||||
|
||||
export function Header() {
|
||||
const { auth, logout } = useAuth();
|
||||
const { overview } = useData();
|
||||
const { auth } = useAuth();
|
||||
const { overview, userById } = useData();
|
||||
const { device, locked, conn } = useStatus();
|
||||
const [open, setOpen] = useState(false);
|
||||
const [profile, setProfile] = useState(false);
|
||||
const me = auth.status === 'ok' ? auth.me.user : null;
|
||||
const rec = overview?.recording;
|
||||
const nav = [
|
||||
@@ -178,6 +180,7 @@ export function Header() {
|
||||
['/users', '유저'],
|
||||
['/dictionary', '단어사전'],
|
||||
['/culprit', '🔍 범인찾기'],
|
||||
...(auth.status === 'ok' && auth.me.canViewLogs ? ([['/admin', '🛡️ 관리']] as const) : []),
|
||||
] as const;
|
||||
return (
|
||||
<header className="topbar">
|
||||
@@ -211,14 +214,13 @@ export function Header() {
|
||||
</button>
|
||||
<AnimatePresence>{open && <SettingsPopover onClose={() => setOpen(false)} />}</AnimatePresence>
|
||||
{me && (
|
||||
<div className="me">
|
||||
<Avatar name={me.name} src={me.avatar} color="#5865f2" size={26} />
|
||||
<button className="me me-btn" onClick={() => setProfile((o) => !o)} aria-expanded={profile} title="내 정보 · 표시 이름 · 색 · 로그아웃">
|
||||
<Avatar name={me.name} src={me.avatar} color={userById(me.id)?.color ?? '#5865f2'} size={26} />
|
||||
<span className="me-nm">{me.name}</span>
|
||||
<button className="icon-btn" onClick={logout} title="로그아웃" aria-label="로그아웃">
|
||||
<ILogout width={16} height={16} />
|
||||
</button>
|
||||
</div>
|
||||
<span className="me-caret">▾</span>
|
||||
</button>
|
||||
)}
|
||||
<AnimatePresence>{profile && <ProfilePopover onClose={() => setProfile(false)} />}</AnimatePresence>
|
||||
</div>
|
||||
</header>
|
||||
);
|
||||
|
||||
234
site/web/src/components/UserEdit.tsx
Normal file
234
site/web/src/components/UserEdit.tsx
Normal file
@@ -0,0 +1,234 @@
|
||||
// 유저 설정 고치기 (v1.6.0): 머리글 "내 정보" 와 관리 화면이 같이 쓴다
|
||||
// - 표시 이름: 사이트 서버에 저장 (디스코드 이름 대신 보일 이름, 게임 PC 앱에 바로 전달)
|
||||
// - 색 · 녹음 제외 · 라이엇 ID: 게임 PC 앱 기록에 저장 (앱 v1.6.0~)
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { Link } from 'react-router';
|
||||
import { motion } from 'framer-motion';
|
||||
import type { User } from '@gvr/shared';
|
||||
import { api, ApiError } from '../lib/api';
|
||||
import { sfx } from '../lib/sfx';
|
||||
import { useAuth, useData } from '../store/app';
|
||||
import { Avatar } from './common';
|
||||
import { ILogout } from './Icons';
|
||||
|
||||
/** 타임라인에서 잘 보이는 색들 (어두운 배경) */
|
||||
export const USER_COLORS = ['#ff4655', '#ff8a3d', '#f2b23a', '#c8e04a', '#45d39a', '#14c1b7', '#3db8ff', '#5b8cff', '#9a7bff', '#d46bff', '#ff6fb1', '#c9d1dc'];
|
||||
|
||||
/** 오류를 사람이 읽을 말로 */
|
||||
export function errText(e: unknown): string {
|
||||
if (e instanceof ApiError) {
|
||||
if (e.status === 404 && e.code === 'Not Found') return '게임 PC 앱이 아직 이 기능을 모릅니다. 앱을 v1.6.0 이상으로 업데이트해 주세요';
|
||||
if (e.status === 503 && e.code === 'device_offline') return '게임 PC 가 꺼져 있어 저장하지 못했습니다';
|
||||
if (e.status === 504) return '게임 PC 가 답하지 않습니다. 잠시 뒤 다시 해 주세요';
|
||||
if (e.detail) return e.detail;
|
||||
if (e.status === 0) return '서버에 연결하지 못했습니다';
|
||||
return `저장하지 못했습니다 (${e.status} ${e.code})`;
|
||||
}
|
||||
return e instanceof Error ? e.message : String(e);
|
||||
}
|
||||
|
||||
/** 표시 이름 입력: 저장 · 디스코드 이름으로 되돌리기 */
|
||||
export function NameEditor({ value, custom, onSave, placeholder }: { value: string; custom: boolean; onSave: (name: string) => Promise<void>; placeholder?: string }) {
|
||||
const [v, setV] = useState(value);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [msg, setMsg] = useState<{ ok: boolean; text: string } | null>(null);
|
||||
useEffect(() => setV(value), [value]);
|
||||
const save = async (name: string) => {
|
||||
setBusy(true);
|
||||
setMsg(null);
|
||||
try {
|
||||
await onSave(name);
|
||||
setMsg({ ok: true, text: name ? '저장했습니다' : '디스코드 이름으로 되돌렸습니다' });
|
||||
sfx('click');
|
||||
} catch (e) {
|
||||
setMsg({ ok: false, text: errText(e) });
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
return (
|
||||
<div className="ue-block">
|
||||
<form
|
||||
className="ue-row"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
if (v.trim() && v.trim() !== value) void save(v.trim());
|
||||
}}
|
||||
>
|
||||
<input className="ue-input" value={v} maxLength={32} placeholder={placeholder ?? '표시 이름'} onChange={(e) => setV(e.target.value)} aria-label="표시 이름" />
|
||||
<button className="btn sm primary" disabled={busy || !v.trim() || v.trim() === value}>
|
||||
저장
|
||||
</button>
|
||||
{custom && (
|
||||
<button type="button" className="btn sm" disabled={busy} onClick={() => void save('')} title="표시 이름을 지우고 디스코드 서버 별명으로 보이게">
|
||||
되돌리기
|
||||
</button>
|
||||
)}
|
||||
</form>
|
||||
{msg && <div className={`ue-msg${msg.ok ? ' ok' : ' bad'}`}>{msg.text}</div>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** 색 · 녹음 제외 · 라이엇 ID (게임 PC 앱에 저장) */
|
||||
export function AppUserEditor({ user, self }: { user: User; self: boolean }) {
|
||||
const { reloadUsers } = useData();
|
||||
const [riot, setRiot] = useState(user.riot.map((r) => r.riotId).join(', '));
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [msg, setMsg] = useState<{ ok: boolean; text: string } | null>(null);
|
||||
const riotNow = user.riot.map((r) => r.riotId).join(', ');
|
||||
useEffect(() => setRiot(riotNow), [riotNow]);
|
||||
const colorRef = useRef<HTMLInputElement>(null);
|
||||
const patch = async (p: { color?: string; excluded?: boolean; riotIds?: string[] }, okText: string) => {
|
||||
setBusy(true);
|
||||
setMsg(null);
|
||||
try {
|
||||
const r = await api.updateUser(user.id, p);
|
||||
reloadUsers();
|
||||
setMsg(r.taken.length ? { ok: false, text: `다른 사람에게 연결된 라이엇 ID 는 빼고 저장했습니다: ${r.taken.join(', ')}` } : { ok: true, text: okText });
|
||||
sfx('click');
|
||||
} catch (e) {
|
||||
setMsg({ ok: false, text: errText(e) });
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
const riotIds = riot
|
||||
.split(/[,\n]/)
|
||||
.map((x) => x.trim())
|
||||
.filter(Boolean);
|
||||
const riotBad = riotIds.filter((r) => !/^[^#]{1,32}#[^#]{1,8}$/.test(r));
|
||||
return (
|
||||
<div className="ue-block">
|
||||
<div className="ue-label">색</div>
|
||||
<div className="ue-colors" role="radiogroup" aria-label="유저 색">
|
||||
{USER_COLORS.map((c) => (
|
||||
<button
|
||||
key={c}
|
||||
className={`ue-sw${user.color.toLowerCase() === c ? ' on' : ''}`}
|
||||
style={{ background: c }}
|
||||
role="radio"
|
||||
aria-checked={user.color.toLowerCase() === c}
|
||||
aria-label={c}
|
||||
disabled={busy}
|
||||
onClick={() => void patch({ color: c }, '색을 바꿨습니다')}
|
||||
/>
|
||||
))}
|
||||
<button className="ue-sw custom" title="다른 색 고르기" aria-label="다른 색 고르기" disabled={busy} onClick={() => colorRef.current?.click()}>
|
||||
+
|
||||
</button>
|
||||
<input ref={colorRef} type="color" className="ue-hidden" defaultValue={user.color} onChange={(e) => void patch({ color: e.target.value }, '색을 바꿨습니다')} />
|
||||
</div>
|
||||
|
||||
<div className="ue-label">라이엇 ID</div>
|
||||
<form
|
||||
className="ue-row"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
if (!riotBad.length) void patch({ riotIds }, '라이엇 ID 를 저장했습니다');
|
||||
}}
|
||||
>
|
||||
<input className="ue-input" value={riot} placeholder="이름#태그 (여러 개는 쉼표로)" onChange={(e) => setRiot(e.target.value)} aria-label="라이엇 ID" />
|
||||
<button className="btn sm" disabled={busy || riot.trim() === riotNow || riotBad.length > 0 || riotIds.length > 5}>
|
||||
저장
|
||||
</button>
|
||||
</form>
|
||||
{riotBad.length > 0 && <div className="ue-msg bad">이름#태그 형식이 아닙니다: {riotBad.join(', ')}</div>}
|
||||
<div className="ue-hint">경기 기록의 선수와 연결됩니다. 새로 넣은 ID 는 다음 경기에서 확인됩니다.</div>
|
||||
|
||||
<label className="ue-check">
|
||||
<input type="checkbox" checked={user.excluded} disabled={busy} onChange={(e) => void patch({ excluded: e.target.checked }, e.target.checked ? '앞으로 녹음하지 않습니다' : '다시 녹음합니다')} />
|
||||
<span>
|
||||
<b>녹음 제외</b>
|
||||
<span className="ue-hint">{self ? '켜면 앞으로 내 목소리를 녹음하지 않습니다 (이미 녹음된 기록은 그대로).' : '켜면 앞으로 이 사람 목소리를 녹음하지 않습니다.'}</span>
|
||||
</span>
|
||||
</label>
|
||||
{msg && <div className={`ue-msg${msg.ok ? ' ok' : ' bad'}`}>{msg.text}</div>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** 머리글 오른쪽 위 내 이름을 누르면 나오는 "내 정보" */
|
||||
export function ProfilePopover({ onClose }: { onClose: () => void }) {
|
||||
const { auth, logout, refreshMe } = useAuth();
|
||||
const { userById } = useData();
|
||||
const ref = useRef<HTMLDivElement>(null);
|
||||
const [custom, setCustom] = useState<boolean | null>(null);
|
||||
useEffect(() => {
|
||||
const down = (e: PointerEvent) => {
|
||||
if (ref.current && !ref.current.contains(e.target as Node) && !(e.target as HTMLElement).closest('.me-btn')) onClose();
|
||||
};
|
||||
const key = (e: KeyboardEvent) => e.key === 'Escape' && onClose();
|
||||
document.addEventListener('pointerdown', down);
|
||||
document.addEventListener('keydown', key);
|
||||
return () => {
|
||||
document.removeEventListener('pointerdown', down);
|
||||
document.removeEventListener('keydown', key);
|
||||
};
|
||||
}, [onClose]);
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
fetch('/site/profile', { credentials: 'include' })
|
||||
.then((r) => (r.ok ? r.json() : null))
|
||||
.then((p) => alive && p && setCustom(!!p.customName))
|
||||
.catch(() => undefined);
|
||||
return () => {
|
||||
alive = false;
|
||||
};
|
||||
}, []);
|
||||
if (auth.status !== 'ok') return null;
|
||||
const me = auth.me.user;
|
||||
const u = userById(me.id);
|
||||
const admin = auth.me.canViewLogs;
|
||||
const roleLabel = auth.me.role === 'superadmin' ? '최고 관리자' : auth.me.role === 'admin' ? '관리자' : auth.me.role === 'user' ? '앱 유저' : admin ? '관리자' : '서버 멤버';
|
||||
return (
|
||||
<motion.div
|
||||
ref={ref}
|
||||
className="popover profile-pop"
|
||||
initial={{ opacity: 0, y: -6, scale: 0.98 }}
|
||||
animate={{ opacity: 1, y: 0, scale: 1 }}
|
||||
exit={{ opacity: 0, y: -6, scale: 0.98 }}
|
||||
transition={{ duration: 0.16 }}
|
||||
role="dialog"
|
||||
aria-label="내 정보"
|
||||
>
|
||||
<div className="pp-head">
|
||||
<Avatar name={me.name} src={me.avatar} color={u?.color ?? '#5865f2'} size={40} />
|
||||
<div>
|
||||
<b style={u ? { color: u.color } : undefined}>{me.name}</b>
|
||||
<div className="dim small">
|
||||
{roleLabel} · <span className="mono">{me.id}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<h5>표시 이름</h5>
|
||||
<NameEditor
|
||||
value={me.name}
|
||||
custom={!!custom}
|
||||
onSave={async (name) => {
|
||||
const r = await api.setMyName(name);
|
||||
setCustom(!!r.customName);
|
||||
await refreshMe();
|
||||
}}
|
||||
/>
|
||||
<div className="ue-hint">사이트 · 게임 PC 기록 · 범인 분석에서 디스코드 이름 대신 보입니다.</div>
|
||||
<h5>녹음 기록 설정</h5>
|
||||
{u ? <AppUserEditor user={u} self /> : <div className="ue-hint">아직 녹음된 적이 없습니다. 음성채널에서 한 번 녹음되면 색 · 라이엇 ID · 녹음 제외를 바꿀 수 있습니다.</div>}
|
||||
<div className="pp-links">
|
||||
{u && (
|
||||
<Link to={`/users/${me.id}`} className="mini-btn" onClick={onClose}>
|
||||
내 기록 보기
|
||||
</Link>
|
||||
)}
|
||||
{admin && (
|
||||
<Link to="/admin" className="mini-btn" onClick={onClose}>
|
||||
🛡️ 관리 페이지
|
||||
</Link>
|
||||
)}
|
||||
<button className="mini-btn" onClick={logout}>
|
||||
<ILogout width={13} height={13} /> 로그아웃
|
||||
</button>
|
||||
</div>
|
||||
</motion.div>
|
||||
);
|
||||
}
|
||||
@@ -15,6 +15,8 @@ import type {
|
||||
BundleInfo,
|
||||
BundleImportResult,
|
||||
NoisePhrase,
|
||||
AppRole,
|
||||
AppUserRow,
|
||||
} from '@gvr/shared';
|
||||
|
||||
import { reportClient } from './report';
|
||||
@@ -77,6 +79,16 @@ export interface Me {
|
||||
isOwner: boolean;
|
||||
/** 사이트 로그를 볼 수 있는지 (관리자 · 최고 관리자, v1.3.6~) */
|
||||
canViewLogs?: boolean;
|
||||
/** 앱 역할 (등록 안 된 멤버는 null, v1.6.0~) */
|
||||
role?: AppRole | null;
|
||||
}
|
||||
|
||||
/** 관리 화면 머리 (v1.6.0) */
|
||||
export interface AdminOverview {
|
||||
device: DeviceStatus & { guildId: string | null };
|
||||
latest: { version: string; url: string; publishedAt: string | null } | null;
|
||||
role: AppRole;
|
||||
serverVersion: string;
|
||||
}
|
||||
export interface StatusResponse {
|
||||
device: DeviceStatus;
|
||||
@@ -119,6 +131,17 @@ export const api = {
|
||||
/** 관리자(OWNER_DISCORD_IDS) 전용: 게임 PC 1회용 등록 코드 (10분) */
|
||||
registrationCode: () => request<{ code: string; expiresAt: number }>('/admin/registration-code', { method: 'POST' }),
|
||||
status: () => request<StatusResponse>('/api/status'),
|
||||
// 내 정보 · 관리 화면 (v1.6.0)
|
||||
setMyName: (name: string) => request<{ user: Me['user']; customName: string | null }>('/site/profile/name', { method: 'PUT', body: JSON.stringify({ name }) }),
|
||||
/** 색 · 녹음 제외 · 라이엇 ID (게임 PC 앱 v1.6.0~, 본인 또는 관리자) */
|
||||
updateUser: (id: string, patch: { color?: string; excluded?: boolean; riotIds?: string[] }) =>
|
||||
request<{ user: User; taken: string[] }>(`/api/users/${encodeURIComponent(id)}`, { method: 'PATCH', body: JSON.stringify(patch) }),
|
||||
adminOverview: () => request<AdminOverview>('/site/admin/overview'),
|
||||
adminUsers: () => request<{ users: AppUserRow[]; names: Record<string, string> }>('/site/admin/users'),
|
||||
adminSetName: (id: string, name: string) => request<{ names: Record<string, string> }>('/site/admin/names', { method: 'PUT', body: JSON.stringify({ id, name }) }),
|
||||
adminAddUser: (id: string, role: 'admin' | 'user') => request<{ users: AppUserRow[] }>('/site/admin/users', { method: 'POST', body: JSON.stringify({ id, role }) }),
|
||||
adminSetRole: (id: string, role: 'admin' | 'user') => request<{ users: AppUserRow[] }>(`/site/admin/users/${encodeURIComponent(id)}`, { method: 'PATCH', body: JSON.stringify({ role }) }),
|
||||
adminRemoveUser: (id: string) => request<{ users: AppUserRow[] }>(`/site/admin/users/${encodeURIComponent(id)}`, { method: 'DELETE' }),
|
||||
overview: () => request<Overview>('/api/overview'),
|
||||
users: () => request<User[]>('/api/users'),
|
||||
user: (id: string) => request<UserProfile>(`/api/users/${encodeURIComponent(id)}`),
|
||||
|
||||
299
site/web/src/pages/AdminPage.tsx
Normal file
299
site/web/src/pages/AdminPage.tsx
Normal file
@@ -0,0 +1,299 @@
|
||||
// 관리 페이지 (v1.6.0, 관리자 · 최고 관리자)
|
||||
// - 게임 PC: 연결 · 앱 버전 · 새 버전 안내
|
||||
// - 유저: 표시 이름 · 색 · 녹음 제외 · 라이엇 ID (녹음된 사람), 앱 등록 · 역할 · 해제 (최고 관리자)
|
||||
import { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import { Link } from 'react-router';
|
||||
import type { AppUserRow, User } from '@gvr/shared';
|
||||
import { api, type AdminOverview } from '../lib/api';
|
||||
import { fmtDay } from '../lib/format';
|
||||
import { useAuth, useData } from '../store/app';
|
||||
import { Avatar, ErrorBox, Panel, Spinner } from '../components/common';
|
||||
import { AppUserEditor, errText, NameEditor } from '../components/UserEdit';
|
||||
|
||||
const ROLE: Record<string, string> = { superadmin: '최고 관리자', admin: '관리자', user: '앱 유저' };
|
||||
|
||||
/** "1.4.1" < "1.5.0" */
|
||||
export function olderVersion(a: string | null | undefined, b: string | null | undefined): boolean {
|
||||
if (!a || !b) return false;
|
||||
const pa = a.split('.').map((x) => parseInt(x, 10) || 0);
|
||||
const pb = b.split('.').map((x) => parseInt(x, 10) || 0);
|
||||
for (let i = 0; i < Math.max(pa.length, pb.length); i++) if ((pa[i] ?? 0) !== (pb[i] ?? 0)) return (pa[i] ?? 0) < (pb[i] ?? 0);
|
||||
return false;
|
||||
}
|
||||
|
||||
const when = (t: number | null) => (t ? `${fmtDay(t)} ${new Date(t).toLocaleTimeString('ko-KR', { hour12: false, hour: '2-digit', minute: '2-digit' })}` : '—');
|
||||
|
||||
interface Row {
|
||||
id: string;
|
||||
name: string;
|
||||
avatar: string | null;
|
||||
/** 녹음 기록에 있는 사람 (게임 PC 앱) */
|
||||
user: User | null;
|
||||
/** 앱 등록 (사이트 서버) */
|
||||
reg: AppUserRow | null;
|
||||
}
|
||||
|
||||
export function AdminPage() {
|
||||
const { auth } = useAuth();
|
||||
const { users } = useData();
|
||||
const [ov, setOv] = useState<AdminOverview | null>(null);
|
||||
const [regs, setRegs] = useState<AppUserRow[] | null>(null);
|
||||
const [names, setNames] = useState<Record<string, string>>({});
|
||||
const [err, setErr] = useState<unknown>(null);
|
||||
const [open, setOpen] = useState<string | null>(null);
|
||||
const [q, setQ] = useState('');
|
||||
const load = useCallback(() => {
|
||||
setErr(null);
|
||||
Promise.all([api.adminOverview(), api.adminUsers()])
|
||||
.then(([o, u]) => {
|
||||
setOv(o);
|
||||
setRegs(u.users);
|
||||
setNames(u.names ?? {});
|
||||
})
|
||||
.catch(setErr);
|
||||
}, []);
|
||||
useEffect(load, [load]);
|
||||
const sup = ov?.role === 'superadmin';
|
||||
|
||||
const rows = useMemo<Row[]>(() => {
|
||||
const m = new Map<string, Row>();
|
||||
for (const u of users) m.set(u.id, { id: u.id, name: u.name, avatar: u.avatar, user: u, reg: null });
|
||||
for (const r of regs ?? []) {
|
||||
const cur = m.get(r.id);
|
||||
if (cur) cur.reg = r;
|
||||
else m.set(r.id, { id: r.id, name: r.name, avatar: r.avatar, user: null, reg: r });
|
||||
}
|
||||
const order = (r: Row) => (r.reg?.role === 'superadmin' ? 0 : r.reg?.role === 'admin' ? 1 : r.reg ? 2 : 3);
|
||||
const k = q.trim().toLowerCase();
|
||||
return [...m.values()]
|
||||
.filter((r) => !k || r.name.toLowerCase().includes(k) || r.id.includes(k) || r.user?.riot.some((x) => x.riotId.toLowerCase().includes(k)))
|
||||
.sort((a, b) => order(a) - order(b) || a.name.localeCompare(b.name, 'ko'));
|
||||
}, [users, regs, q]);
|
||||
|
||||
if (auth.status !== 'ok' || !auth.me.canViewLogs)
|
||||
return (
|
||||
<main className="page-pad">
|
||||
<h2 className="page-h h">관리</h2>
|
||||
<div className="dim">관리자만 볼 수 있습니다.</div>
|
||||
</main>
|
||||
);
|
||||
if (err) return <main className="page-pad"><ErrorBox error={err} onRetry={load} /></main>;
|
||||
if (!ov || !regs) return <main className="page-pad"><Spinner /></main>;
|
||||
|
||||
const dev = ov.device;
|
||||
const outdated = olderVersion(dev.version, ov.latest?.version);
|
||||
return (
|
||||
<main className="page-pad admin-page">
|
||||
<div className="page-h-row">
|
||||
<h2 className="page-h h">🛡️ 관리</h2>
|
||||
<div className="chips-wrap">
|
||||
<a className="mini-btn" href="/logs">
|
||||
📄 사이트 로그
|
||||
</a>
|
||||
<button className="mini-btn" onClick={load}>
|
||||
새로고침
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Panel title="게임 PC">
|
||||
<div className="adm-dev">
|
||||
<div>
|
||||
<span className={`dot-st ${dev.online ? 'on' : 'off'}`} /> <b>{dev.name ?? '등록된 PC 없음'}</b>
|
||||
<span className="dim small"> · {dev.online ? '연결됨' : dev.lastSeen ? `마지막 연결 ${when(dev.lastSeen)}` : '연결 안 됨'}</span>
|
||||
</div>
|
||||
<div>
|
||||
앱 <b className="mono">{dev.version ?? '?'}</b>
|
||||
{ov.latest && (
|
||||
<span className="dim small">
|
||||
{' '}
|
||||
· 최신 <span className="mono">{ov.latest.version}</span>
|
||||
</span>
|
||||
)}
|
||||
{outdated && ov.latest && (
|
||||
<a className="adm-update" href={ov.latest.url} target="_blank" rel="noreferrer">
|
||||
새 버전 v{ov.latest.version} 받기 →
|
||||
</a>
|
||||
)}
|
||||
</div>
|
||||
{outdated && <div className="ue-hint">게임 PC 앱이 최신이 아닙니다. 색 · 녹음 제외 · 라이엇 ID 바꾸기와 3D 리플레이는 최신 앱에서 됩니다.</div>}
|
||||
</div>
|
||||
</Panel>
|
||||
|
||||
<Panel
|
||||
title={`유저 ${rows.length}명`}
|
||||
right={<input className="ue-input adm-search" value={q} placeholder="이름 · 아이디 · 라이엇 ID 찾기" onChange={(e) => setQ(e.target.value)} aria-label="유저 찾기" />}
|
||||
>
|
||||
<div className="ue-hint adm-note">
|
||||
표시 이름은 디스코드 이름 대신 사이트 · 게임 PC 기록 · 범인 분석에 보입니다 (관리자). 앱 등록 · 역할 바꾸기 · 등록 해제는 최고 관리자만 할 수 있습니다.
|
||||
</div>
|
||||
<div className="adm-list">
|
||||
{rows.map((r) => (
|
||||
<AdminUserRow
|
||||
key={r.id}
|
||||
r={r}
|
||||
custom={!!names[r.id]}
|
||||
sup={sup}
|
||||
open={open === r.id}
|
||||
onToggle={() => setOpen((o) => (o === r.id ? null : r.id))}
|
||||
onNames={setNames}
|
||||
onRegs={setRegs}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
{sup && <AddUser onRegs={setRegs} />}
|
||||
</Panel>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
function AdminUserRow({
|
||||
r,
|
||||
custom,
|
||||
sup,
|
||||
open,
|
||||
onToggle,
|
||||
onNames,
|
||||
onRegs,
|
||||
}: {
|
||||
r: Row;
|
||||
custom: boolean;
|
||||
sup: boolean;
|
||||
open: boolean;
|
||||
onToggle: () => void;
|
||||
onNames: (n: Record<string, string>) => void;
|
||||
onRegs: (u: AppUserRow[]) => void;
|
||||
}) {
|
||||
const { reloadUsers } = useData();
|
||||
const { auth, refreshMe } = useAuth();
|
||||
const [msg, setMsg] = useState<string | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const act = async (fn: () => Promise<{ users: AppUserRow[] }>) => {
|
||||
setBusy(true);
|
||||
setMsg(null);
|
||||
try {
|
||||
onRegs((await fn()).users);
|
||||
} catch (e) {
|
||||
setMsg(errText(e));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
const role = r.reg?.role ?? null;
|
||||
return (
|
||||
<div className={`adm-row${open ? ' open' : ''}`}>
|
||||
<button className="adm-sum" onClick={onToggle} aria-expanded={open}>
|
||||
<Avatar user={r.user} name={r.name} src={r.avatar} size={30} />
|
||||
<span className="adm-nm">
|
||||
<b style={r.user ? { color: r.user.color } : undefined}>{r.name}</b>
|
||||
{custom && <span className="badge b-name">표시 이름</span>}
|
||||
{r.user?.excluded && <span className="badge b-excl">녹음 제외</span>}
|
||||
<span className="dim small mono">{r.id}</span>
|
||||
</span>
|
||||
<span className="adm-role">{role ? <span className={`badge b-role ${role}`}>{ROLE[role]}</span> : <span className="dim small">앱 미등록</span>}</span>
|
||||
<span className="adm-seen dim small">{r.reg?.lastSeenAt ? `앱 ${when(r.reg.lastSeenAt)}${r.reg.lastVersion ? ` · v${r.reg.lastVersion}` : ''}` : r.user ? '녹음 기록 있음' : ''}</span>
|
||||
<span className="adm-caret">{open ? '▴' : '▾'}</span>
|
||||
</button>
|
||||
{open && (
|
||||
<div className="adm-body">
|
||||
<div className="ue-label">표시 이름</div>
|
||||
<NameEditor
|
||||
value={r.name}
|
||||
custom={custom}
|
||||
onSave={async (name) => {
|
||||
const res = await api.adminSetName(r.id, name);
|
||||
onNames(res.names);
|
||||
// 게임 PC 앱이 이름을 받아 유저 목록을 다시 보낸다. 조금 기다렸다가 다시 받는다
|
||||
window.setTimeout(reloadUsers, 1500);
|
||||
if (auth.status === 'ok' && auth.me.user.id === r.id) await refreshMe();
|
||||
const regs = await api.adminUsers().catch(() => null);
|
||||
if (regs) onRegs(regs.users);
|
||||
}}
|
||||
/>
|
||||
{r.user ? (
|
||||
<AppUserEditor user={r.user} self={false} />
|
||||
) : (
|
||||
<div className="ue-hint">이 PC 녹음 기록에 없는 사람입니다. 음성채널에서 한 번 녹음되면 색 · 라이엇 ID · 녹음 제외를 바꿀 수 있습니다.</div>
|
||||
)}
|
||||
{r.user && (
|
||||
<Link className="mini-btn" to={`/users/${r.id}`}>
|
||||
기록 보기
|
||||
</Link>
|
||||
)}
|
||||
{sup && role !== 'superadmin' && (
|
||||
<div className="adm-acts">
|
||||
<div className="ue-label">앱 사용 (게임 PC 앱 로그인)</div>
|
||||
{role ? (
|
||||
<>
|
||||
<button className="btn sm" disabled={busy} onClick={() => void act(() => api.adminSetRole(r.id, role === 'admin' ? 'user' : 'admin'))}>
|
||||
{role === 'admin' ? '관리자 → 앱 유저로' : '앱 유저 → 관리자로'}
|
||||
</button>
|
||||
<button
|
||||
className="btn sm danger"
|
||||
disabled={busy}
|
||||
onClick={() => {
|
||||
if (window.confirm(`${r.name} 님의 앱 등록을 해제할까요? 그 사람의 겜녹이 앱이 바로 잠깁니다.`)) void act(() => api.adminRemoveUser(r.id));
|
||||
}}
|
||||
>
|
||||
등록 해제
|
||||
</button>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<button className="btn sm" disabled={busy} onClick={() => void act(() => api.adminAddUser(r.id, 'user'))}>
|
||||
앱 유저로 등록
|
||||
</button>
|
||||
<button className="btn sm" disabled={busy} onClick={() => void act(() => api.adminAddUser(r.id, 'admin'))}>
|
||||
관리자로 등록
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{msg && <div className="ue-msg bad">{msg}</div>}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function AddUser({ onRegs }: { onRegs: (u: AppUserRow[]) => void }) {
|
||||
const [id, setId] = useState('');
|
||||
const [role, setRole] = useState<'user' | 'admin'>('user');
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [msg, setMsg] = useState<{ ok: boolean; text: string } | null>(null);
|
||||
const ok = /^\d{17,20}$/.test(id.trim());
|
||||
return (
|
||||
<form
|
||||
className="adm-add"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
if (!ok) return;
|
||||
setBusy(true);
|
||||
setMsg(null);
|
||||
api
|
||||
.adminAddUser(id.trim(), role)
|
||||
.then((r) => {
|
||||
onRegs(r.users);
|
||||
setMsg({ ok: true, text: '등록했습니다. 그 사람은 이제 겜녹이 앱에 로그인할 수 있습니다' });
|
||||
setId('');
|
||||
})
|
||||
.catch((e) => setMsg({ ok: false, text: errText(e) }))
|
||||
.finally(() => setBusy(false));
|
||||
}}
|
||||
>
|
||||
<div className="ue-label">디스코드 아이디로 앱 유저 등록</div>
|
||||
<div className="ue-row">
|
||||
<input className="ue-input mono" value={id} inputMode="numeric" placeholder="디스코드 아이디 (17~20자리 숫자)" onChange={(e) => setId(e.target.value)} aria-label="디스코드 아이디" />
|
||||
<select className="ue-input adm-sel" value={role} onChange={(e) => setRole(e.target.value as 'user' | 'admin')} aria-label="역할">
|
||||
<option value="user">앱 유저</option>
|
||||
<option value="admin">관리자</option>
|
||||
</select>
|
||||
<button className="btn sm primary" disabled={busy || !ok}>
|
||||
등록
|
||||
</button>
|
||||
</div>
|
||||
{msg && <div className={`ue-msg${msg.ok ? ' ok' : ' bad'}`}>{msg.text}</div>}
|
||||
</form>
|
||||
);
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import { makeUnknownUserCheck } from '../lib/unknown-users';
|
||||
|
||||
// ── 로그인 ───────────────────────────────────────────
|
||||
type AuthState = { status: 'loading' } | { status: 'anon' } | { status: 'not_member' } | { status: 'ok'; me: Me };
|
||||
const AuthCtx = createContext<{ auth: AuthState; logout: () => void }>({ auth: { status: 'loading' }, logout: () => {} });
|
||||
const AuthCtx = createContext<{ auth: AuthState; logout: () => void; refreshMe: () => Promise<void> }>({ auth: { status: 'loading' }, logout: () => {}, refreshMe: async () => {} });
|
||||
|
||||
export function AuthProvider({ children }: { children: ReactNode }) {
|
||||
const [auth, setAuth] = useState<AuthState>({ status: 'loading' });
|
||||
@@ -28,7 +28,12 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
||||
const logout = useCallback(() => {
|
||||
void api.logout().finally(() => setAuth({ status: 'anon' }));
|
||||
}, []);
|
||||
return <AuthCtx.Provider value={{ auth, logout }}>{children}</AuthCtx.Provider>;
|
||||
// 내 표시 이름을 바꾼 뒤 머리글 이름을 다시 받는다
|
||||
const refreshMe = useCallback(async () => {
|
||||
const r = await api.me().catch(() => null);
|
||||
if (r?.ok) setAuth({ status: 'ok', me: r.me });
|
||||
}, []);
|
||||
return <AuthCtx.Provider value={{ auth, logout, refreshMe }}>{children}</AuthCtx.Provider>;
|
||||
}
|
||||
export const useAuth = () => useContext(AuthCtx);
|
||||
|
||||
@@ -123,8 +128,10 @@ interface DataValue {
|
||||
overview: Overview | null;
|
||||
users: User[];
|
||||
userById: (id: string | undefined | null) => User | undefined;
|
||||
/** 유저 목록 다시 받기 (유저 설정을 바꾼 뒤) */
|
||||
reloadUsers: () => void;
|
||||
}
|
||||
const DataCtx = createContext<DataValue>({ overview: null, users: [], userById: () => undefined });
|
||||
const DataCtx = createContext<DataValue>({ overview: null, users: [], userById: () => undefined, reloadUsers: () => {} });
|
||||
|
||||
export function DataProvider({ children }: { children: ReactNode }) {
|
||||
const { epoch, locked } = useStatus();
|
||||
@@ -163,6 +170,6 @@ export function DataProvider({ children }: { children: ReactNode }) {
|
||||
if (e.type === 'games.state') setOverview((o) => (o ? { ...o, live: e.data } : o));
|
||||
});
|
||||
const userById = useCallback((id: string | undefined | null) => (id ? map.get(id) : undefined), [map]);
|
||||
return <DataCtx.Provider value={{ overview, users, userById }}>{children}</DataCtx.Provider>;
|
||||
return <DataCtx.Provider value={{ overview, users, userById, reloadUsers }}>{children}</DataCtx.Provider>;
|
||||
}
|
||||
export const useData = () => useContext(DataCtx);
|
||||
|
||||
@@ -4079,3 +4079,273 @@ button.match:hover {
|
||||
width: 90px;
|
||||
accent-color: var(--accent);
|
||||
}
|
||||
|
||||
/* ── 내 정보 · 관리 페이지 (v1.6.0) ───────────────── */
|
||||
.me-btn {
|
||||
padding: 4px 8px 4px 4px;
|
||||
border-radius: 20px;
|
||||
border: 1px solid transparent;
|
||||
transition: border-color 0.15s, background 0.15s;
|
||||
}
|
||||
.me-btn:hover,
|
||||
.me-btn[aria-expanded='true'] {
|
||||
border-color: var(--line);
|
||||
background: #15222f;
|
||||
}
|
||||
.me-caret {
|
||||
font-size: 10px;
|
||||
color: var(--dim);
|
||||
}
|
||||
.popover.profile-pop {
|
||||
right: 0;
|
||||
width: 360px;
|
||||
max-height: calc(100vh - var(--header-h) - 24px);
|
||||
overflow: auto;
|
||||
}
|
||||
.pp-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding-bottom: 10px;
|
||||
border-bottom: 1px solid var(--line);
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
.pp-head b {
|
||||
font-size: 15px;
|
||||
}
|
||||
.pp-links {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
margin-top: 14px;
|
||||
padding-top: 10px;
|
||||
border-top: 1px solid var(--line);
|
||||
}
|
||||
.ue-block {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
}
|
||||
.ue-row {
|
||||
display: flex;
|
||||
gap: 6px;
|
||||
align-items: center;
|
||||
}
|
||||
.ue-input {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
background: #0b141c;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 7px;
|
||||
padding: 6px 9px;
|
||||
font-size: 13px;
|
||||
color: var(--ink);
|
||||
}
|
||||
.ue-input:focus {
|
||||
outline: none;
|
||||
border-color: #3a5670;
|
||||
}
|
||||
.ue-label {
|
||||
font-size: 11.5px;
|
||||
color: var(--muted);
|
||||
margin-top: 6px;
|
||||
}
|
||||
.ue-hint {
|
||||
font-size: 11.5px;
|
||||
color: var(--dim);
|
||||
line-height: 1.5;
|
||||
display: block;
|
||||
}
|
||||
.ue-msg {
|
||||
font-size: 12px;
|
||||
}
|
||||
.ue-msg.ok {
|
||||
color: var(--good);
|
||||
}
|
||||
.ue-msg.bad {
|
||||
color: #ff8a8a;
|
||||
}
|
||||
.ue-colors {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
}
|
||||
.ue-sw {
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
border-radius: 50%;
|
||||
border: 2px solid transparent;
|
||||
box-shadow: 0 0 0 1px #2c3f52;
|
||||
}
|
||||
.ue-sw.on {
|
||||
border-color: #fff;
|
||||
}
|
||||
.ue-sw.custom {
|
||||
background: var(--panel2);
|
||||
color: var(--muted);
|
||||
font-size: 13px;
|
||||
line-height: 1;
|
||||
}
|
||||
.ue-hidden {
|
||||
position: absolute;
|
||||
width: 0;
|
||||
height: 0;
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
}
|
||||
.ue-check {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
align-items: flex-start;
|
||||
font-size: 13px;
|
||||
margin-top: 6px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.ue-check input {
|
||||
margin-top: 3px;
|
||||
accent-color: var(--accent);
|
||||
}
|
||||
.ue-check > span {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
}
|
||||
.admin-page .panel {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.adm-dev {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
font-size: 13.5px;
|
||||
}
|
||||
.dot-st {
|
||||
display: inline-block;
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 50%;
|
||||
background: #4a5866;
|
||||
vertical-align: middle;
|
||||
}
|
||||
.dot-st.on {
|
||||
background: var(--good);
|
||||
}
|
||||
.adm-update {
|
||||
margin-left: 10px;
|
||||
color: var(--gold);
|
||||
font-weight: 700;
|
||||
font-size: 12.5px;
|
||||
}
|
||||
.adm-search {
|
||||
max-width: 240px;
|
||||
}
|
||||
.adm-note {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.adm-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
.adm-row {
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 10px;
|
||||
background: #0f1923;
|
||||
}
|
||||
.adm-row.open {
|
||||
border-color: #34506a;
|
||||
}
|
||||
.adm-sum {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 8px 12px;
|
||||
text-align: left;
|
||||
}
|
||||
.adm-nm {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.adm-role {
|
||||
width: 96px;
|
||||
}
|
||||
.adm-seen {
|
||||
width: 200px;
|
||||
text-align: right;
|
||||
}
|
||||
.adm-caret {
|
||||
color: var(--dim);
|
||||
font-size: 11px;
|
||||
}
|
||||
.adm-body {
|
||||
padding: 4px 14px 14px 52px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
align-items: flex-start;
|
||||
}
|
||||
.adm-body > .ue-block {
|
||||
width: min(520px, 100%);
|
||||
}
|
||||
.adm-acts {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
align-items: center;
|
||||
}
|
||||
.adm-acts .ue-label {
|
||||
width: 100%;
|
||||
}
|
||||
.adm-add {
|
||||
margin-top: 14px;
|
||||
padding-top: 12px;
|
||||
border-top: 1px solid var(--line);
|
||||
max-width: 560px;
|
||||
}
|
||||
.adm-sel {
|
||||
flex: none;
|
||||
width: auto;
|
||||
}
|
||||
.b-name {
|
||||
background: #13283a;
|
||||
color: #8fc6ff;
|
||||
border: 1px solid #23415c;
|
||||
}
|
||||
.b-role.superadmin {
|
||||
background: #3a1820;
|
||||
color: #ff8a95;
|
||||
}
|
||||
.b-role.admin {
|
||||
background: #2b2412;
|
||||
color: var(--gold);
|
||||
}
|
||||
.b-role.user {
|
||||
background: #18303a;
|
||||
color: var(--mint);
|
||||
}
|
||||
.btn.danger {
|
||||
border-color: #5a2029;
|
||||
color: #ff8a8a;
|
||||
}
|
||||
@media (max-width: 760px) {
|
||||
.adm-seen,
|
||||
.adm-role {
|
||||
display: none;
|
||||
}
|
||||
.adm-body {
|
||||
padding-left: 14px;
|
||||
}
|
||||
.popover.profile-pop {
|
||||
position: fixed;
|
||||
top: calc(var(--header-h) + 6px);
|
||||
left: 8px;
|
||||
right: 8px;
|
||||
width: auto;
|
||||
max-height: calc(100vh - var(--header-h) - 16px);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user