add option to use sveltekit's fetch for seeding db

This commit is contained in:
2026-02-05 22:31:37 -08:00
parent 03ce24d707
commit 2f0426ce2e
2 changed files with 5 additions and 3 deletions

View File

@@ -36,14 +36,16 @@ function ensureBrowser() {
*
* @param opts.version Bump to force users to refresh from the shipped snapshot
* @param opts.force If true, reseed even if already seeded for this version
* @param opts.fetch Optional fetch implementation (prefer the one from load)
*/
export async function ensureSeeded(
opts: { version?: number; force?: boolean } = {},
opts: { version?: number; force?: boolean; fetch?: typeof fetch } = {},
): Promise<void> {
ensureBrowser();
const version = opts.version ?? AMQ_DB_SEED_VERSION;
const key = seededStorageKey(version);
const fetcher = opts.fetch ?? fetch;
if (!opts.force && localStorage.getItem(key) === "1") return;
@@ -56,7 +58,7 @@ export async function ensureSeeded(
const url = asset(SEED_ASSET_PATH);
const res = await fetch(url, { cache: "no-cache" });
const res = await fetcher(url, { cache: "no-cache" });
if (!res.ok) {
throw new Error(
`Failed to fetch seed DB from ${url}: ${res.status} ${res.statusText}`,