Skip to content

Commit

Permalink
Prevent file upload when folder creation failed
Browse files Browse the repository at this point in the history
  • Loading branch information
JammingBen committed Nov 17, 2022
1 parent 1c2b103 commit 85eb7ad
Show file tree
Hide file tree
Showing 9 changed files with 645 additions and 570 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Bugfix: Prevent file upload when folder creation failed

We've fixed a bug where files would try to be uploaded if the creation of their respective folder failed beforehands.

https://github.com/owncloud/web/pull/7975
https://github.com/owncloud/web/issues/7957
30 changes: 24 additions & 6 deletions packages/web-app-files/src/helpers/resource/actions/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
isShareSpaceResource,
SpaceResource
} from 'web-client/src/helpers'
import { UppyResource } from 'web-runtime/src/composables/upload'
import { CreateDirectoryTreeResult, UppyResource } from 'web-runtime/src/composables/upload'
import { UppyService } from 'web-runtime/src/services/uppyService'
import { ConflictDialog, ResolveConflict, resolveFileNameDuplicate, ResolveStrategy } from '..'
import { locationPublicLink } from '../../../router/public'
import { locationSpacesGeneric } from '../../../router/spaces'
Expand All @@ -15,13 +16,18 @@ export class ResourcesUpload extends ConflictDialog {
private filesToUpload: File[],
private currentFiles: Resource[],
private inputFilesToUppyFiles: (inputFileOptions) => UppyResource[],
private $uppyService: any,
private $uppyService: UppyService,
private space: SpaceResource,
private currentFolder: string,
private currentFolderId: string | number,
private spaces: SpaceResource[],
private hasSpaces: boolean,
private createDirectoryTree: any,
private createDirectoryTree: (
space: SpaceResource,
currentPath: string,
files: UppyResource[],
currentFolderId?: string | number
) => Promise<CreateDirectoryTreeResult>,
createModal: (modal: object) => void,
hideModal: () => void,
showMessage: (data: object) => void,
Expand Down Expand Up @@ -77,9 +83,21 @@ export class ResourcesUpload extends ConflictDialog {

async handleUppyFileUpload(space: SpaceResource, currentFolder: string, files: UppyResource[]) {
this.$uppyService.publish('uploadStarted')
await this.createDirectoryTree(space, currentFolder, files, this.currentFolderId)
this.$uppyService.publish('addedForUpload', files)
this.$uppyService.uploadFiles(files)
const result = await this.createDirectoryTree(space, currentFolder, files, this.currentFolderId)

let filesToUpload = files
if (result.failed.length) {
filesToUpload = files.filter(
(f) => !result.failed.some((r) => f.meta.relativeFolder.startsWith(r))
)
}

if (filesToUpload.length) {
this.$uppyService.publish('addedForUpload', filesToUpload)
this.$uppyService.uploadFiles(filesToUpload)
} else {
this.$uppyService.publish('uploadCompleted', { successful: [] })
}
}

async displayOverwriteDialog(files: UppyResource[], conflicts) {
Expand Down
Loading

0 comments on commit 85eb7ad

Please sign in to comment.