Files
ai-spel-frontend/piper-model-routing.mjs
Ein Anderssono ed0a8b90a6
Build and publish frontend / publish (push) Successful in 49s
Serve Piper speech assets from dedicated static service
2026-10-16 07:32:34 +02:00

10 lines
513 B
JavaScript

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;
}