fix batch download (closes #1008)

This commit is contained in:
Alex Shnitman
2026-06-16 21:37:05 +03:00
parent 5aa7d033e2
commit 37f7af0555
+24 -4
View File
@@ -1189,10 +1189,22 @@ export class App implements AfterViewInit, OnInit, OnDestroy {
}); });
} }
downloadSelectedFiles() { // Chromium-based browsers silently drop programmatic downloads beyond ~10 when
// eslint-disable-next-line @typescript-eslint/no-unused-vars // triggered in a tight loop. Trigger in batches with a short pause in between so
this.downloads.done.forEach((dl, _) => { // large selections download cleanly. See issue #1008.
private static readonly DOWNLOAD_BATCH_SIZE = 10;
private static readonly DOWNLOAD_BATCH_DELAY_MS = 1000;
async downloadSelectedFiles() {
const selected: Download[] = [];
this.downloads.done.forEach((dl) => {
if (dl.status === 'finished' && dl.checked) { if (dl.status === 'finished' && dl.checked) {
selected.push(dl);
}
});
for (let i = 0; i < selected.length; i++) {
const dl = selected[i];
const link = document.createElement('a'); const link = document.createElement('a');
link.href = this.buildDownloadLink(dl); link.href = this.buildDownloadLink(dl);
link.setAttribute('download', dl.filename); link.setAttribute('download', dl.filename);
@@ -1200,8 +1212,16 @@ export class App implements AfterViewInit, OnInit, OnDestroy {
document.body.appendChild(link); document.body.appendChild(link);
link.click(); link.click();
document.body.removeChild(link); document.body.removeChild(link);
if (
(i + 1) % App.DOWNLOAD_BATCH_SIZE === 0 &&
i + 1 < selected.length
) {
await new Promise((resolve) =>
setTimeout(resolve, App.DOWNLOAD_BATCH_DELAY_MS),
);
}
} }
});
} }
buildDownloadLink(download: Download) { buildDownloadLink(download: Download) {