Skip to content

Commit

Permalink
fix(download): use contextual URL mapping for file downloads
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewazores committed Jan 31, 2025
1 parent e12c454 commit 8f6d51c
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/app/Shared/Services/Api.service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -857,11 +857,13 @@ export class ApiService {
}

downloadRecording(recording: Recording): void {
this.downloadFile(recording.downloadUrl, recording.name + (recording.name.endsWith('.jfr') ? '' : '.jfr'));
this.downloadFile(
createBlobURL(JSON.stringify(recording.metadata), 'application/json'),
recording.name.replace(/\.jfr$/, '') + '.metadata.json',
);
this.ctx.url(recording.downloadUrl).subscribe((resourceUrl) => {
this.downloadFile(resourceUrl, recording.name + (recording.name.endsWith('.jfr') ? '' : '.jfr'));
this.downloadFile(
createBlobURL(JSON.stringify(recording.metadata), 'application/json'),
recording.name.replace(/\.jfr$/, '') + '.metadata.json',
);
});
}

downloadTemplate(template: EventTemplate): void {
Expand All @@ -875,19 +877,25 @@ export class ApiService {
`/api/v4/targets/${target!.id}/event_templates/${encodeURIComponent(template.type)}/${encodeURIComponent(template.name)}`,
),
),
concatMap((resourceUrl) => this.ctx.url(resourceUrl)),
)
.subscribe((resourceUrl) => {
this.downloadFile(resourceUrl, `${template.name}.jfc`);
});
}

downloadRule(name: string): void {
const filename = `${name}.json`;
this.doGet<Rule>(`rules/${name}`)
.pipe(first())
.subscribe((rule) => {
const filename = `${rule.name}.json`;
const file = new File([JSON.stringify(rule)], filename);
const resourceUrl = URL.createObjectURL(file);
.pipe(
first(),
map((rule) => {
const file = new File([JSON.stringify(rule)], filename);
return URL.createObjectURL(file);
}),
concatMap((resourceUrl) => this.ctx.url(resourceUrl)),
)
.subscribe((resourceUrl) => {
this.downloadFile(resourceUrl, filename);
setTimeout(() => URL.revokeObjectURL(resourceUrl), 1000);
});
Expand Down

0 comments on commit 8f6d51c

Please sign in to comment.