From 530058d12121816073f1cd2a205e4c93d52084d8 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Thu, 27 Oct 2022 08:58:31 +0200 Subject: handle request cancellation --- client-web/source/sw/download_stream.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'client-web/source/sw/download_stream.ts') diff --git a/client-web/source/sw/download_stream.ts b/client-web/source/sw/download_stream.ts index 1a2fec8..0ba6289 100644 --- a/client-web/source/sw/download_stream.ts +++ b/client-web/source/sw/download_stream.ts @@ -26,7 +26,12 @@ function FallbackStreamDownload(size: number, filename?: string, progress?: (pos } } -export function StreamDownload(size: number, filename?: string, progress?: (position: number) => void) { +export function StreamDownload({ size, filename, cancel, progress }: { + size: number, + filename: string, + cancel: () => void, + progress: (position: number) => void +}) { if (!SW) FallbackStreamDownload(size, filename, progress) let position = 0 @@ -41,6 +46,13 @@ export function StreamDownload(size: number, filename?: string, progress?: (posi a.target = "_blank" a.click() + port1.onmessage = ev => { + if (ev.data.abort) { + cancel() + port1.close() + } + } + return { close() { port1.postMessage("end") -- cgit v1.2.3-70-g09d2