Browse Source

core: Return { successful, failed } object from .upload().

Renée Kooi 7 years ago
parent
commit
874bad50d8
3 changed files with 19 additions and 5 deletions
  1. 8 3
      examples/bundled-example/main.js
  2. 8 0
      src/core/Core.js
  3. 3 2
      src/plugins/GoldenRetriever/index.js

+ 8 - 3
examples/bundled-example/main.js

@@ -72,9 +72,14 @@ const uppy = Uppy({
   // .use(GoldenRetriever, {serviceWorker: true})
   .run()
 
-uppy.on('core:success', (fileList) => {
-  console.log('UPLOAD SUCCESSFUL!!!')
-  console.log(fileList)
+uppy.on('core:complete', ({ successful, failed }) => {
+  if (failed.length === 0) {
+    console.log('UPLOAD SUCCESSFUL!!!')
+  } else {
+    console.warn('UPLOAD FAILED!!!')
+  }
+  console.log('successful files:', successful)
+  console.log('failed files:', failed)
 })
 
 if ('serviceWorker' in navigator) {

+ 8 - 0
src/core/Core.js

@@ -1055,9 +1055,17 @@ class Uppy {
     })
 
     return lastStep.then(() => {
+      const files = fileIDs.map((fileID) => this.getFile(fileID))
+      const successful = files.filter((file) => !file.error)
+      const failed = files.filter((file) => file.error)
+      this.emit('core:complete', { successful, failed })
+
+      // Compatibility with pre-0.21
       this.emit('core:success', fileIDs)
 
       this.removeUpload(uploadID)
+
+      return { successful, failed }
     })
   }
 

+ 3 - 2
src/plugins/GoldenRetriever/index.js

@@ -213,9 +213,10 @@ module.exports = class GoldenRetriever extends Plugin {
       this.IndexedDBStore.delete(fileID)
     })
 
-    this.core.on('core:success', (fileIDs) => {
+    this.core.on('core:complete', ({ successful }) => {
+      const fileIDs = successful.map((file) => file.id)
       this.deleteBlobs(fileIDs).then(() => {
-        this.core.log(`[GoldenRetriever] removed ${fileIDs.length} files that finished uploading`)
+        this.core.log(`RestoreFiles: removed ${successful.length} files that finished uploading`)
       })
     })