From fa8bb48c502515eeed478fae18ddfe8b877effd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9e=20Kooi?= Date: Mon, 22 Jan 2018 11:04:32 +0100 Subject: [PATCH] s3: Respect `limit` option for upload parameter requests too Ref https://github.com/transloadit/uppy/issues/513 Apply the same limit to upload parameter requests as is applied to XHRUpload requests. --- src/plugins/AwsS3/index.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/plugins/AwsS3/index.js b/src/plugins/AwsS3/index.js index 142352169..50e96e4f2 100644 --- a/src/plugins/AwsS3/index.js +++ b/src/plugins/AwsS3/index.js @@ -1,5 +1,6 @@ const Plugin = require('../../core/Plugin') const Translator = require('../../core/Translator') +const { limitPromises } = require('../../core/Utils') const XHRUpload = require('../XHRUpload') function isXml (xhr) { @@ -34,6 +35,12 @@ module.exports = class AwsS3 extends Plugin { this.i18n = this.translator.translate.bind(this.translator) this.prepareUpload = this.prepareUpload.bind(this) + + if (typeof this.opts.limit === 'number' && this.opts.limit !== 0) { + this.limitRequests = limitPromises(this.opts.limit) + } else { + this.limitRequests = (fn) => fn + } } getUploadParameters (file) { @@ -58,11 +65,13 @@ module.exports = class AwsS3 extends Plugin { }) }) + const getUploadParameters = this.limitRequests(this.opts.getUploadParameters) + return Promise.all( fileIDs.map((id) => { const file = this.uppy.getFile(id) const paramsPromise = Promise.resolve() - .then(() => this.opts.getUploadParameters(file)) + .then(() => getUploadParameters(file)) return paramsPromise.then((params) => { this.uppy.emit('preprocess-progress', file.id, { mode: 'determinate',