const PIPER_MODEL_ORIGIN = 'https://huggingface.co/diffusionstudio/piper-voices/resolve/main/'; const localPathPrefix = '/static/piper-wasm-v1/voices/'; export function localPiperModelUrl(requestedUrl, origin) { if (!requestedUrl.startsWith(PIPER_MODEL_ORIGIN)) return null; const relativePath = requestedUrl.slice(PIPER_MODEL_ORIGIN.length); if (!/^[\w./-]+$/.test(relativePath) || relativePath.split('/').includes('..')) return null; return new URL(`${localPathPrefix}${relativePath}`, origin).href; }