feat(icon_pack): check if JSON is parsable

This commit is contained in:
Elian Doran 2025-12-26 16:00:21 +02:00
parent af4fc11a4e
commit a56a5fe1f5
No known key found for this signature in database
2 changed files with 30 additions and 0 deletions

View File

@ -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();
});
});

View File

@ -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);
}