|
@@ -1103,7 +1103,6 @@ class Uppy {
|
|
|
*/
|
|
|
_runUpload (uploadID) {
|
|
|
const uploadData = this.getState().currentUploads[uploadID]
|
|
|
- const fileIDs = uploadData.fileIDs
|
|
|
const restoreStep = uploadData.step
|
|
|
|
|
|
const steps = [
|
|
@@ -1120,48 +1119,58 @@ class Uppy {
|
|
|
|
|
|
lastStep = lastStep.then(() => {
|
|
|
const { currentUploads } = this.getState()
|
|
|
- const currentUpload = Object.assign({}, currentUploads[uploadID], {
|
|
|
+ const currentUpload = {
|
|
|
+ ...currentUploads[uploadID],
|
|
|
step: step
|
|
|
- })
|
|
|
+ }
|
|
|
this.setState({
|
|
|
- currentUploads: Object.assign({}, currentUploads, {
|
|
|
+ currentUploads: {
|
|
|
+ ...currentUploads,
|
|
|
[uploadID]: currentUpload
|
|
|
- })
|
|
|
+ }
|
|
|
})
|
|
|
+
|
|
|
// TODO give this the `currentUpload` object as its only parameter maybe?
|
|
|
// Otherwise when more metadata may be added to the upload this would keep getting more parameters
|
|
|
- return fn(fileIDs, uploadID)
|
|
|
+ return fn(currentUpload.fileIDs, uploadID)
|
|
|
}).then((result) => {
|
|
|
return null
|
|
|
})
|
|
|
})
|
|
|
|
|
|
- // Not returning the `catch`ed promise, because we still want to return a rejected
|
|
|
- // promise from this method if the upload failed.
|
|
|
- lastStep.catch((err) => {
|
|
|
- this.emit('error', err, uploadID)
|
|
|
-
|
|
|
- this._removeUpload(uploadID)
|
|
|
- })
|
|
|
-
|
|
|
return lastStep.then(() => {
|
|
|
- const files = fileIDs.map((fileID) => this.getFile(fileID))
|
|
|
- const successful = files.filter((file) => file && !file.error)
|
|
|
- const failed = files.filter((file) => file && file.error)
|
|
|
- this.addResultData(uploadID, { successful, failed, uploadID })
|
|
|
-
|
|
|
+ // Set result data.
|
|
|
const { currentUploads } = this.getState()
|
|
|
- if (!currentUploads[uploadID]) {
|
|
|
+ const currentUpload = currentUploads[uploadID]
|
|
|
+ if (!currentUpload) {
|
|
|
this.log(`Not setting result for an upload that has been removed: ${uploadID}`)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- const result = currentUploads[uploadID].result
|
|
|
+ const files = currentUpload.fileIDs
|
|
|
+ .map((fileID) => this.getFile(fileID))
|
|
|
+ const successful = files.filter((file) => !file.error)
|
|
|
+ const failed = files.filter((file) => file.error)
|
|
|
+ this.addResultData(uploadID, { successful, failed, uploadID })
|
|
|
+ }).then(() => {
|
|
|
+ // Emit completion events.
|
|
|
+ // This is in a separate function so that the `currentUploads` variable
|
|
|
+ // always refers to the latest state. In the handler right above it refers
|
|
|
+ // to an outdated object without the `.result` property.
|
|
|
+ const { currentUploads } = this.getState()
|
|
|
+ const currentUpload = currentUploads[uploadID]
|
|
|
+ const result = currentUpload.result
|
|
|
this.emit('complete', result)
|
|
|
|
|
|
this._removeUpload(uploadID)
|
|
|
|
|
|
return result
|
|
|
+ }, (err) => {
|
|
|
+ this.emit('error', err, uploadID)
|
|
|
+
|
|
|
+ this._removeUpload(uploadID)
|
|
|
+
|
|
|
+ throw err
|
|
|
})
|
|
|
}
|
|
|
|