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(icon_pack): check if JSON is parsable
Elian Dorana56a5fe1f535
diff --git a/apps/server/src/services/icon_packs.spec.ts b/apps/server/src/services/icon_packs.spec.tsnew file mode 100644index 0000000000..1dd75d71ff--- /dev/null+++ b/apps/server/src/services/icon_packs.spec.ts@@ -0,0 +1,12 @@+import { buildNote } from "../test/becca_easy_mocking";+import { processIconPack } from "./icon_packs";++describe("Processing icon packs", () => {+ it("doesn't crash if icon pack is incorrect type", () => {+ const iconPack = processIconPack(buildNote({+ type: "text",+ content: "Foo"+ }));+ expect(iconPack).toBeFalsy();+ });+});diff --git a/apps/server/src/services/icon_packs.ts b/apps/server/src/services/icon_packs.tsnew file mode 100644index 0000000000..1b9ee166c6--- /dev/null+++ b/apps/server/src/services/icon_packs.ts@@ -0,0 +1,18 @@+import type BNote from "../becca/entities/bnote";+import log from "./log";++interface Manifest {+ name: string;+ prefix: string;+ icons: Record<string, string>;+}++export function processIconPack(iconPackNote: BNote) {+ const manifest = iconPackNote.getJsonContentSafely();+ if (!manifest) {+ log.error(`Icon pack is missing JSON manifest (or has syntax errors): ${iconPackNote.title} (${iconPackNote.noteId})`);+ return;+ }++ console.log("Got manifest", manifest);+}