🐛Fix file uploading of a big directory tree (#208)
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user