- added feature to cache sounds for cross devices - should work in theory

This commit is contained in:
2025-10-29 15:04:40 +00:00
parent cf72a1e1d3
commit a8abed2246
10 changed files with 56 additions and 26 deletions

View File

@@ -1,12 +1,15 @@
export async function getOrCacheBlob(url: string) {
console.log(url);
const cache = await caches.open("app-sounds-v1");
if (cache) console.log(cache);
const hit = await cache.match(url);
if (hit) return await hit.blob();
const res = await fetch(url, { cache: "no-store" });
console.log("fetching...");
if (!res.ok) throw new Error(`Fetch failed: ${res.status}`);
await cache.put(url, res.clone());
await cache.put(url, res.clone());
return await res.blob();
}

View File

@@ -0,0 +1,24 @@
import { getSoundFileURL } from "./utils";
import { CAM_BASE } from "./config";
import type { SoundUploadValue } from "../types/types";
export function resolveSoundSource(
selected: string | undefined,
soundOptions: SoundUploadValue[] | undefined
): { type: "uploaded"; url: string } | { type: "builtin"; url: string } | undefined {
if (!selected) return undefined;
const isFile = selected.endsWith(".mp3") || selected.endsWith(".wav");
if (isFile) {
const match = soundOptions?.find((o) => o.soundFileName === selected);
const version = match?.uploadedAt ?? 0;
const url = `${CAM_BASE}/Mobile/${encodeURIComponent(selected)}?v=${version}`;
return { type: "uploaded", url };
}
const builtin = getSoundFileURL(selected);
if (builtin) return { type: "builtin", url: builtin };
return undefined;
}