@uppy/core
Advanced tools
Comparing version 2.0.2 to 2.0.3
107
lib/index.js
@@ -238,2 +238,3 @@ "use strict"; | ||
authenticateWith: 'Connect to %{pluginName}', | ||
signInWithGoogle: 'Sign in with Google', | ||
searchImages: 'Search for images', | ||
@@ -1485,6 +1486,5 @@ enterTextToSearch: 'Enter text to search for images', | ||
const errors = []; | ||
const fileIDs = Object.keys(files); | ||
for (let i = 0; i < fileIDs.length; i++) { | ||
const file = this.getFile(fileIDs[i]); | ||
for (const fileID of Object.keys(files)) { | ||
const file = this.getFile(fileID); | ||
@@ -1864,23 +1864,17 @@ for (let i = 0; i < requiredMetaFields.length; i++) { | ||
function _runUpload2(uploadID) { | ||
const uploadData = this.getState().currentUploads[uploadID]; | ||
const restoreStep = uploadData.step; | ||
async function _runUpload2(uploadID) { | ||
let { | ||
currentUploads | ||
} = this.getState(); | ||
let currentUpload = currentUploads[uploadID]; | ||
const restoreStep = currentUpload.step || 0; | ||
const steps = [..._classPrivateFieldLooseBase(this, _preProcessors)[_preProcessors], ..._classPrivateFieldLooseBase(this, _uploaders)[_uploaders], ..._classPrivateFieldLooseBase(this, _postProcessors)[_postProcessors]]; | ||
let lastStep = Promise.resolve(); | ||
steps.forEach((fn, step) => { | ||
// Skip this step if we are restoring and have already completed this step before. | ||
if (step < restoreStep) { | ||
return; | ||
} | ||
lastStep = lastStep.then(() => { | ||
const { | ||
currentUploads | ||
} = this.getState(); | ||
const currentUpload = currentUploads[uploadID]; | ||
try { | ||
for (let step = restoreStep; step < steps.length; step++) { | ||
if (!currentUpload) { | ||
return; | ||
break; | ||
} | ||
const fn = steps[step]; | ||
const updatedUpload = { ...currentUpload, | ||
@@ -1896,22 +1890,18 @@ step | ||
return fn(updatedUpload.fileIDs, uploadID); // eslint-disable-line consistent-return | ||
}).then(() => null); | ||
}); // Not returning the `catch`ed promise, because we still want to return a rejected | ||
// promise from this method if the upload failed. | ||
await fn(updatedUpload.fileIDs, uploadID); // Update currentUpload value in case it was modified asynchronously. | ||
lastStep.catch(err => { | ||
currentUploads = this.getState().currentUploads; | ||
currentUpload = currentUploads[uploadID]; | ||
} | ||
} catch (err) { | ||
this.emit('error', err); | ||
_classPrivateFieldLooseBase(this, _removeUpload)[_removeUpload](uploadID); | ||
}); | ||
return lastStep.then(() => { | ||
// Set result data. | ||
const { | ||
currentUploads | ||
} = this.getState(); | ||
const currentUpload = currentUploads[uploadID]; | ||
if (!currentUpload) { | ||
return; | ||
} // Mark postprocessing step as complete if necessary; this addresses a case where we might get | ||
throw err; | ||
} // Set result data. | ||
if (currentUpload) { | ||
// Mark postprocessing step as complete if necessary; this addresses a case where we might get | ||
// stuck in the postprocessing UI while the upload is fully complete. | ||
@@ -1926,4 +1916,2 @@ // If the postprocessing steps do not do any work, they may not emit postprocessing events at | ||
// postprocessing completion, we do it instead. | ||
currentUpload.fileIDs.forEach(fileID => { | ||
@@ -1939,40 +1927,33 @@ const file = this.getFile(fileID); | ||
const failed = files.filter(file => file.error); | ||
this.addResultData(uploadID, { | ||
await 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(); | ||
}); // Update currentUpload value in case it was modified asynchronously. | ||
if (!currentUploads[uploadID]) { | ||
return; | ||
} | ||
currentUploads = this.getState().currentUploads; | ||
currentUpload = currentUploads[uploadID]; | ||
} // 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 currentUpload = currentUploads[uploadID]; | ||
const { | ||
result | ||
} = currentUpload; | ||
let result; | ||
if (currentUpload) { | ||
result = currentUpload.result; | ||
this.emit('complete', result); | ||
_classPrivateFieldLooseBase(this, _removeUpload)[_removeUpload](uploadID); // eslint-disable-next-line consistent-return | ||
_classPrivateFieldLooseBase(this, _removeUpload)[_removeUpload](uploadID); | ||
} | ||
if (result == null) { | ||
this.log(`Not setting result for an upload that has been removed: ${uploadID}`); | ||
} | ||
return result; | ||
}).then(result => { | ||
if (result == null) { | ||
this.log(`Not setting result for an upload that has been removed: ${uploadID}`); | ||
} | ||
return result; | ||
}); | ||
return result; | ||
} | ||
Uppy.VERSION = "2.0.2"; | ||
Uppy.VERSION = "2.0.3"; | ||
module.exports = Uppy; | ||
@@ -1979,0 +1960,0 @@ module.exports.Uppy = Uppy; |
{ | ||
"name": "@uppy/core", | ||
"description": "Core module for the extensible JavaScript file upload widget with support for drag&drop, resumable uploads, previews, restrictions, file processing/encoding, remote providers like Instagram, Dropbox, Google Drive, S3 and more :dog:", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"license": "MIT", | ||
@@ -25,3 +25,3 @@ "main": "lib/index.js", | ||
"@uppy/store-default": "^2.0.0", | ||
"@uppy/utils": "^4.0.0", | ||
"@uppy/utils": "^4.0.1", | ||
"lodash.throttle": "^4.1.1", | ||
@@ -33,3 +33,3 @@ "mime-match": "^1.0.2", | ||
}, | ||
"gitHead": "246eafc51a7ed6a1f534629454e1f78cd6f507c1" | ||
"gitHead": "b3b68c07773395d1521c38148cbf87ed88ff2364" | ||
} |
@@ -110,2 +110,3 @@ /* global AggregateError */ | ||
authenticateWith: 'Connect to %{pluginName}', | ||
signInWithGoogle: 'Sign in with Google', | ||
searchImages: 'Search for images', | ||
@@ -566,5 +567,4 @@ enterTextToSearch: 'Enter text to search for images', | ||
const errors = [] | ||
const fileIDs = Object.keys(files) | ||
for (let i = 0; i < fileIDs.length; i++) { | ||
const file = this.getFile(fileIDs[i]) | ||
for (const fileID of Object.keys(files)) { | ||
const file = this.getFile(fileID) | ||
for (let i = 0; i < requiredMetaFields.length; i++) { | ||
@@ -1589,5 +1589,6 @@ if (!hasOwnProperty.call(file.meta, requiredMetaFields[i]) || file.meta[requiredMetaFields[i]] === '') { | ||
*/ | ||
#runUpload (uploadID) { | ||
const uploadData = this.getState().currentUploads[uploadID] | ||
const restoreStep = uploadData.step | ||
async #runUpload (uploadID) { | ||
let { currentUploads } = this.getState() | ||
let currentUpload = currentUploads[uploadID] | ||
const restoreStep = currentUpload.step || 0 | ||
@@ -1599,15 +1600,8 @@ const steps = [ | ||
] | ||
let lastStep = Promise.resolve() | ||
steps.forEach((fn, step) => { | ||
// Skip this step if we are restoring and have already completed this step before. | ||
if (step < restoreStep) { | ||
return | ||
} | ||
lastStep = lastStep.then(() => { | ||
const { currentUploads } = this.getState() | ||
const currentUpload = currentUploads[uploadID] | ||
try { | ||
for (let step = restoreStep; step < steps.length; step++) { | ||
if (!currentUpload) { | ||
return | ||
break | ||
} | ||
const fn = steps[step] | ||
@@ -1628,21 +1622,16 @@ const updatedUpload = { | ||
// Otherwise when more metadata may be added to the upload this would keep getting more parameters | ||
return fn(updatedUpload.fileIDs, uploadID) // eslint-disable-line consistent-return | ||
}).then(() => null) | ||
}) | ||
await fn(updatedUpload.fileIDs, uploadID) | ||
// 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) => { | ||
// Update currentUpload value in case it was modified asynchronously. | ||
currentUploads = this.getState().currentUploads | ||
currentUpload = currentUploads[uploadID] | ||
} | ||
} catch (err) { | ||
this.emit('error', err) | ||
this.#removeUpload(uploadID) | ||
}) | ||
throw err | ||
} | ||
return lastStep.then(() => { | ||
// Set result data. | ||
const { currentUploads } = this.getState() | ||
const currentUpload = currentUploads[uploadID] | ||
if (!currentUpload) { | ||
return | ||
} | ||
// Set result data. | ||
if (currentUpload) { | ||
// Mark postprocessing step as complete if necessary; this addresses a case where we might get | ||
@@ -1668,26 +1657,23 @@ // stuck in the postprocessing UI while the upload is fully complete. | ||
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() | ||
if (!currentUploads[uploadID]) { | ||
return | ||
} | ||
const currentUpload = currentUploads[uploadID] | ||
const { result } = currentUpload | ||
await this.addResultData(uploadID, { successful, failed, uploadID }) | ||
// Update currentUpload value in case it was modified asynchronously. | ||
currentUploads = this.getState().currentUploads | ||
currentUpload = currentUploads[uploadID] | ||
} | ||
// 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. | ||
let result | ||
if (currentUpload) { | ||
result = currentUpload.result | ||
this.emit('complete', result) | ||
this.#removeUpload(uploadID) | ||
// eslint-disable-next-line consistent-return | ||
return result | ||
}).then((result) => { | ||
if (result == null) { | ||
this.log(`Not setting result for an upload that has been removed: ${uploadID}`) | ||
} | ||
return result | ||
}) | ||
} | ||
if (result == null) { | ||
this.log(`Not setting result for an upload that has been removed: ${uploadID}`) | ||
} | ||
return result | ||
} | ||
@@ -1694,0 +1680,0 @@ |
@@ -31,2 +31,3 @@ /* eslint-disable */ | ||
| 'authenticateWith' | ||
| 'signInWithGoogle' | ||
| 'searchImages' | ||
@@ -33,0 +34,0 @@ | 'enterTextToSearch' |
Sorry, the diff of this file is not supported yet
352237
6129
Updated@uppy/utils@^4.0.1