From 07794bf654a0d8eb70c41fc2e0aa175fb91bcd7a Mon Sep 17 00:00:00 2001 From: Anton Shepilov Date: Fri, 15 Sep 2023 10:48:12 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9BFix=20file=20uploading=20of=20a=20b?= =?UTF-8?q?ig=20directory=20tree=20(#208)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/app/features/drive/hooks/use-drive-upload.tsx | 6 +++++- .../src/app/features/files/services/file-upload-service.ts | 7 ++++--- .../frontend/src/app/views/client/body/drive/browser.tsx | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/tdrive/frontend/src/app/features/drive/hooks/use-drive-upload.tsx b/tdrive/frontend/src/app/features/drive/hooks/use-drive-upload.tsx index 655b49430..f41dcbf15 100644 --- a/tdrive/frontend/src/app/features/drive/hooks/use-drive-upload.tsx +++ b/tdrive/frontend/src/app/features/drive/hooks/use-drive-upload.tsx @@ -48,12 +48,14 @@ export const useDriveUpload = () => { const filesPerParentId: { [key: string]: File[] } = {}; // Create all directories + console.debug("Start creating directories ..."); const createDirectories = async (tree: FileTreeObject['tree'], parentId: string) => { for (const directory of Object.keys(tree)) { if (tree[directory] instanceof File) { if (!filesPerParentId[parentId]) filesPerParentId[parentId] = []; filesPerParentId[parentId].push(tree[directory] as File); } else { + console.debug(`Create directory ${directory}`); const driveItem = await create( { company_id: context.companyId, @@ -63,6 +65,7 @@ export const useDriveUpload = () => { }, {}, ); + console.debug(`Directory ${directory} created`); if (driveItem?.id) { await createDirectories(tree[directory] as FileTreeObject['tree'], driveItem.id); } else { @@ -72,10 +75,11 @@ export const useDriveUpload = () => { } }; await createDirectories(tree.tree, context.parentId); + console.debug("All directories created"); // Upload files into directories for (const parentId of Object.keys(filesPerParentId)) { - FileUploadService.upload(filesPerParentId[parentId], { + await FileUploadService.upload(filesPerParentId[parentId], { context: { companyId: context.companyId, parentId: parentId, diff --git a/tdrive/frontend/src/app/features/files/services/file-upload-service.ts b/tdrive/frontend/src/app/features/files/services/file-upload-service.ts index d998043fa..3b04c99a8 100644 --- a/tdrive/frontend/src/app/features/files/services/file-upload-service.ts +++ b/tdrive/frontend/src/app/features/files/services/file-upload-service.ts @@ -56,8 +56,8 @@ class FileUploadService { this.currentTaskId = uuid(); } - fileList.forEach(async file => { - if (!file) return; + for (const file of fileList) { + if (!file) continue; const pendingFile: PendingFileType = { id: uuid(), @@ -140,7 +140,7 @@ class FileUploadService { options?.callback?.(null, options?.context || {}); this.notify(); }); - }); + } return this.pendingFiles.filter(f => f.uploadTaskId === this.currentTaskId); } @@ -258,6 +258,7 @@ class FileUploadService { }); } + public getDownloadRoute({ companyId, fileId }: { companyId: string; fileId: string }): string { return FileUploadAPIClient.getDownloadRoute({ companyId: companyId, diff --git a/tdrive/frontend/src/app/views/client/body/drive/browser.tsx b/tdrive/frontend/src/app/views/client/body/drive/browser.tsx index f9a06dba9..746f6188b 100644 --- a/tdrive/frontend/src/app/views/client/body/drive/browser.tsx +++ b/tdrive/frontend/src/app/views/client/body/drive/browser.tsx @@ -156,7 +156,7 @@ export default memo( if (dataTransfer) { const tree = await getFilesTree(dataTransfer); setCreationModalState({ parent_id: '', open: false }); - uploadTree(tree, { + await uploadTree(tree, { companyId, parentId, });