Track Piper model bytes in the worker
Build and publish frontend / publish (push) Successful in 47s

This commit is contained in:
Ein Anderssono
2026-10-16 08:02:17 +02:00
parent ab574acd39
commit 7f77b904ac
6 changed files with 95 additions and 8 deletions
+32
View File
@@ -0,0 +1,32 @@
export function trackModelDownload(response, {id, postMessage}) {
const reader = response.body?.getReader?.();
if (!reader || typeof ReadableStream !== 'function' || typeof Response !== 'function') return response;
const total = Number(response.headers.get('content-length')) || 0;
let loaded = 0;
const body = new ReadableStream({
async pull(controller) {
try {
const {done, value} = await reader.read();
if (done) {
controller.close();
return;
}
loaded += value.byteLength;
postMessage({id, type: 'progress', progress: {loaded, total}});
controller.enqueue(value);
} catch (error) {
controller.error(error);
}
},
cancel(reason) {
return reader.cancel(reason);
},
});
return new Response(body, {
status: response.status,
statusText: response.statusText,
headers: response.headers,
});
}