Skip to content

Commit 62a834d

Browse files
committed
Fix for #346 - Download does not download all images.
1 parent 46181f1 commit 62a834d

File tree

2 files changed

+22
-27
lines changed

2 files changed

+22
-27
lines changed

src/components/TestRunList/BulkOperation.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,13 @@ export const BulkOperation: React.FunctionComponent = () => {
125125
}
126126
if (downloadDialogOpen) {
127127
let urlsToDownload: { download: string, filename: string }[] = [];
128-
ids.forEach((id, index) => {
128+
ids.forEach((id) => {
129129
testRunService.getDetails(id.toString())
130130
.then(
131131
(e) => {
132132
urlsToDownload.push({ "download": "static/imageUploads/" + e.imageName, "filename": e.name });
133133
//Call getFile function only when all images names are pushed into the array.
134-
if (index === ids.length - 1) {
134+
if (urlsToDownload.length === ids.length) {
135135
testRunService.getFiles(urlsToDownload);
136136
}
137137
});

src/services/testRun.service.ts

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,28 @@ async function getFiles(urls: { download: string, filename: string }[]): Promise
2323

2424
// Reference : https://www.c-sharpcorner.com/article/download-multiple-file-as-zip-file-using-angular/
2525
const zip = new JSZip();
26-
urls.forEach((element, index) => {
27-
fetch(element.download)
28-
.then((res) => res.blob())
29-
.then((blob) => zip.file(element.filename, blob))
30-
.then(() => {
31-
if (index === urls.length - 1) {
32-
zip.generateAsync({ type: 'blob' })
33-
.then((content) => {
34-
if (content) {
35-
FileSaver.saveAs(content, 'vrt-test-run.zip');
36-
}
37-
});
38-
}
39-
});
40-
41-
// Downloads multiple images as individual files, kept it here for reference
42-
// Reference : https://github.com/robertdiers/js-multi-file-download/blob/master/src/main/resources/static/index.html
43-
/*
44-
urls.forEach(function (e) {
45-
fetch(e.download)
46-
.then(res => res.blob()) // Gets the response and returns it as a blob
47-
.then(blob => {
48-
FileSaver.saveAs(blob, e.filename);
49-
});
26+
for (const eachUrl of urls) {
27+
const response = await fetch(eachUrl.download);
28+
const blob = await response.blob();
29+
zip.file(eachUrl.filename, blob);
30+
}
31+
await zip.generateAsync({ type: 'blob' })
32+
.then((content) => {
33+
if (content) {
34+
FileSaver.saveAs(content, 'vrt-test-run.zip');
35+
}
5036
});
51-
*/
37+
// Downloads multiple images as individual files, kept it here for reference
38+
// Reference : https://github.com/robertdiers/js-multi-file-download/blob/master/src/main/resources/static/index.html
39+
/*
40+
urls.forEach(function (e) {
41+
fetch(e.download)
42+
.then(res => res.blob()) // Gets the response and returns it as a blob
43+
.then(blob => {
44+
FileSaver.saveAs(blob, e.filename);
45+
});
5246
});
47+
*/
5348
}
5449

5550
async function getDetails(id: string): Promise<TestRun> {

0 commit comments

Comments
 (0)