Forráskód Böngészése

core: Start a completely new upload when retrying.

Renée Kooi 7 éve
szülő
commit
d7557bd13d
2 módosított fájl, 25 hozzáadás és 25 törlés
  1. 24 20
      src/core/Core.js
  2. 1 5
      src/plugins/Dashboard/index.js

+ 24 - 20
src/core/Core.js

@@ -84,6 +84,7 @@ class Uppy {
     this.resumeAll = this.resumeAll.bind(this)
     this.resumeAll = this.resumeAll.bind(this)
     this.retryAll = this.retryAll.bind(this)
     this.retryAll = this.retryAll.bind(this)
     this.cancelAll = this.cancelAll.bind(this)
     this.cancelAll = this.cancelAll.bind(this)
+    this.retryUpload = this.retryUpload.bind(this)
 
 
     // this.bus = this.emitter = ee()
     // this.bus = this.emitter = ee()
     this.emitter = ee()
     this.emitter = ee()
@@ -471,10 +472,6 @@ class Uppy {
 
 
   retryAll () {
   retryAll () {
     const updatedFiles = Object.assign({}, this.getState().files)
     const updatedFiles = Object.assign({}, this.getState().files)
-    // const inProgressUpdatedFiles = Object.keys(updatedFiles).filter((file) => {
-    //   return !updatedFiles[file].progress.uploadComplete &&
-    //          updatedFiles[file].progress.uploadStarted
-    // })
     const filesToRetry = Object.keys(updatedFiles).filter(file => {
     const filesToRetry = Object.keys(updatedFiles).filter(file => {
       return updatedFiles[file].error
       return updatedFiles[file].error
     })
     })
@@ -486,16 +483,36 @@ class Uppy {
       })
       })
       updatedFiles[file] = updatedFile
       updatedFiles[file] = updatedFile
     })
     })
-    this.setState({files: updatedFiles})
+    this.setState({
+      files: updatedFiles,
+      error: null
+    })
 
 
     this.emit('core:retry-all', filesToRetry)
     this.emit('core:retry-all', filesToRetry)
+
+    const uploadID = this.createUpload(filesToRetry)
+    return this.runUpload(uploadID)
+  }
+
+  retryUpload (fileID) {
+    const updatedFiles = Object.assign({}, this.state.files)
+    const updatedFile = Object.assign({}, updatedFiles[fileID],
+      { error: null, isPaused: false }
+    )
+    updatedFiles[fileID] = updatedFile
+    this.setState({
+      files: updatedFiles
+    })
+
+    this.emit('core:upload-retry', fileID)
+
+    const uploadID = this.createUpload([ fileID ])
+    return this.runUpload(uploadID)
   }
   }
 
 
   reset () {
   reset () {
     this.cancelAll()
     this.cancelAll()
     // this.pauseAll()
     // this.pauseAll()
-    // this.emit('core:pause-all')
-    // this.emit('core:cancel-all')
   }
   }
 
 
   cancelAll () {
   cancelAll () {
@@ -594,19 +611,6 @@ class Uppy {
       this.info(message, 'error', 5000)
       this.info(message, 'error', 5000)
     })
     })
 
 
-    this.on('core:upload-retry', (fileID) => {
-      const updatedFiles = Object.assign({}, this.state.files)
-      const updatedFile = Object.assign({}, updatedFiles[fileID],
-        { error: null, isPaused: false }
-      )
-      updatedFiles[fileID] = updatedFile
-      this.setState({files: updatedFiles})
-    })
-
-    this.on('core:retry-all', () => {
-      this.setState({ error: null })
-    })
-
     this.on('core:upload', () => {
     this.on('core:upload', () => {
       this.setState({ error: null })
       this.setState({ error: null })
     })
     })

+ 1 - 5
src/plugins/Dashboard/index.js

@@ -327,10 +327,6 @@ module.exports = class DashboardUI extends Plugin {
       })
       })
     }
     }
 
 
-    const retryUpload = (fileID) => {
-      this.core.emit('core:upload-retry', fileID)
-    }
-
     const cancelUpload = (fileID) => {
     const cancelUpload = (fileID) => {
       this.core.emit('core:upload-cancel', fileID)
       this.core.emit('core:upload-cancel', fileID)
       this.core.emit('core:file-remove', fileID)
       this.core.emit('core:file-remove', fileID)
@@ -378,7 +374,7 @@ module.exports = class DashboardUI extends Plugin {
       resumableUploads: this.core.state.capabilities.resumableUploads || false,
       resumableUploads: this.core.state.capabilities.resumableUploads || false,
       startUpload: startUpload,
       startUpload: startUpload,
       pauseUpload: this.core.pauseResume,
       pauseUpload: this.core.pauseResume,
-      retryUpload: retryUpload,
+      retryUpload: this.core.retryUpload,
       cancelUpload: cancelUpload,
       cancelUpload: cancelUpload,
       fileCardFor: pluginState.fileCardFor,
       fileCardFor: pluginState.fileCardFor,
       showFileCard: showFileCard,
       showFileCard: showFileCard,