Frontend: - migrate from Vite to Astro (astro.config.mjs, pages/, layouts/) - add admin panel, settings page, command palette, error boundary - refactor App.tsx, MascotChatbot, Sidebar, Header, DashboardLayout - update API client, WebSocket, auth, dashboard features Backend: - add admin module and config routes - refactor middlewares, Redis connection, WebSocket server/bridge - add runtime config loader Discord Gateway: - refactor AI moderation: circuit breaker, concurrency limiter, fallback processor - add media analysis client, Seaxng search, user profile learner - add new drizzle migration Shared: - extend database schema, add new config fields
51 lines
1.4 KiB
TypeScript
51 lines
1.4 KiB
TypeScript
import { createChildLogger } from "@bete/shared/logger";
|
|
import type { Request, Response, Router } from "express";
|
|
import express from "express";
|
|
import { asyncHandler } from "../../shared/middlewares/index.js";
|
|
import { uiStateService } from "./ui-state.service.js";
|
|
|
|
const logger = createChildLogger("ui-state.routes");
|
|
|
|
// Allowed UI state keys — reject any update that does not match these.
|
|
const ALLOWED_KEYS = new Set([
|
|
"activeTab",
|
|
"selectedVoiceGuild",
|
|
"selectedVoiceChannel",
|
|
"selectedTextChannel",
|
|
"sidebarCollapsed",
|
|
]);
|
|
|
|
export function createUiStateRouter(): Router {
|
|
const router = express.Router();
|
|
|
|
// GET /api/ui-state
|
|
router.get(
|
|
"/ui-state",
|
|
asyncHandler(async (_req: Request, res: Response) => {
|
|
logger.debug("Fetching UI state");
|
|
const state = await uiStateService.getState();
|
|
res.json(state);
|
|
}),
|
|
);
|
|
|
|
// POST /api/ui-state
|
|
router.post(
|
|
"/ui-state",
|
|
asyncHandler(async (req: Request, res: Response) => {
|
|
const updates = req.body as Record<string, unknown>;
|
|
logger.debug({ keys: Object.keys(updates) }, "Updating UI state");
|
|
// Filter to only allow known safe keys
|
|
const filtered: Record<string, unknown> = {};
|
|
for (const key of Object.keys(updates)) {
|
|
if (ALLOWED_KEYS.has(key)) {
|
|
filtered[key] = updates[key];
|
|
}
|
|
}
|
|
const result = await uiStateService.updateState(filtered);
|
|
res.json(result);
|
|
}),
|
|
);
|
|
|
|
return router;
|
|
}
|