import { StrictMode, type ReactNode } from "react"; import { createRoot } from "react-dom/client"; import { registerPublicAssetServiceWorker } from "./public-asset-cache.js"; import { AdminAuthPage } from "./admin-auth.js"; import { UserAuthPage } from "./user-auth.js"; import { AccountSettingsPage } from "./account-settings.js"; import { AdminUsersPage } from "./admin-users.js"; import { AdminModelsPage } from "./admin-models.js"; import { AdminAssetsPage } from "./admin-assets.js"; import { AdminGenerationsPage } from "./admin-generations.js"; import { AdminServicesStoragePage } from "./admin-services-storage.js"; import { AdminAuditPage } from "./admin-audit.js"; import { CreditsPage } from "./credits-page.js"; import { ProjectDetailPage, ProjectsPage, WorkspacePage } from "./project-pages.js"; import { EditorPage } from "./editor-page.js"; import { AdminOverviewPage, AdminPlaceholderPage, AdminProtectedRoute } from "./admin-shell.js"; const root = document.getElementById("root"); if (!root) { throw new Error("Dada web root element is missing."); } // Cache failure leaves public assets network-backed and must not create alternate persistence. void registerPublicAssetServiceWorker().catch(() => undefined); const appRoot = createRoot(root); let authRevision = 0; function renderAuthenticationEntry() { authRevision += 1; const editorProject = window.location.pathname.match(/^\/app\/projects\/([0-9a-f-]{36})\/editor$/i); const projectDetail = window.location.pathname.match(/^\/app\/projects\/([0-9a-f-]{36})$/i); let authenticationPage; if (window.location.pathname === "/app/settings") authenticationPage = ; else if (window.location.pathname === "/app/credits") authenticationPage = ; else if (editorProject?.[1]) authenticationPage = ; else if (projectDetail?.[1]) authenticationPage = ; else if (window.location.pathname === "/app/projects") authenticationPage = ; else if (window.location.pathname === "/app") authenticationPage = ; else if (window.location.pathname === "/admin/login") authenticationPage = ; else if (window.location.pathname.startsWith("/admin")) { const adminPages: Record = { "/admin": { content: , title: "运营总览" }, "/admin/assets": { content: , title: "素材" }, "/admin/audit": { content: , title: "审计" }, "/admin/generations": { content: , title: "生成记录" }, "/admin/invites": { content: , title: "邀请码" }, "/admin/models": { content: , title: "模型" }, "/admin/preview": { content: , title: "内部预览" }, "/admin/services-storage": { content: , title: "服务与存储" }, "/admin/users": { content: , title: "用户与点数" }, }; const page = adminPages[window.location.pathname] ?? adminPages["/admin"]!; authenticationPage = ( {page.content} ); } else authenticationPage = ; appRoot.render( {authenticationPage} , ); } // Any authenticated surface can dispatch this after a revoked/invalid session response. window.addEventListener("dada:session-invalid", () => { if (window.location.pathname.startsWith("/app")) window.history.replaceState(null, "", "/"); renderAuthenticationEntry(); }); renderAuthenticationEntry();