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

Fix multiple file download in resource container #1528

Merged
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
26 changes: 16 additions & 10 deletions src/shared/components/Preview/Preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { useSelector } from 'react-redux';
import { RootState } from '../../store/reducers';
import nexusUrlHardEncode from '../../utils/nexusEncode';
import { TError } from '../../../utils/types';
import * as Sentry from '@sentry/browser';

export const parseResourceId = (url: string) => {
const fileUrlPattern = /files\/([\w-]+)\/([\w-]+)\/(.*)/;
Expand Down Expand Up @@ -176,22 +177,27 @@ const Preview: React.FC<{
body: JSON.stringify(payload),
}
);
const archive = await nexus.httpGet({
path: `${apiEndpoint}/archives/${orgLabel}/${projectLabel}/${payload.archiveId}?ignoreNotFound=true`,
headers: { accept: 'application/zip, application/json' },
context: {
parseAs: 'blob',
},
});
const blob = archive as Blob;
const archiveName = `data-${payload.archiveId}.zip`;
downloadBlobHelper(blob, archiveName);

notification.success({
message: `Archive ${archiveName} downloaded successfully`,
});
} catch (error) {
Sentry.captureException({ error, message: 'Failed to download archive' });
notification.error({
message: 'Failed to download the file',
description: (error as TError).reason || (error as TError).message,
});
}
const archive = (await nexus.Archive.get(
orgLabel,
projectLabel,
archiveId,
{
as: 'x-tar',
}
)) as string;
const blob = new Blob([archive]);
downloadBlobHelper(blob, `${archiveId}.tar.gz`);
};

const downloadButton = (disabled: boolean) => {
Expand Down
Loading