- added feature to cache sounds for cross devices - should work in theory
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
24
src/utils/soundResolver.ts
Normal file
24
src/utils/soundResolver.ts
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user