From 183020a4e3c4adf11001da8b2445f7fdab4cc5e9 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Fri, 26 Dec 2025 16:04:56 +0200 Subject: [PATCH] chore(icon_pack): return icon mappings --- apps/server/src/services/icon_packs.spec.ts | 21 ++++++++++++++++++++- apps/server/src/services/icon_packs.ts | 15 +++++++++++---- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/apps/server/src/services/icon_packs.spec.ts b/apps/server/src/services/icon_packs.spec.ts index 1dd75d71f..432d964a5 100644 --- a/apps/server/src/services/icon_packs.spec.ts +++ b/apps/server/src/services/icon_packs.spec.ts @@ -1,5 +1,5 @@ import { buildNote } from "../test/becca_easy_mocking"; -import { processIconPack } from "./icon_packs"; +import { IconPackManifest, processIconPack } from "./icon_packs"; describe("Processing icon packs", () => { it("doesn't crash if icon pack is incorrect type", () => { @@ -9,4 +9,23 @@ describe("Processing icon packs", () => { })); expect(iconPack).toBeFalsy(); }); + + it("processes manifest", () => { + const manifest: IconPackManifest = { + name: "Boxicons v2", + prefix: "bx", + icons: { + "bx-ball": "\ue9c2", + "bxs-party": "\uec92" + } + }; + const iconPack = processIconPack(buildNote({ + type: "text", + content: JSON.stringify(manifest) + })); + expect(iconPack?.iconMappings).toMatchObject({ + "bx-ball": "\ue9c2", + "bxs-party": "\uec92" + }); + }); }); diff --git a/apps/server/src/services/icon_packs.ts b/apps/server/src/services/icon_packs.ts index 1b9ee166c..0813d709d 100644 --- a/apps/server/src/services/icon_packs.ts +++ b/apps/server/src/services/icon_packs.ts @@ -1,18 +1,25 @@ import type BNote from "../becca/entities/bnote"; import log from "./log"; -interface Manifest { +export interface IconPackManifest { name: string; prefix: string; icons: Record; } -export function processIconPack(iconPackNote: BNote) { - const manifest = iconPackNote.getJsonContentSafely(); +interface ProcessResult { + iconMappings: Record; +} + +export function processIconPack(iconPackNote: BNote): ProcessResult | undefined { + const manifest = iconPackNote.getJsonContentSafely() as IconPackManifest; if (!manifest) { log.error(`Icon pack is missing JSON manifest (or has syntax errors): ${iconPackNote.title} (${iconPackNote.noteId})`); return; } - console.log("Got manifest", manifest); + + return { + iconMappings: manifest.icons + }; }