Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Respond to hub API changes for yaml download #1329

Merged
merged 1 commit into from
Sep 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions client/src/app/queries/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,34 @@ export const downloadStaticReport = async ({
applicationId,
mimeType,
}: DownloadOptions): Promise<void> => {
let acceptHeader = "application/x-tar";
const yamlAcceptHeader = "application/x-yaml";
let url = `${APPLICATIONS}/${applicationId}/analysis/report`;

switch (mimeType) {
case MimeType.YAML:
acceptHeader = "application/x-yaml";
url = `${APPLICATIONS}/${applicationId}/analysis`;
break;
case MimeType.TAR:
default:
acceptHeader = "application/x-tar";
url = `${APPLICATIONS}/${applicationId}/analysis/report`;
}

try {
const response = await axios.get(
`${APPLICATIONS}/${applicationId}/analysis/report`,
{
responseType: "blob",
const response = await axios.get(url, {
responseType: "blob",
...(MimeType.YAML && {
headers: {
Accept: acceptHeader,
Accept: yamlAcceptHeader,
},
}
);
}),
});

if (response.status !== 200) {
throw new Error("Network response was not ok when downloading file.");
}

const blob = new Blob([response.data]);
saveAs(
blob,
`analysis-report-app-${applicationId}.${acceptHeader.split("-")[1]}`
);
saveAs(blob, `analysis-report-app-${applicationId}.${mimeType}`);
} catch (error) {
console.error("There was an error downloading the file:", error);
throw error;
Expand Down