Skip to content

Commit

Permalink
Merge pull request #274 from Lodestone-Team/download_folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Ynng committed Jun 29, 2023
2 parents b346a07 + 9071734 commit f4c28ae
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
17 changes: 6 additions & 11 deletions src/components/FileViewer/FileViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,20 +206,15 @@ export default function FileViewer() {

const downloadTickedFiles = async () => {
if (!tickedFiles) return;
const missedDirectories: string[] = [];

for (const file of tickedFiles) {
const timeout = file?.file_type == 'Directory' ? 60000 : 5000;
if (file.file_type === 'Directory') {
missedDirectories.push(file.path);
} else if (file.file_type === 'File') {
downloadInstanceFile(instance.uuid, file);
tickFile(file, false);
toast.info('Zipping directory for download...');
}
}
if (missedDirectories.length > 0) {
const missedDirectoriesString = missedDirectories.join(', ');
toast.error(
`Downloading a directory is not supported. The following directories were not downloaded: ${missedDirectoriesString}`
);

downloadInstanceFile(instance.uuid, file, timeout);
tickFile(file, false);
}
};

Expand Down
8 changes: 5 additions & 3 deletions src/utils/apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,19 +120,21 @@ export const deleteInstanceDirectory = async (

export const requestInstanceFileUrl = async (
uuid: string,
file: ClientFile
file: ClientFile,
timeout = 5000,
): Promise<string> => {
const tokenResponse = await axiosWrapper<string>({
method: 'get',
url: `/instance/${uuid}/fs/${Base64.encode(file.path, true)}/url`,
timeout: timeout,
});
return axios.defaults.baseURL + `/file/${tokenResponse}`;
};

export const downloadInstanceFile = async (uuid: string, file: ClientFile) => {
export const downloadInstanceFile = async (uuid: string, file: ClientFile, timeout = 5000) => {
// TODO handle errors

window.open(await requestInstanceFileUrl(uuid, file), '_blank');
window.open(await requestInstanceFileUrl(uuid, file, timeout), '_blank');
};

export const uploadInstanceFiles = async (
Expand Down

0 comments on commit f4c28ae

Please sign in to comment.