|
@@ -11,7 +11,8 @@ const generateFileID = require('@uppy/utils/lib/generateFileID')
|
|
|
const findIndex = require('@uppy/utils/lib/findIndex')
|
|
|
const supportsUploadProgress = require('./supportsUploadProgress')
|
|
|
const { justErrorsLogger, debugLogger } = require('./loggers')
|
|
|
-const Plugin = require('./Plugin')
|
|
|
+const Plugin = require('./Plugin')
|
|
|
+
|
|
|
class RestrictionError extends Error {
|
|
|
constructor (...args) {
|
|
|
super(...args)
|
|
@@ -37,15 +38,15 @@ class Uppy {
|
|
|
strings: {
|
|
|
addBulkFilesFailed: {
|
|
|
0: 'Failed to add %{smart_count} file due to an internal error',
|
|
|
- 1: 'Failed to add %{smart_count} files due to internal errors'
|
|
|
+ 1: 'Failed to add %{smart_count} files due to internal errors',
|
|
|
},
|
|
|
youCanOnlyUploadX: {
|
|
|
0: 'You can only upload %{smart_count} file',
|
|
|
- 1: 'You can only upload %{smart_count} files'
|
|
|
+ 1: 'You can only upload %{smart_count} files',
|
|
|
},
|
|
|
youHaveToAtLeastSelectX: {
|
|
|
0: 'You have to select at least %{smart_count} file',
|
|
|
- 1: 'You have to select at least %{smart_count} files'
|
|
|
+ 1: 'You have to select at least %{smart_count} files',
|
|
|
},
|
|
|
|
|
|
|
|
@@ -67,7 +68,7 @@ class Uppy {
|
|
|
noFilesFound: 'You have no files or folders here',
|
|
|
selectX: {
|
|
|
0: 'Select %{smart_count}',
|
|
|
- 1: 'Select %{smart_count}'
|
|
|
+ 1: 'Select %{smart_count}',
|
|
|
},
|
|
|
selectAllFilesFromFolderNamed: 'Select all files from folder %{name}',
|
|
|
unselectAllFilesFromFolderNamed: 'Unselect all files from folder %{name}',
|
|
@@ -87,9 +88,9 @@ class Uppy {
|
|
|
emptyFolderAdded: 'No files were added from empty folder',
|
|
|
folderAdded: {
|
|
|
0: 'Added %{smart_count} file from %{folder}',
|
|
|
- 1: 'Added %{smart_count} files from %{folder}'
|
|
|
- }
|
|
|
- }
|
|
|
+ 1: 'Added %{smart_count} files from %{folder}',
|
|
|
+ },
|
|
|
+ },
|
|
|
}
|
|
|
|
|
|
const defaultOptions = {
|
|
@@ -103,14 +104,14 @@ class Uppy {
|
|
|
maxTotalFileSize: null,
|
|
|
maxNumberOfFiles: null,
|
|
|
minNumberOfFiles: null,
|
|
|
- allowedFileTypes: null
|
|
|
+ allowedFileTypes: null,
|
|
|
},
|
|
|
meta: {},
|
|
|
onBeforeFileAdded: (currentFile, files) => currentFile,
|
|
|
onBeforeUpload: (files) => files,
|
|
|
store: DefaultStore(),
|
|
|
logger: justErrorsLogger,
|
|
|
- infoTimeout: 5000
|
|
|
+ infoTimeout: 5000,
|
|
|
}
|
|
|
|
|
|
|
|
@@ -120,8 +121,8 @@ class Uppy {
|
|
|
...opts,
|
|
|
restrictions: {
|
|
|
...defaultOptions.restrictions,
|
|
|
- ...(opts && opts.restrictions)
|
|
|
- }
|
|
|
+ ...(opts && opts.restrictions),
|
|
|
+ },
|
|
|
}
|
|
|
|
|
|
|
|
@@ -134,9 +135,9 @@ class Uppy {
|
|
|
|
|
|
this.log(`Using Core v${this.constructor.VERSION}`)
|
|
|
|
|
|
- if (this.opts.restrictions.allowedFileTypes &&
|
|
|
- this.opts.restrictions.allowedFileTypes !== null &&
|
|
|
- !Array.isArray(this.opts.restrictions.allowedFileTypes)) {
|
|
|
+ if (this.opts.restrictions.allowedFileTypes
|
|
|
+ && this.opts.restrictions.allowedFileTypes !== null
|
|
|
+ && !Array.isArray(this.opts.restrictions.allowedFileTypes)) {
|
|
|
throw new TypeError('`restrictions.allowedFileTypes` must be an array')
|
|
|
}
|
|
|
|
|
@@ -193,15 +194,15 @@ class Uppy {
|
|
|
capabilities: {
|
|
|
uploadProgress: supportsUploadProgress(),
|
|
|
individualCancellation: true,
|
|
|
- resumableUploads: false
|
|
|
+ resumableUploads: false,
|
|
|
},
|
|
|
totalProgress: 0,
|
|
|
meta: { ...this.opts.meta },
|
|
|
info: {
|
|
|
isHidden: true,
|
|
|
type: 'info',
|
|
|
- message: ''
|
|
|
- }
|
|
|
+ message: '',
|
|
|
+ },
|
|
|
})
|
|
|
|
|
|
this._storeUnsubscribe = this.store.subscribe((prevState, nextState, patch) => {
|
|
@@ -286,9 +287,7 @@ class Uppy {
|
|
|
}
|
|
|
|
|
|
this.setState({
|
|
|
- files: Object.assign({}, this.getState().files, {
|
|
|
- [fileID]: Object.assign({}, this.getState().files[fileID], state)
|
|
|
- })
|
|
|
+ files: { ...this.getState().files, [fileID]: { ...this.getState().files[fileID], ...state } },
|
|
|
})
|
|
|
}
|
|
|
|
|
@@ -305,8 +304,8 @@ class Uppy {
|
|
|
...newOpts,
|
|
|
restrictions: {
|
|
|
...this.opts.restrictions,
|
|
|
- ...(newOpts && newOpts.restrictions)
|
|
|
- }
|
|
|
+ ...(newOpts && newOpts.restrictions),
|
|
|
+ },
|
|
|
}
|
|
|
|
|
|
if (newOpts.meta) {
|
|
@@ -329,19 +328,19 @@ class Uppy {
|
|
|
percentage: 0,
|
|
|
bytesUploaded: 0,
|
|
|
uploadComplete: false,
|
|
|
- uploadStarted: null
|
|
|
+ uploadStarted: null,
|
|
|
}
|
|
|
- const files = Object.assign({}, this.getState().files)
|
|
|
+ const files = { ...this.getState().files }
|
|
|
const updatedFiles = {}
|
|
|
Object.keys(files).forEach(fileID => {
|
|
|
- const updatedFile = Object.assign({}, files[fileID])
|
|
|
- updatedFile.progress = Object.assign({}, updatedFile.progress, defaultProgress)
|
|
|
+ const updatedFile = { ...files[fileID] }
|
|
|
+ updatedFile.progress = { ...updatedFile.progress, ...defaultProgress }
|
|
|
updatedFiles[fileID] = updatedFile
|
|
|
})
|
|
|
|
|
|
this.setState({
|
|
|
files: updatedFiles,
|
|
|
- totalProgress: 0
|
|
|
+ totalProgress: 0,
|
|
|
})
|
|
|
|
|
|
this.emit('reset-progress')
|
|
@@ -381,13 +380,11 @@ class Uppy {
|
|
|
}
|
|
|
|
|
|
setMeta (data) {
|
|
|
- const updatedMeta = Object.assign({}, this.getState().meta, data)
|
|
|
- const updatedFiles = Object.assign({}, this.getState().files)
|
|
|
+ const updatedMeta = { ...this.getState().meta, ...data }
|
|
|
+ const updatedFiles = { ...this.getState().files }
|
|
|
|
|
|
Object.keys(updatedFiles).forEach((fileID) => {
|
|
|
- updatedFiles[fileID] = Object.assign({}, updatedFiles[fileID], {
|
|
|
- meta: Object.assign({}, updatedFiles[fileID].meta, data)
|
|
|
- })
|
|
|
+ updatedFiles[fileID] = { ...updatedFiles[fileID], meta: { ...updatedFiles[fileID].meta, ...data } }
|
|
|
})
|
|
|
|
|
|
this.log('Adding metadata:')
|
|
@@ -395,20 +392,18 @@ class Uppy {
|
|
|
|
|
|
this.setState({
|
|
|
meta: updatedMeta,
|
|
|
- files: updatedFiles
|
|
|
+ files: updatedFiles,
|
|
|
})
|
|
|
}
|
|
|
|
|
|
setFileMeta (fileID, data) {
|
|
|
- const updatedFiles = Object.assign({}, this.getState().files)
|
|
|
+ const updatedFiles = { ...this.getState().files }
|
|
|
if (!updatedFiles[fileID]) {
|
|
|
this.log('Was trying to set metadata for a file that has been removed: ', fileID)
|
|
|
return
|
|
|
}
|
|
|
- const newMeta = Object.assign({}, updatedFiles[fileID].meta, data)
|
|
|
- updatedFiles[fileID] = Object.assign({}, updatedFiles[fileID], {
|
|
|
- meta: newMeta
|
|
|
- })
|
|
|
+ const newMeta = { ...updatedFiles[fileID].meta, ...data }
|
|
|
+ updatedFiles[fileID] = { ...updatedFiles[fileID], meta: newMeta }
|
|
|
this.setState({ files: updatedFiles })
|
|
|
}
|
|
|
|
|
@@ -441,12 +436,12 @@ class Uppy {
|
|
|
try {
|
|
|
this._checkRestrictions(file, files)
|
|
|
return {
|
|
|
- result: true
|
|
|
+ result: true,
|
|
|
}
|
|
|
} catch (err) {
|
|
|
return {
|
|
|
result: false,
|
|
|
- reason: err.message
|
|
|
+ reason: err.message,
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -499,7 +494,7 @@ class Uppy {
|
|
|
if (totalFilesSize > maxTotalFileSize) {
|
|
|
throw new RestrictionError(this.i18n('exceedsSize2', {
|
|
|
backwardsCompat: this.i18n('exceedsSize'),
|
|
|
- size: prettierBytes(maxTotalFileSize)
|
|
|
+ size: prettierBytes(maxTotalFileSize),
|
|
|
}))
|
|
|
}
|
|
|
}
|
|
@@ -509,7 +504,7 @@ class Uppy {
|
|
|
if (file.size > maxFileSize) {
|
|
|
throw new RestrictionError(this.i18n('exceedsSize2', {
|
|
|
backwardsCompat: this.i18n('exceedsSize'),
|
|
|
- size: prettierBytes(maxFileSize)
|
|
|
+ size: prettierBytes(maxFileSize),
|
|
|
}))
|
|
|
}
|
|
|
}
|
|
@@ -518,7 +513,7 @@ class Uppy {
|
|
|
if (minFileSize && file.size != null) {
|
|
|
if (file.size < minFileSize) {
|
|
|
throw new RestrictionError(this.i18n('inferiorSize', {
|
|
|
- size: prettierBytes(minFileSize)
|
|
|
+ size: prettierBytes(minFileSize),
|
|
|
}))
|
|
|
}
|
|
|
}
|
|
@@ -555,7 +550,7 @@ class Uppy {
|
|
|
|
|
|
let logMessageWithDetails = message
|
|
|
if (details) {
|
|
|
- logMessageWithDetails += ' ' + details
|
|
|
+ logMessageWithDetails += ` ${details}`
|
|
|
}
|
|
|
if (err.isRestriction) {
|
|
|
this.log(logMessageWithDetails)
|
|
@@ -567,7 +562,7 @@ class Uppy {
|
|
|
|
|
|
|
|
|
if (showInformer) {
|
|
|
- this.info({ message: message, details: details }, 'error', this.opts.infoTimeout)
|
|
|
+ this.info({ message, details }, 'error', this.opts.infoTimeout)
|
|
|
}
|
|
|
|
|
|
if (throwErr) {
|
|
@@ -609,7 +604,7 @@ class Uppy {
|
|
|
if (file.name) {
|
|
|
fileName = file.name
|
|
|
} else if (fileType.split('/')[0] === 'image') {
|
|
|
- fileName = fileType.split('/')[0] + '.' + fileType.split('/')[1]
|
|
|
+ fileName = `${fileType.split('/')[0]}.${fileType.split('/')[1]}`
|
|
|
} else {
|
|
|
fileName = 'noname'
|
|
|
}
|
|
@@ -635,7 +630,7 @@ class Uppy {
|
|
|
extension: fileExtension || '',
|
|
|
meta: {
|
|
|
...this.getState().meta,
|
|
|
- ...meta
|
|
|
+ ...meta,
|
|
|
},
|
|
|
type: fileType,
|
|
|
data: file.data,
|
|
@@ -644,12 +639,12 @@ class Uppy {
|
|
|
bytesUploaded: 0,
|
|
|
bytesTotal: size,
|
|
|
uploadComplete: false,
|
|
|
- uploadStarted: null
|
|
|
+ uploadStarted: null,
|
|
|
},
|
|
|
- size: size,
|
|
|
- isRemote: isRemote,
|
|
|
+ size,
|
|
|
+ isRemote,
|
|
|
remote: file.remote || '',
|
|
|
- preview: file.preview
|
|
|
+ preview: file.preview,
|
|
|
}
|
|
|
|
|
|
try {
|
|
@@ -693,8 +688,8 @@ class Uppy {
|
|
|
this.setState({
|
|
|
files: {
|
|
|
...files,
|
|
|
- [newFile.id]: newFile
|
|
|
- }
|
|
|
+ [newFile.id]: newFile,
|
|
|
+ },
|
|
|
})
|
|
|
|
|
|
this.emit('file-added', newFile)
|
|
@@ -760,7 +755,7 @@ class Uppy {
|
|
|
|
|
|
this.info({
|
|
|
message: this.i18n('addBulkFilesFailed', { smart_count: errors.length }),
|
|
|
- details: message
|
|
|
+ details: message,
|
|
|
}, 'error', this.opts.infoTimeout)
|
|
|
|
|
|
const err = new Error(message)
|
|
@@ -798,7 +793,7 @@ class Uppy {
|
|
|
|
|
|
updatedUploads[uploadID] = {
|
|
|
...currentUploads[uploadID],
|
|
|
- fileIDs: newFileIDs
|
|
|
+ fileIDs: newFileIDs,
|
|
|
}
|
|
|
})
|
|
|
|
|
@@ -808,7 +803,7 @@ class Uppy {
|
|
|
|
|
|
const stateUpdate = {
|
|
|
currentUploads: updatedUploads,
|
|
|
- files: updatedFiles
|
|
|
+ files: updatedFiles,
|
|
|
}
|
|
|
|
|
|
|
|
@@ -837,8 +832,8 @@ class Uppy {
|
|
|
}
|
|
|
|
|
|
pauseResume (fileID) {
|
|
|
- if (!this.getState().capabilities.resumableUploads ||
|
|
|
- this.getFile(fileID).uploadComplete) {
|
|
|
+ if (!this.getState().capabilities.resumableUploads
|
|
|
+ || this.getFile(fileID).uploadComplete) {
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -846,7 +841,7 @@ class Uppy {
|
|
|
const isPaused = !wasPaused
|
|
|
|
|
|
this.setFileState(fileID, {
|
|
|
- isPaused: isPaused
|
|
|
+ isPaused,
|
|
|
})
|
|
|
|
|
|
this.emit('upload-pause', fileID, isPaused)
|
|
@@ -855,16 +850,14 @@ class Uppy {
|
|
|
}
|
|
|
|
|
|
pauseAll () {
|
|
|
- const updatedFiles = Object.assign({}, this.getState().files)
|
|
|
+ const updatedFiles = { ...this.getState().files }
|
|
|
const inProgressUpdatedFiles = Object.keys(updatedFiles).filter((file) => {
|
|
|
- return !updatedFiles[file].progress.uploadComplete &&
|
|
|
- updatedFiles[file].progress.uploadStarted
|
|
|
+ return !updatedFiles[file].progress.uploadComplete
|
|
|
+ && updatedFiles[file].progress.uploadStarted
|
|
|
})
|
|
|
|
|
|
inProgressUpdatedFiles.forEach((file) => {
|
|
|
- const updatedFile = Object.assign({}, updatedFiles[file], {
|
|
|
- isPaused: true
|
|
|
- })
|
|
|
+ const updatedFile = { ...updatedFiles[file], isPaused: true }
|
|
|
updatedFiles[file] = updatedFile
|
|
|
})
|
|
|
|
|
@@ -873,17 +866,18 @@ class Uppy {
|
|
|
}
|
|
|
|
|
|
resumeAll () {
|
|
|
- const updatedFiles = Object.assign({}, this.getState().files)
|
|
|
+ const updatedFiles = { ...this.getState().files }
|
|
|
const inProgressUpdatedFiles = Object.keys(updatedFiles).filter((file) => {
|
|
|
- return !updatedFiles[file].progress.uploadComplete &&
|
|
|
- updatedFiles[file].progress.uploadStarted
|
|
|
+ return !updatedFiles[file].progress.uploadComplete
|
|
|
+ && updatedFiles[file].progress.uploadStarted
|
|
|
})
|
|
|
|
|
|
inProgressUpdatedFiles.forEach((file) => {
|
|
|
- const updatedFile = Object.assign({}, updatedFiles[file], {
|
|
|
+ const updatedFile = {
|
|
|
+ ...updatedFiles[file],
|
|
|
isPaused: false,
|
|
|
- error: null
|
|
|
- })
|
|
|
+ error: null,
|
|
|
+ }
|
|
|
updatedFiles[file] = updatedFile
|
|
|
})
|
|
|
this.setState({ files: updatedFiles })
|
|
@@ -892,21 +886,22 @@ class Uppy {
|
|
|
}
|
|
|
|
|
|
retryAll () {
|
|
|
- const updatedFiles = Object.assign({}, this.getState().files)
|
|
|
+ const updatedFiles = { ...this.getState().files }
|
|
|
const filesToRetry = Object.keys(updatedFiles).filter(file => {
|
|
|
return updatedFiles[file].error
|
|
|
})
|
|
|
|
|
|
filesToRetry.forEach((file) => {
|
|
|
- const updatedFile = Object.assign({}, updatedFiles[file], {
|
|
|
+ const updatedFile = {
|
|
|
+ ...updatedFiles[file],
|
|
|
isPaused: false,
|
|
|
- error: null
|
|
|
- })
|
|
|
+ error: null,
|
|
|
+ }
|
|
|
updatedFiles[file] = updatedFile
|
|
|
})
|
|
|
this.setState({
|
|
|
files: updatedFiles,
|
|
|
- error: null
|
|
|
+ error: null,
|
|
|
})
|
|
|
|
|
|
this.emit('retry-all', filesToRetry)
|
|
@@ -914,12 +909,12 @@ class Uppy {
|
|
|
if (filesToRetry.length === 0) {
|
|
|
return Promise.resolve({
|
|
|
successful: [],
|
|
|
- failed: []
|
|
|
+ failed: [],
|
|
|
})
|
|
|
}
|
|
|
|
|
|
const uploadID = this._createUpload(filesToRetry, {
|
|
|
- forceAllowNewUpload: true
|
|
|
+ forceAllowNewUpload: true,
|
|
|
})
|
|
|
return this._runUpload(uploadID)
|
|
|
}
|
|
@@ -936,20 +931,20 @@ class Uppy {
|
|
|
|
|
|
this.setState({
|
|
|
totalProgress: 0,
|
|
|
- error: null
|
|
|
+ error: null,
|
|
|
})
|
|
|
}
|
|
|
|
|
|
retryUpload (fileID) {
|
|
|
this.setFileState(fileID, {
|
|
|
error: null,
|
|
|
- isPaused: false
|
|
|
+ isPaused: false,
|
|
|
})
|
|
|
|
|
|
this.emit('upload-retry', fileID)
|
|
|
|
|
|
const uploadID = this._createUpload([fileID], {
|
|
|
- forceAllowNewUpload: true
|
|
|
+ forceAllowNewUpload: true,
|
|
|
})
|
|
|
return this._runUpload(uploadID)
|
|
|
}
|
|
@@ -975,8 +970,8 @@ class Uppy {
|
|
|
|
|
|
|
|
|
? Math.round(data.bytesUploaded / data.bytesTotal * 100)
|
|
|
- : 0
|
|
|
- }
|
|
|
+ : 0,
|
|
|
+ },
|
|
|
})
|
|
|
|
|
|
this._calculateTotalProgress()
|
|
@@ -988,9 +983,9 @@ class Uppy {
|
|
|
const files = this.getFiles()
|
|
|
|
|
|
const inProgress = files.filter((file) => {
|
|
|
- return file.progress.uploadStarted ||
|
|
|
- file.progress.preprocess ||
|
|
|
- file.progress.postprocess
|
|
|
+ return file.progress.uploadStarted
|
|
|
+ || file.progress.preprocess
|
|
|
+ || file.progress.postprocess
|
|
|
})
|
|
|
|
|
|
if (inProgress.length === 0) {
|
|
@@ -1052,7 +1047,7 @@ class Uppy {
|
|
|
}
|
|
|
|
|
|
if (error.details) {
|
|
|
- errorMsg += ' ' + error.details
|
|
|
+ errorMsg += ` ${error.details}`
|
|
|
}
|
|
|
|
|
|
this.setState({ error: errorMsg })
|
|
@@ -1065,12 +1060,12 @@ class Uppy {
|
|
|
}
|
|
|
|
|
|
if (error.details) {
|
|
|
- errorMsg += ' ' + error.details
|
|
|
+ errorMsg += ` ${error.details}`
|
|
|
}
|
|
|
|
|
|
this.setFileState(file.id, {
|
|
|
error: errorMsg,
|
|
|
- response
|
|
|
+ response,
|
|
|
})
|
|
|
|
|
|
this.setState({ error: error.message })
|
|
@@ -1079,15 +1074,15 @@ class Uppy {
|
|
|
const newError = new Error(error.message)
|
|
|
newError.details = error.message
|
|
|
if (error.details) {
|
|
|
- newError.details += ' ' + error.details
|
|
|
+ newError.details += ` ${error.details}`
|
|
|
}
|
|
|
newError.message = this.i18n('failedToUpload', { file: file.name })
|
|
|
this._showOrLogErrorAndThrow(newError, {
|
|
|
- throwErr: false
|
|
|
+ throwErr: false,
|
|
|
})
|
|
|
} else {
|
|
|
this._showOrLogErrorAndThrow(error, {
|
|
|
- throwErr: false
|
|
|
+ throwErr: false,
|
|
|
})
|
|
|
}
|
|
|
})
|
|
@@ -1107,8 +1102,8 @@ class Uppy {
|
|
|
uploadComplete: false,
|
|
|
percentage: 0,
|
|
|
bytesUploaded: 0,
|
|
|
- bytesTotal: file.size
|
|
|
- }
|
|
|
+ bytesTotal: file.size,
|
|
|
+ },
|
|
|
})
|
|
|
})
|
|
|
|
|
@@ -1122,17 +1117,18 @@ class Uppy {
|
|
|
|
|
|
const currentProgress = this.getFile(file.id).progress
|
|
|
this.setFileState(file.id, {
|
|
|
- progress: Object.assign({}, currentProgress, {
|
|
|
+ progress: {
|
|
|
+ ...currentProgress,
|
|
|
postprocess: this.postProcessors.length > 0 ? {
|
|
|
- mode: 'indeterminate'
|
|
|
+ mode: 'indeterminate',
|
|
|
} : null,
|
|
|
uploadComplete: true,
|
|
|
percentage: 100,
|
|
|
- bytesUploaded: currentProgress.bytesTotal
|
|
|
- }),
|
|
|
+ bytesUploaded: currentProgress.bytesTotal,
|
|
|
+ },
|
|
|
response: uploadResp,
|
|
|
uploadURL: uploadResp.uploadURL,
|
|
|
- isPaused: false
|
|
|
+ isPaused: false,
|
|
|
})
|
|
|
|
|
|
this._calculateTotalProgress()
|
|
@@ -1144,9 +1140,7 @@ class Uppy {
|
|
|
return
|
|
|
}
|
|
|
this.setFileState(file.id, {
|
|
|
- progress: Object.assign({}, this.getFile(file.id).progress, {
|
|
|
- preprocess: progress
|
|
|
- })
|
|
|
+ progress: { ...this.getFile(file.id).progress, preprocess: progress },
|
|
|
})
|
|
|
})
|
|
|
|
|
@@ -1155,13 +1149,11 @@ class Uppy {
|
|
|
this.log(`Not setting progress for a file that has been removed: ${file.id}`)
|
|
|
return
|
|
|
}
|
|
|
- const files = Object.assign({}, this.getState().files)
|
|
|
- files[file.id] = Object.assign({}, files[file.id], {
|
|
|
- progress: Object.assign({}, files[file.id].progress)
|
|
|
- })
|
|
|
+ const files = { ...this.getState().files }
|
|
|
+ files[file.id] = { ...files[file.id], progress: { ...files[file.id].progress } }
|
|
|
delete files[file.id].progress.preprocess
|
|
|
|
|
|
- this.setState({ files: files })
|
|
|
+ this.setState({ files })
|
|
|
})
|
|
|
|
|
|
this.on('postprocess-progress', (file, progress) => {
|
|
@@ -1170,9 +1162,7 @@ class Uppy {
|
|
|
return
|
|
|
}
|
|
|
this.setFileState(file.id, {
|
|
|
- progress: Object.assign({}, this.getState().files[file.id].progress, {
|
|
|
- postprocess: progress
|
|
|
- })
|
|
|
+ progress: { ...this.getState().files[file.id].progress, postprocess: progress },
|
|
|
})
|
|
|
})
|
|
|
|
|
@@ -1182,20 +1172,20 @@ class Uppy {
|
|
|
return
|
|
|
}
|
|
|
const files = {
|
|
|
- ...this.getState().files
|
|
|
+ ...this.getState().files,
|
|
|
}
|
|
|
files[file.id] = {
|
|
|
...files[file.id],
|
|
|
progress: {
|
|
|
- ...files[file.id].progress
|
|
|
- }
|
|
|
+ ...files[file.id].progress,
|
|
|
+ },
|
|
|
}
|
|
|
delete files[file.id].progress.postprocess
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- this.setState({ files: files })
|
|
|
+ this.setState({ files })
|
|
|
})
|
|
|
|
|
|
this.on('restored', () => {
|
|
@@ -1212,8 +1202,8 @@ class Uppy {
|
|
|
}
|
|
|
|
|
|
updateOnlineStatus () {
|
|
|
- const online =
|
|
|
- typeof window.navigator.onLine !== 'undefined'
|
|
|
+ const online
|
|
|
+ = typeof window.navigator.onLine !== 'undefined'
|
|
|
? window.navigator.onLine
|
|
|
: true
|
|
|
if (!online) {
|
|
@@ -1243,8 +1233,8 @@ class Uppy {
|
|
|
*/
|
|
|
use (Plugin, opts) {
|
|
|
if (typeof Plugin !== 'function') {
|
|
|
- const msg = `Expected a plugin class, but got ${Plugin === null ? 'null' : typeof Plugin}.` +
|
|
|
- ' Please verify that the plugin was imported and spelled correctly.'
|
|
|
+ const msg = `Expected a plugin class, but got ${Plugin === null ? 'null' : typeof Plugin}.`
|
|
|
+ + ' Please verify that the plugin was imported and spelled correctly.'
|
|
|
throw new TypeError(msg)
|
|
|
}
|
|
|
|
|
@@ -1263,9 +1253,9 @@ class Uppy {
|
|
|
|
|
|
const existsPluginAlready = this.getPlugin(pluginId)
|
|
|
if (existsPluginAlready) {
|
|
|
- const msg = `Already found a plugin named '${existsPluginAlready.id}'. ` +
|
|
|
- `Tried to use: '${pluginId}'.\n` +
|
|
|
- 'Uppy plugins must have unique `id` options. See https://uppy.io/docs/plugins/#id.'
|
|
|
+ const msg = `Already found a plugin named '${existsPluginAlready.id}'. `
|
|
|
+ + `Tried to use: '${pluginId}'.\n`
|
|
|
+ + 'Uppy plugins must have unique `id` options. See https://uppy.io/docs/plugins/#id.'
|
|
|
throw new Error(msg)
|
|
|
}
|
|
|
|
|
@@ -1334,8 +1324,8 @@ class Uppy {
|
|
|
const updatedState = {
|
|
|
plugins: {
|
|
|
...state.plugins,
|
|
|
- [instance.id]: undefined
|
|
|
- }
|
|
|
+ [instance.id]: undefined,
|
|
|
+ },
|
|
|
}
|
|
|
this.setState(updatedState)
|
|
|
}
|
|
@@ -1370,10 +1360,10 @@ class Uppy {
|
|
|
this.setState({
|
|
|
info: {
|
|
|
isHidden: false,
|
|
|
- type: type,
|
|
|
+ type,
|
|
|
message: isComplexMessage ? message.message : message,
|
|
|
- details: isComplexMessage ? message.details : null
|
|
|
- }
|
|
|
+ details: isComplexMessage ? message.details : null,
|
|
|
+ },
|
|
|
})
|
|
|
|
|
|
this.emit('info-visible')
|
|
@@ -1389,11 +1379,9 @@ class Uppy {
|
|
|
}
|
|
|
|
|
|
hideInfo () {
|
|
|
- const newInfo = Object.assign({}, this.getState().info, {
|
|
|
- isHidden: true
|
|
|
- })
|
|
|
+ const newInfo = { ...this.getState().info, isHidden: true }
|
|
|
this.setState({
|
|
|
- info: newInfo
|
|
|
+ info: newInfo,
|
|
|
})
|
|
|
this.emit('info-hidden')
|
|
|
}
|
|
@@ -1444,7 +1432,7 @@ class Uppy {
|
|
|
*/
|
|
|
_createUpload (fileIDs, opts = {}) {
|
|
|
const {
|
|
|
- forceAllowNewUpload = false
|
|
|
+ forceAllowNewUpload = false,
|
|
|
} = opts
|
|
|
|
|
|
const { allowNewUpload, currentUploads } = this.getState()
|
|
@@ -1456,7 +1444,7 @@ class Uppy {
|
|
|
|
|
|
this.emit('upload', {
|
|
|
id: uploadID,
|
|
|
- fileIDs: fileIDs
|
|
|
+ fileIDs,
|
|
|
})
|
|
|
|
|
|
this.setState({
|
|
@@ -1465,11 +1453,11 @@ class Uppy {
|
|
|
currentUploads: {
|
|
|
...currentUploads,
|
|
|
[uploadID]: {
|
|
|
- fileIDs: fileIDs,
|
|
|
+ fileIDs,
|
|
|
step: 0,
|
|
|
- result: {}
|
|
|
- }
|
|
|
- }
|
|
|
+ result: {},
|
|
|
+ },
|
|
|
+ },
|
|
|
})
|
|
|
|
|
|
return uploadID
|
|
@@ -1493,13 +1481,9 @@ class Uppy {
|
|
|
return
|
|
|
}
|
|
|
const currentUploads = this.getState().currentUploads
|
|
|
- const currentUpload = Object.assign({}, currentUploads[uploadID], {
|
|
|
- result: Object.assign({}, currentUploads[uploadID].result, data)
|
|
|
- })
|
|
|
+ const currentUpload = { ...currentUploads[uploadID], result: { ...currentUploads[uploadID].result, ...data } }
|
|
|
this.setState({
|
|
|
- currentUploads: Object.assign({}, currentUploads, {
|
|
|
- [uploadID]: currentUpload
|
|
|
- })
|
|
|
+ currentUploads: { ...currentUploads, [uploadID]: currentUpload },
|
|
|
})
|
|
|
}
|
|
|
|
|
@@ -1513,7 +1497,7 @@ class Uppy {
|
|
|
delete currentUploads[uploadID]
|
|
|
|
|
|
this.setState({
|
|
|
- currentUploads: currentUploads
|
|
|
+ currentUploads,
|
|
|
})
|
|
|
}
|
|
|
|
|
@@ -1529,7 +1513,7 @@ class Uppy {
|
|
|
const steps = [
|
|
|
...this.preProcessors,
|
|
|
...this.uploaders,
|
|
|
- ...this.postProcessors
|
|
|
+ ...this.postProcessors,
|
|
|
]
|
|
|
let lastStep = Promise.resolve()
|
|
|
steps.forEach((fn, step) => {
|
|
@@ -1547,14 +1531,14 @@ class Uppy {
|
|
|
|
|
|
const updatedUpload = {
|
|
|
...currentUpload,
|
|
|
- step
|
|
|
+ step,
|
|
|
}
|
|
|
|
|
|
this.setState({
|
|
|
currentUploads: {
|
|
|
...currentUploads,
|
|
|
- [uploadID]: updatedUpload
|
|
|
- }
|
|
|
+ [uploadID]: updatedUpload,
|
|
|
+ },
|
|
|
})
|
|
|
|
|
|
|
|
@@ -1648,7 +1632,7 @@ class Uppy {
|
|
|
|
|
|
|
|
|
this.setState({
|
|
|
- files: files
|
|
|
+ files,
|
|
|
})
|
|
|
}
|
|
|
|
|
@@ -1676,7 +1660,7 @@ class Uppy {
|
|
|
})
|
|
|
.catch((err) => {
|
|
|
this._showOrLogErrorAndThrow(err, {
|
|
|
- showInformer: false
|
|
|
+ showInformer: false,
|
|
|
})
|
|
|
})
|
|
|
}
|