From e82b72275b5b4f74a27fcffc943a35499d123079 Mon Sep 17 00:00:00 2001 From: dswbx Date: Tue, 4 Mar 2025 11:21:33 +0100 Subject: [PATCH 1/5] moved flash message, removed theme from admin controller --- app/src/modules/server/AdminController.tsx | 125 ++++++++++----------- app/src/ui/Admin.tsx | 14 +-- app/src/ui/modules/server/FlashMessage.tsx | 2 +- app/src/ui/routes/index.tsx | 4 +- 4 files changed, 71 insertions(+), 74 deletions(-) diff --git a/app/src/modules/server/AdminController.tsx b/app/src/modules/server/AdminController.tsx index 7d48bb0..b868807 100644 --- a/app/src/modules/server/AdminController.tsx +++ b/app/src/modules/server/AdminController.tsx @@ -5,6 +5,7 @@ import { config, isDebug } from "core"; import { addFlashMessage } from "core/server/flash"; import { html } from "hono/html"; import { Fragment } from "hono/jsx"; +import { css, Style } from "hono/css"; import { Controller } from "modules/Controller"; import * as SystemPermissions from "modules/permissions"; import type { AppTheme } from "modules/server/AppServer"; @@ -23,7 +24,7 @@ export type AdminControllerOptions = { export class AdminController extends Controller { constructor( private readonly app: App, - private _options: AdminControllerOptions = {} + private _options: AdminControllerOptions = {}, ) { super(); } @@ -36,7 +37,7 @@ export class AdminController extends Controller { return { ...this._options, basepath: this._options.basepath ?? "/", - assets_path: this._options.assets_path ?? config.server.assets_path + assets_path: this._options.assets_path ?? config.server.assets_path, }; } @@ -53,7 +54,7 @@ export class AdminController extends Controller { const hono = this.create().use( authMiddleware({ //skip: [/favicon\.ico$/] - }) + }), ); const auth = this.app.module.auth; @@ -66,14 +67,14 @@ export class AdminController extends Controller { success: configs.auth.cookie.pathSuccess ?? "/", loggedOut: configs.auth.cookie.pathLoggedOut ?? "/", login: "/auth/login", - logout: "/auth/logout" + logout: "/auth/logout", }; hono.use("*", async (c, next) => { const obj = { user: c.get("auth")?.user, logout_route: this.withBasePath(authRoutes.logout), - color_scheme: configs.server.admin.color_scheme + color_scheme: configs.server.admin.color_scheme, }; const html = await this.getHtml(obj); if (!html) { @@ -97,11 +98,11 @@ export class AdminController extends Controller { console.log("redirecting to success"); return c.redirect(authRoutes.success); } - } + }, }), async (c) => { return c.html(c.get("html")!); - } + }, ); hono.get(authRoutes.logout, async (c) => { @@ -119,16 +120,16 @@ export class AdminController extends Controller { console.log("redirecting"); return c.redirect(authRoutes.login); - } + }, }), permission(SystemPermissions.schemaRead, { onDenied: async (c) => { addFlashMessage(c, "You not allowed to read the schema", "warning"); - } + }, }), async (c) => { return c.html(c.get("html")!); - } + }, ); return hono; @@ -141,12 +142,12 @@ export class AdminController extends Controller { if (this.options.html.includes(htmlBkndContextReplace)) { return this.options.html.replace( htmlBkndContextReplace, - "" + "", ); } console.warn( - `Custom HTML needs to include '${htmlBkndContextReplace}' to inject BKND context` + `Custom HTML needs to include '${htmlBkndContextReplace}' to inject BKND context`, ); return this.options.html as string; } @@ -160,27 +161,36 @@ export class AdminController extends Controller { const assets = { js: "main.js", - css: "styles.css" + css: "styles.css", }; if (isProd) { - // @ts-ignore - const manifest = await import("bknd/dist/manifest.json", { - assert: { type: "json" } - }); + let manifest: any; + if (this.options.assets_path.startsWith("http")) { + manifest = await fetch(this.options.assets_path + "manifest.json", { + headers: { + Accept: "application/json", + }, + }).then((res) => res.json()); + } else { + // @ts-ignore + manifest = await import("bknd/dist/manifest.json", { + assert: { type: "json" }, + }).then((res) => res.default); + } + // @todo: load all marked as entry (incl. css) - assets.js = manifest.default["src/ui/main.tsx"].file; - assets.css = manifest.default["src/ui/main.tsx"].css[0] as any; + assets.js = manifest["src/ui/main.tsx"].file; + assets.css = manifest["src/ui/main.tsx"].css[0] as any; } - const theme = configs.server.admin.color_scheme ?? "light"; const favicon = isProd ? this.options.assets_path + "favicon.ico" : "/favicon.ico"; return ( {/* dnd complains otherwise */} {html``} - + -