refactor(catalog): unify commands and embed guarded catalog workspace
CI / check (push) Successful in 1m16s
CI / deploy (push) Successful in 28s

This commit is contained in:
Simo committed 2026-09-06 19:40:52 +02:00
1 parent 16f35568f5
commit 193b6686a9
57 files changed
+3268 -728

No files matched your search

@@ -0,0 +1,29 @@
export interface CatalogSelection {
rootId: number | null;
pageId: number | null;
}
function positiveId(value: string | null) {
if (!value || !/^\d+$/.test(value)) return null;
const id = Number(value);
return Number.isSafeInteger(id) && id > 0 ? id : null;
}
export function readCatalogSelection(url: URL): CatalogSelection {
return {
rootId: positiveId(url.searchParams.get("root")),
pageId: positiveId(url.searchParams.get("category")),
};
}
export function writeCatalogSelection(
url: URL,
selection: CatalogSelection,
): URL {
const next = new URL(url);
for (const [key, value] of [
["root", selection.rootId],
["category", selection.pageId],
] as const) {
if (value === null) next.searchParams.delete(key);
else next.searchParams.set(key, String(value));
}
return next;
}