Skip to content

Commit

Permalink
Merge pull request #70 from venit1123/CSCwj84515
Browse files Browse the repository at this point in the history
CSCwj84515: only download file when response returns zip file - and f…
  • Loading branch information
venit1123 authored May 3, 2024
2 parents 085ca1d + 55e8d2b commit 553ca30
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/components/Operation/Operation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,21 +163,24 @@ export class Operation extends React.Component<OperationProps, OperationState> {
setCookieParams(cookieParams);

this.setState({ pendingRequest: true });
fetch(`${appendParamsToPath(path, pathParams, queryParams)}`, request)
const api_url = `${appendParamsToPath(path, pathParams, queryParams)}`
fetch(api_url, request)
.then(async (response: any) => {
const statusCode = response.status;
const statusType = mapStatusCodeToType(statusCode);
const isError = statusType === 'error';
const contentType = response.headers.get('content-type');

if (contentType?.indexOf('application/zip') !== -1 && !isError) {
const slug = last(path?.split('/') || []);
if (contentType && contentType?.indexOf('application/zip') !== -1 && !isError) {
const slug = last(api_url?.split('/') || []);
const fileName = slug || 'file';
const bytes = await response.blob();

const temporaryAnchor = document.createElement('a');
temporaryAnchor.href = URL.createObjectURL(bytes);
temporaryAnchor.setAttribute('download', fileName);
temporaryAnchor.click();

this.setState({
response: {
type: mapStatusCodeToType(statusCode),
Expand Down

0 comments on commit 553ca30

Please sign in to comment.