diff --git a/src/lib/db/client-db/seed.ts b/src/lib/db/client-db/seed.ts index 29a975e..1f19104 100644 --- a/src/lib/db/client-db/seed.ts +++ b/src/lib/db/client-db/seed.ts @@ -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 { 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}`, diff --git a/src/routes/list/+page.ts b/src/routes/list/+page.ts index ccb41ef..f803302 100644 --- a/src/routes/list/+page.ts +++ b/src/routes/list/+page.ts @@ -83,7 +83,7 @@ export const load: PageLoad = async ({ url, fetch, depends }) => { } // Browser path: seed then query local DB for songs by MAL ids - await ensureSeeded(); + await ensureSeeded({ fetch }); const malIds = malResponse.data.map((e) => e.node.id); const songRows = await getSongsForMalAnimeIds(db, malIds);