1const S="audio-v1",C="sw.js";self.addEventListener("install",e=>{console.log(C,"Installing service worker..."),self.skipWaiting()});self.addEventListener("activate",e=>{console.log(C,"Activating service worker..."),caches.open(S).then(t=>{t.keys().then(s=>{s.forEach(o=>{t.delete(o)})})}),e.waitUntil(self.clients.claim())});function h(e){self.clients.matchAll().then(t=>{t.forEach(s=>{s.postMessage({type:"download-complete",message:e})})})}function i(e){self.clients.matchAll().then(t=>{t.forEach(s=>{s.postMessage({type:"debug-log",data:e})})})}const T=e=>/restapi\.(eu\.)?deepdub\.ai\/api\/v1\/tts\/.*/.test(e.url)||/devrestapi\.deepdub\.app\/api\/v1\/tts\/.*/.test(e.url),W={dev:"wss://wsapi.deepdub.ai/dev",prod:"wss://wsapi.deepdub.ai/open"},f=new Map;function O(e){return e.includes("devrestapi")?"dev":"prod"}function P(e,t){return`${W[e]}?x-api-key=${t}`}function E(e,t){const s=`${e}:${t}`,o=f.get(s);if(o&&o.socket.readyState===WebSocket.OPEN||o&&o.socket.readyState===WebSocket.CONNECTING)return o.ready;if(o){try{o.socket.close()}catch{}f.delete(s)}const a=new WebSocket(P(e,t)),n=new Promise((c,r)=>{a.addEventListener("open",()=>{i({event:"ws-pool-connected",env:e}),c(a)}),a.addEventListener("error",()=>{f.delete(s),r(new Error("WebSocket connection failed"))})});return a.addEventListener("close",()=>{f.delete(s)}),f.set(s,{socket:a,ready:n}),n}async function R(e,t,s){const o=crypto.randomUUID(),a={...s,action:"text-to-speech",generationId:o,format:"mp3"};delete a.apiKey,delete a.cacheBust;let n;try{n=await E(e,t)}catch{i({event:"ws-connect-retry",env:e}),n=await E(e,t)}return new Promise((c,r)=>{const l=[],p=setTimeout(()=>{d(),r(new Error("WebSocket generation timed out"))},6e4);function y(L){let u;try{u=JSON.parse(L.data)}catch{return}if(u.generationId===o){if(u.error){d(),r(u.errorType||u.error);return}if(u.data){const g=N(u.data);l.push(g)}if(u.isFinished){d();const g=l.reduce((w,A)=>w+A.byteLength,0),m=new Uint8Array(g);let k=0;for(const w of l)m.set(new Uint8Array(w),k),k+=w.byteLength;c(m.buffer)}}}function d(){clearTimeout(p),n.removeEventListener("message",y),n.removeEventListener("close",v),n.removeEventListener("error",b)}function v(){d(),r(new Error("WebSocket closed during generation"))}function b(){d(),r(new Error("WebSocket error during generation"))}n.addEventListener("message",y),n.addEventListener("close",v),n.addEventListener("error",b),i({event:"ws-generate-send",generationId:o}),n.send(JSON.stringify(a))})}function N(e){const t=atob(e),s=new Uint8Array(t.length);for(let o=0;o<t.length;o++)s[o]=t.charCodeAt(o);return s.buffer}self.addEventListener("fetch",e=>{const t=e.request;T(t)&&e.respondWith(x(t))});async function x(e){const t=await caches.open(S),s=await t.match(e);if(s)return i({event:"cache-hit",url:e.url}),h(e.url),s;const o=new URL(e.url),a=o.searchParams.get("params");if(!a)return new Response("No params",{status:400});const n=JSON.parse(a);return n.realtime?U(e,n,t):I(e,n,o,t)}async function U(e,t,s){const o=t.apiKey,a=O(e.url);i({event:"ws-generate-start",url:e.url});try{const n=await R(a,o,t),c=new Response(n,{headers:{"Content-Type":"audio/mpeg","Access-Control-Allow-Origin":"*"}});return s.put(e,c.clone()),h(e.url),i({event:"ws-generate-ok",url:e.url,size:n.byteLength}),c}catch(n){const c=typeof n=="string"?n:(n==null?void 0:n.message)||"WebSocket generation failed";return i({event:"ws-generate-error",url:e.url,error:c}),new Response(JSON.stringify({success:!1,message:c}),{status:500,headers:{"Content-Type":"application/json","Access-Control-Allow-Origin":"*"}})}}async function I(e,t,s,o){const a={...e},n=t.apiKey;delete t.apiKey,s.searchParams.delete("params"),delete a.url;const c={...a,method:"POST",headers:{...e.headers,"Content-Type":"application/json","x-api-key":n},body:JSON.stringify(t)},r=await fetch(s.toString().replace("/proxy",""),c),l=r.headers.get("content-type")||"";if(r.status===200){if(!l.includes("audio")){const d=await r.clone().text();return i({event:"non-audio-200",url:e.url,contentType:l,bodyPreview:d.substring(0,500)}),new Response(d,{status:r.status,headers:{"Content-Type":l,"Access-Control-Allow-Origin":"*"}})}i({event:"tts-response-ok",url:e.url,contentType:l});const p=r.clone(),y=r.clone();return p.bytes().then(()=>{o.put(e,y),h(e.url)}),new Response(r.body,{headers:{"Content-Type":"audio/mpeg","Access-Control-Allow-Origin":"*"}})}else{const p=await r.clone().text();return i({event:"tts-error",url:e.url,status:r.status,contentType:l,bodyPreview:p.substring(0,500)}),new Response(r.body,{status:r.status})}} 2//# sourceMappingURL=sw.js.map
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.