Переглянути джерело

@uppy/core: check capabilities in clearUploadedFiles (#5201)

Merlijn Vos 10 місяців тому
батько
коміт
54700c91eb
2 змінених файлів з 14 додано та 2 видалено
  1. 1 1
      packages/@uppy/core/src/Uppy.test.ts
  2. 13 1
      packages/@uppy/core/src/Uppy.ts

+ 1 - 1
packages/@uppy/core/src/Uppy.test.ts

@@ -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()

+ 13 - 1
packages/@uppy/core/src/Uppy.ts

@@ -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: {} })
   }
 
@@ -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] = {