feat(ui): migrate to @recloudstudio/ui, add theme toggle and polish console UX

This commit is contained in:
RhenCloud committed 2026-10-03 22:54:32 +08:00
1 parent a899e16604
commit fbbff669a3
45 files changed
+1489 -1343

No files matched your search

+1
View File
@@ -8,6 +8,7 @@ export interface Env {
DISCORD_TOKEN?: string;
BASE_URL?: string;
ADMIN_USER_IDS?: string;
DEBUG_MODE?: string;
DISCORD_PUBLIC_KEY?: string;
DISCORD_APPLICATION_ID?: string;
TELEGRAM_TOKEN?: string;
+5 -1
View File
@@ -11,7 +11,7 @@ import type { Route, Group, GroupMember, GroupRole, ForgeSource, FilterNode } fr
import { loadRoutes, saveRoutes } from "../config";
import { loadFragments, saveFragments, type NamedFragment } from "../fragments";
import { evaluateFilterNode, explainFilterNode } from "../events/filter-ast";
import { getAdminSession, destroyAdminSession, clearAdminCookie } from "./session";
import { getAdminSession, destroyAdminSession, clearAdminCookie, isDebugMode } from "./session";
import { saveGroups, loadGroups, identityMatches, normalizeGroupMembers } from "./groups";
import {
requireAnyAccess,
@@ -492,6 +492,10 @@ function getRequestOrigin(event: H3Event): string {
/** GET /admin/login */
export async function adminLogin(event: H3Event): Promise<void> {
if (isDebugMode(cfEnv(event))) {
await sendRedirect(event, "/admin");
return;
}
await sendRedirect(event, "/auth/github?redirect=/admin");
}
+6 -2
View File
@@ -1,7 +1,7 @@
import type { H3Event } from "h3";
import { createError, getHeader } from "h3";
import type { Group, GroupRole } from "../types";
import { getAdminSession, type AdminSession } from "./session";
import { getAdminSession, isDebugMode, type AdminSession } from "./session";
import {
loadGroups,
resolveScope,
@@ -28,9 +28,13 @@ const AUTH_KEY = "auth";
export async function loadAuth(event: H3Event): Promise<AuthContext | null> {
const env = cfEnv(event);
initConfigStore(env);
const groups = await loadGroups(env.KV);
if (isDebugMode(env)) {
const session: AdminSession = { userId: "debug", login: "debug" };
return { session, scope: resolveScope(env, groups, session.userId, session.login), groups };
}
const session = await getAdminSession(env.KV, getHeader(event, "cookie"));
if (!session) return null;
const groups = await loadGroups(env.KV);
const scope = resolveScope(env, groups, session.userId, session.login);
return { session, scope, groups };
}
+12
View File
@@ -8,7 +8,19 @@ export interface AdminSession {
login: string;
}
export function isDebugMode(env: Env): boolean {
if (env.DEBUG_MODE === "true") return true;
const anyEnv = env as unknown as Record<string, string | undefined>;
if (anyEnv["debug_mode"] === "true") return true;
const proc = (globalThis as unknown as { process?: { env?: Record<string, string | undefined> } }).process;
if (proc?.env?.NODE_ENV !== "test") {
if (proc?.env?.DEBUG_MODE === "true" || proc?.env?.debug_mode === "true") return true;
}
return false;
}
export function isAdminUser(env: Env, userId: string, login: string): boolean {
if (isDebugMode(env)) return true;
const ids = (env.ADMIN_USER_IDS ?? "")
.split(",")
.map((s) => s.trim())