Anki/ts/routes/card-info/[cardId]/+page.ts
llama a2ad0bce55
Fix CardInfoPlaceholder not showing when card id is invalid (#3631)
* Catch bigint parsing error

* Modify CONTRIBUTORS
2024-12-14 21:32:51 +11:00

19 lines
555 B
TypeScript

// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import { cardStats } from "@generated/backend";
import type { PageLoad } from "./$types";
function optionalBigInt(x: any): bigint | null {
try {
return BigInt(x);
} catch (e) {
return null;
}
}
export const load = (async ({ params }) => {
const cid = optionalBigInt(params.cardId);
const info = cid !== null ? await cardStats({ cid }) : null;
return { info };
}) satisfies PageLoad;