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
fix(server): crashing due to bad icon pack
Elian Doran2c4ac4ba30f3
diff --git a/apps/server/src/routes/index.ts b/apps/server/src/routes/index.tsindex bc94dc7bc7..a94e8e57e2 100644--- a/apps/server/src/routes/index.ts+++ b/apps/server/src/routes/index.ts@@ -62,7 +62,10 @@ function index(req: Request, res: Response) {appPath,baseApiUrl: 'api/',currentLocale: getCurrentLocale(),- iconPackCss: iconPacks.map(p => generateCss(p)).join("\n\n"),+ iconPackCss: iconPacks+ .map(p => generateCss(p))+ .filter(Boolean)+ .join("\n\n"),iconRegistry: generateIconRegistry(iconPacks)});}diff --git a/apps/server/src/services/icon_packs.ts b/apps/server/src/services/icon_packs.tsindex 4d77eddaa5..1b266ad00e 100644--- a/apps/server/src/services/icon_packs.ts+++ b/apps/server/src/services/icon_packs.ts@@ -4,6 +4,7 @@ import type BAttachment from "../becca/entities/battachment";import type BNote from "../becca/entities/bnote";import log from "./log";import search from "./search/services/search";+import { safeExtractMessageAndStackFromError } from "./utils";const PREFERRED_MIME_TYPE = ["font/woff2",@@ -92,32 +93,37 @@ export function determineBestFontAttachment(iconPackNote: BNote) {}export function generateCss({ manifest, fontAttachmentId, fontMime }: ProcessResult) {- const iconDeclarations: string[] = [];- for (const [ key, mapping ] of Object.entries(manifest.icons)) {- iconDeclarations.push(`.${manifest.prefix}.${key}::before { content: '\\${mapping.glyph.charCodeAt(0).toString(16)}'; }`);- }-- return `\- @font-face {- font-family: 'trilium-icon-pack-${manifest.prefix}';- font-weight: normal;- font-style: normal;- src: url('/api/attachments/${fontAttachmentId}/download') format('${MIME_TO_CSS_FORMAT_MAPPINGS[fontMime]}');+ try {+ const iconDeclarations: string[] = [];+ for (const [ key, mapping ] of Object.entries(manifest.icons)) {+ iconDeclarations.push(`.${manifest.prefix}.${key}::before { content: '\\${mapping.glyph.charCodeAt(0).toString(16)}'; }`);}- .${manifest.prefix} {- font-family: 'trilium-icon-pack-${manifest.prefix}' !important;- font-weight: normal;- font-style: normal;- font-variant: normal;- line-height: 1;- text-rendering: auto;- display: inline-block;- text-transform: none;- -webkit-font-smoothing: antialiased;- -moz-osx-font-smoothing: grayscale;- }-- ${iconDeclarations.join("\n")}- `;+ return `\+ @font-face {+ font-family: 'trilium-icon-pack-${manifest.prefix}';+ font-weight: normal;+ font-style: normal;+ src: url('/api/attachments/${fontAttachmentId}/download') format('${MIME_TO_CSS_FORMAT_MAPPINGS[fontMime]}');+ }++ .${manifest.prefix} {+ font-family: 'trilium-icon-pack-${manifest.prefix}' !important;+ font-weight: normal;+ font-style: normal;+ font-variant: normal;+ line-height: 1;+ text-rendering: auto;+ display: inline-block;+ text-transform: none;+ -webkit-font-smoothing: antialiased;+ -moz-osx-font-smoothing: grayscale;+ }++ ${iconDeclarations.join("\n")}+ `;+ } catch (e) {+ log.error(safeExtractMessageAndStackFromError(e));+ return null;+ }}