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 bug unable to recreate document or folder #835

Merged
merged 1 commit into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
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
13 changes: 13 additions & 0 deletions tdrive/frontend/src/app/components/uploads/file-tree-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,16 @@ export const getFilesTree = (
}
});
};

export const getFileIdsInTree = (tree: FileTreeObject['tree']): string[] => {
const fileIds: string[] = [];
for (const directory of Object.keys(tree)) {
if (tree[directory].root) {
fileIds.push(tree[directory].root as string);
} else {
getFileIdsInTree(tree[directory] as FileTreeObject['tree']);
}
}

return fileIds;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FileTreeObject } from '@components/uploads/file-tree-utils';
import { FileTreeObject, getFileIdsInTree } from '@components/uploads/file-tree-utils';
import FileUploadService from '@features/files/services/file-upload-service';
import { ToasterService } from '@features/global/services/toaster-service';
import { DriveApiClient } from '../api-client/api-client';
Expand All @@ -16,6 +16,7 @@ export const useDriveUpload = () => {

const uploadVersion = async (file: File, context: { companyId: string; id: string }) => {
return new Promise(r => {
FileUploadService.resetStates([file.name]);
FileUploadService.upload([{ root: file.name, file }], {
context: {
companyId: context.companyId,
Expand Down Expand Up @@ -49,6 +50,7 @@ export const useDriveUpload = () => {
context: { companyId: string; parentId: string },
) => {
logger.debug('Start creating directories and file upload ...');
FileUploadService.resetStates(getFileIdsInTree(tree.tree));
await FileUploadService.createDirectories(tree, context);
await refresh(context.parentId, true);
};
Expand All @@ -68,6 +70,7 @@ export const useDriveUpload = () => {
`Unexpected response status code: ${request.status} from ${JSON.stringify(url)}`,
);
const file = new File([request.response], name);
FileUploadService.resetStates([file.name]);
FileUploadService.upload([{ root: file.name, file }], {
context: {
companyId: context.companyId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ export const useUploadZones = (zoneId: string) => {
list: File[],
options?: { uploader?: (file: File, context: any) => Promise<FileType>; context?: any },
) => {
FileUploadService.resetStates(list.map((file) => file.name));
const newFiles = await FileUploadService.upload(
list.map((file, index) => {
list.map((file) => {
return {
root: file.name,
file,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import FileUploadAPIClient from '../api/file-upload-api-client';
import { isPendingFileStatusPending } from '../utils/pending-files';
import { FileTreeObject } from 'components/uploads/file-tree-utils';
import { DriveApiClient } from 'features/drive/api-client/api-client';
import { ToasterService } from 'app/features/global/services/toaster-service';
import Languages from 'app/features/global/services/languages-service';
import { DriveItem, DriveItemVersion } from 'app/features/drive/types';

export enum Events {
Expand Down Expand Up @@ -63,6 +61,9 @@ class FileUploadService {
* @private
*/
async _waitWhilePaused(id?: string) {
logger.debug('===== _waitWhilePaused ======');
logger.debug('rootStates: ', this.rootStates);
logger.debug('status: ', this.uploadStatus)
while (this.uploadStatus === UploadStateEnum.Paused || (id && this.rootStates.paused[id])) {
if (this.uploadStatus === UploadStateEnum.Cancelled || (id && this.rootStates.cancelled[id]))
return;
Expand Down Expand Up @@ -305,10 +306,14 @@ class FileUploadService {
callback?: (file: { root: string; file: FileType | null }, context: any) => void;
},
): Promise<PendingFileType[]> {
logger.debug('===== upload =====');
logger.debug('uploadStatus: ', this.uploadStatus);

// reset the upload status when creating a new document
if (fileList.length === 1 && fileList[0].root === fileList[0].file.name) {
this.pauseOrResume();
if (this.uploadStatus === UploadStateEnum.Paused) {
this.uploadStatus = UploadStateEnum.Progress;
}
}

// if we're uploading one file directly, do the size calc first
Expand Down Expand Up @@ -746,6 +751,28 @@ class FileUploadService {
this.groupIds = {};
this.notify();
}

public resetStates(ids: string[]) {
this.logger.debug('===== START resetStates =====');
this.logger.debug('groupedPendingFiles: ', this.groupedPendingFiles);
this.logger.debug('groupIds: ', this.groupIds);
this.logger.debug('rootStates: ', this.rootStates);

this.uploadStatus = UploadStateEnum.Progress;
for (const id of ids) {
delete this.groupedPendingFiles[id];
delete this.groupIds[id];
delete this.rootStates.paused[id];
delete this.rootStates.completed[id];
delete this.rootStates.failed[id];
delete this.rootStates.cancelled[id];
}

this.logger.debug('===== END resetStates =====');
this.logger.debug('groupedPendingFiles: ', this.groupedPendingFiles);
this.logger.debug('groupIds: ', this.groupIds);
this.logger.debug('rootStates: ', this.rootStates);
}
}

export default new FileUploadService();
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const CreateLink = () => {
type: 'text/uri-list',
});

FileUploadService.resetStates([file.name]);
await FileUploadService.upload([{ root: file.name, file }], {
context: {
parentId: state.parent_id,
Expand Down