Skip to content

Commit

Permalink
@uppy/core: check capabilities in clearUploadedFiles (#5201)
Browse files Browse the repository at this point in the history
  • Loading branch information
Murderlon authored May 30, 2024
1 parent 31cc47f commit 54700c9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/@uppy/core/src/Uppy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ describe('src/Core', () => {

assert.throws(
() => core.removeFile(fileIDs[0]),
/individualCancellation is disabled/,
/The installed uploader plugin does not allow removing files during an upload/,
)

expect(core.getState().currentUploads[id]).toBeDefined()
Expand Down
14 changes: 13 additions & 1 deletion packages/@uppy/core/src/Uppy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,16 @@ export class Uppy<M extends Meta, B extends Body> {
// @todo next major: rename to `clear()`, make it also cancel ongoing uploads
// or throw and say you need to cancel manually
clearUploadedFiles(): void {
const { capabilities, currentUploads } = this.getState()
if (
Object.keys(currentUploads).length > 0 &&
!capabilities.individualCancellation
) {
throw new Error(
'The installed uploader plugin does not allow removing files during an upload.',
)
}

this.setState({ ...defaultUploadState, files: {} })
}

Expand Down Expand Up @@ -1182,7 +1192,9 @@ export class Uppy<M extends Meta, B extends Body> {
newFileIDs.length !== currentUploads[uploadID].fileIDs.length &&
!capabilities.individualCancellation
) {
throw new Error('individualCancellation is disabled')
throw new Error(
'The installed uploader plugin does not allow removing files during an upload.',
)
}

updatedUploads[uploadID] = {
Expand Down

0 comments on commit 54700c9

Please sign in to comment.