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

@uppy/core: check capabilities in clearUploadedFiles #5201

Merged
merged 3 commits into from
May 30, 2024
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
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
Loading