Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(badges): add dedicated badge for custom request handler
Elian Dorana37da0f254dc
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex 4708b28497..ab06d79e90 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -2600,6 +2600,7 @@"active_content_badges": {"type_icon_pack": "Icon pack","type_backend_script": "Backend script",+ "type_custom_request_handler": "Custom request handler","type_frontend_script": "Frontend script","type_widget": "Widget","type_app_css": "Custom CSS",diff --git a/apps/client/src/widgets/layout/ActiveContentBadges.tsx b/apps/client/src/widgets/layout/ActiveContentBadges.tsxindex 99e05bca52..358f95fc2e 100644--- a/apps/client/src/widgets/layout/ActiveContentBadges.tsx+++ b/apps/client/src/widgets/layout/ActiveContentBadges.tsx@@ -17,7 +17,7 @@ const DANGEROUS_ATTRIBUTES = BUILTIN_ATTRIBUTES.filter(a => a.isDangerous || NONconst activeContentLabels = [ "iconPack", "widget", "appCss", "appTheme" ] as const;interface ActiveContentInfo {- type: "iconPack" | "backendScript" | "frontendScript" | "widget" | "appCss" | "renderNote" | "webView" | "appTheme";+ type: "iconPack" | "backendScript" | "customRequestHandler" | "frontendScript" | "widget" | "appCss" | "renderNote" | "webView" | "appTheme";isEnabled: boolean;canToggleEnabled: boolean;}@@ -66,6 +66,12 @@ const typeMappings: Record<ActiveContentInfo["type"], {}]},+ customRequestHandler: {+ title: t("active_content_badges.type_custom_request_handler"),+ icon: "bx bx-world",+ helpPage: "J5Ex1ZrMbyJ6",+ apiDocsPage: "MEtfsqa5VwNi",+ },frontendScript: {title: t("active_content_badges.type_frontend_script"),icon: "bx bx-window",@@ -240,12 +246,21 @@ function useActiveContentInfo(note: FNote | null | undefined) {type = "webView";isEnabled = note.hasLabel("webViewSrc");} else if (noteType === "code" && noteMime === "application/javascript;env=backend") {- type = "backendScript";- for (const backendLabel of [ "run", "customRequestHandler", "customResourceProvider" ]) {- isEnabled ||= note.hasLabel(backendLabel);+ if (note.hasLabelOrDisabled("customRequestHandler")) {+ // A custom request handler takes precedence over the generic backend script badge:+ // it's invoked via the /custom/* route with req/res, so the run/execute controls+ // (which provide no req/res) don't apply.+ type = "customRequestHandler";+ isEnabled = note.hasLabel("customRequestHandler");+ canToggleEnabled = true;+ } else {+ type = "backendScript";+ for (const backendLabel of [ "run", "customRequestHandler", "customResourceProvider" ]) {+ isEnabled ||= note.hasLabel(backendLabel);- if (!canToggleEnabled && note.hasLabelOrDisabled(backendLabel)) {- canToggleEnabled = true;+ if (!canToggleEnabled && note.hasLabelOrDisabled(backendLabel)) {+ canToggleEnabled = true;+ }}}} else if (noteType === "code" && noteMime === "application/javascript;env=frontend") {