mirror of
https://github.com/Elysola/WebHooker.git
synced 2026-11-20 17:13:49 +00:00
feat(ui): migrate to @recloudstudio/ui, add theme toggle and polish console UX
This commit is contained in:
45 files changed
+1489
-1343
No files matched your search
@@ -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;
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
@@ -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 };
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
|
||||
Reference in new issue
Block a user