Skip to content

Commit

Permalink
Download file fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
DoraCretu594118 committed Nov 3, 2023
1 parent 86b8c85 commit 907472b
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions public/app/percona/pmm-dump/PMMDump.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CancelToken, AxiosResponse } from 'axios';
import { CancelToken } from 'axios';

import { PmmDump, ExportDatasetProps } from 'app/percona/shared/core/reducers/pmmDump/pmmDump.types';
import { api } from 'app/percona/shared/helpers/api';
Expand Down Expand Up @@ -38,22 +38,20 @@ export const PMMDumpService = {
async delete(dumpIds: string[]) {
await api.post<void, DeleteDump>(`${BASE_URL}/Delete`, { dump_ids: dumpIds });
},
async dowload(dumpIds: string[]) {
for (const dumpId of dumpIds) {
api.get<AxiosResponse<Blob>, DeleteDump>(`/dump/${dumpId}.tar.gz`).then((response: AxiosResponse<Blob>) => {
const blob = new Blob([response.data], { type: 'application/gzip' });
const url = window.URL.createObjectURL(blob);
dowload(dumpIds: string[], index = 0) {
if (index < dumpIds.length) {
const dumpId = dumpIds[index];
const link = document.createElement('a');
link.setAttribute('href', `${window.location.origin}/dump/${dumpId}.tar.gz`);
link.setAttribute('download', `${dumpId}.tar.gz`);
document.body.appendChild(link);
link.click();
document.body.removeChild(link);

const a = document.createElement('a');
a.style.display = 'none';
a.href = url;
a.download = `${dumpId}.tar.gz`;

document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
document.body.removeChild(a);
});
// Add a delay (1000ms) before the next download
setTimeout(() => {
PMMDumpService.dowload(dumpIds, index + 1);
}, 1000);
}
},
async sendToSupport(body: SendToSupportRequestBody) {
Expand Down

0 comments on commit 907472b

Please sign in to comment.