|
@@ -4,7 +4,8 @@ const UppySocket = require('../core/UppySocket')
|
|
const {
|
|
const {
|
|
emitSocketProgress,
|
|
emitSocketProgress,
|
|
getSocketHost,
|
|
getSocketHost,
|
|
- settle
|
|
|
|
|
|
+ settle,
|
|
|
|
+ limitPromises
|
|
} = require('../core/Utils')
|
|
} = require('../core/Utils')
|
|
require('whatwg-fetch')
|
|
require('whatwg-fetch')
|
|
|
|
|
|
@@ -61,12 +62,20 @@ module.exports = class Tus extends Plugin {
|
|
resume: true,
|
|
resume: true,
|
|
autoRetry: true,
|
|
autoRetry: true,
|
|
useFastRemoteRetry: true,
|
|
useFastRemoteRetry: true,
|
|
|
|
+ limit: 0,
|
|
retryDelays: [0, 1000, 3000, 5000]
|
|
retryDelays: [0, 1000, 3000, 5000]
|
|
}
|
|
}
|
|
|
|
|
|
// merge default options with the ones set by user
|
|
// merge default options with the ones set by user
|
|
this.opts = Object.assign({}, defaultOptions, opts)
|
|
this.opts = Object.assign({}, defaultOptions, opts)
|
|
|
|
|
|
|
|
+ // Simultaneous upload limiting is shared across all uploads with this plugin.
|
|
|
|
+ if (typeof this.opts.limit === 'number' && this.opts.limit !== 0) {
|
|
|
|
+ this.limitUploads = limitPromises(this.opts.limit)
|
|
|
|
+ } else {
|
|
|
|
+ this.limitUploads = (fn) => fn
|
|
|
|
+ }
|
|
|
|
+
|
|
this.uploaders = Object.create(null)
|
|
this.uploaders = Object.create(null)
|
|
this.uploaderEvents = Object.create(null)
|
|
this.uploaderEvents = Object.create(null)
|
|
this.uploaderSockets = Object.create(null)
|
|
this.uploaderSockets = Object.create(null)
|
|
@@ -194,9 +203,6 @@ module.exports = class Tus extends Plugin {
|
|
if (!file.isPaused) {
|
|
if (!file.isPaused) {
|
|
upload.start()
|
|
upload.start()
|
|
}
|
|
}
|
|
- if (!file.isRestored) {
|
|
|
|
- this.uppy.emit('upload-started', file, upload)
|
|
|
|
- }
|
|
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
@@ -218,8 +224,6 @@ module.exports = class Tus extends Plugin {
|
|
.catch(reject)
|
|
.catch(reject)
|
|
}
|
|
}
|
|
|
|
|
|
- this.uppy.emit('upload-started', file)
|
|
|
|
-
|
|
|
|
fetch(file.remote.url, {
|
|
fetch(file.remote.url, {
|
|
method: 'post',
|
|
method: 'post',
|
|
credentials: 'include',
|
|
credentials: 'include',
|
|
@@ -407,23 +411,28 @@ module.exports = class Tus extends Plugin {
|
|
}
|
|
}
|
|
|
|
|
|
uploadFiles (files) {
|
|
uploadFiles (files) {
|
|
- const promises = files.map((file, index) => {
|
|
|
|
- const current = parseInt(index, 10) + 1
|
|
|
|
|
|
+ const actions = files.map((file, i) => {
|
|
|
|
+ const current = parseInt(i, 10) + 1
|
|
const total = files.length
|
|
const total = files.length
|
|
|
|
|
|
if (file.error) {
|
|
if (file.error) {
|
|
- return Promise.reject(new Error(file.error))
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- this.uppy.log(`uploading ${current} of ${total}`)
|
|
|
|
-
|
|
|
|
- if (file.isRemote) {
|
|
|
|
- return this.uploadRemote(file, current, total)
|
|
|
|
|
|
+ return () => Promise.reject(new Error(file.error))
|
|
|
|
+ } else if (file.isRemote) {
|
|
|
|
+ // We emit upload-started here, so that it's also emitted for files
|
|
|
|
+ // that have to wait due to the `limit` option.
|
|
|
|
+ this.uppy.emit('upload-started', file)
|
|
|
|
+ return this.uploadRemote.bind(this, file, current, total)
|
|
} else {
|
|
} else {
|
|
- return this.upload(file, current, total)
|
|
|
|
|
|
+ this.uppy.emit('upload-started', file)
|
|
|
|
+ return this.upload.bind(this, file, current, total)
|
|
}
|
|
}
|
|
})
|
|
})
|
|
|
|
|
|
|
|
+ const promises = actions.map((action) => {
|
|
|
|
+ const limitedAction = this.limitUploads(action)
|
|
|
|
+ return limitedAction()
|
|
|
|
+ })
|
|
|
|
+
|
|
return settle(promises)
|
|
return settle(promises)
|
|
}
|
|
}
|
|
|
|
|