mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05:00
Limited simultaneous upload requests (#890)
closes https://github.com/TryGhost/Ghost/issues/9120 - use `ember-concurrency` to enqueue uploads in `{{gh-uploader}} - set simultaneous upload limit to 2
This commit is contained in:
parent
d03c3a167d
commit
60ed43b373
1 changed files with 9 additions and 6 deletions
|
@ -18,6 +18,8 @@ import {run} from '@ember/runloop';
|
|||
// "allowMultiple" attribute so that single-image uploads don't allow multiple
|
||||
// simultaneous uploads
|
||||
|
||||
const MAX_SIMULTANEOUS_UPLOADS = 2;
|
||||
|
||||
/**
|
||||
* Result from a file upload
|
||||
* @typedef {Object} UploadResult
|
||||
|
@ -166,7 +168,11 @@ export default Component.extend({
|
|||
// NOTE: for...of loop results in a transpilation that errors in Edge,
|
||||
// once we drop IE11 support we should be able to use native for...of
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
uploads.push(this.get('_uploadFile').perform(files[i], i));
|
||||
let file = files[i];
|
||||
let tracker = new UploadTracker({file});
|
||||
|
||||
this.get('_uploadTrackers').pushObject(tracker);
|
||||
uploads.push(this.get('_uploadFile').perform(tracker, file, i));
|
||||
}
|
||||
|
||||
// populates this.errors and this.uploadUrls
|
||||
|
@ -179,14 +185,11 @@ export default Component.extend({
|
|||
this.onComplete(this.get('uploadUrls'));
|
||||
}).drop(),
|
||||
|
||||
_uploadFile: task(function* (file, index) {
|
||||
_uploadFile: task(function* (tracker, file, index) {
|
||||
let ajax = this.get('ajax');
|
||||
let formData = this._getFormData(file);
|
||||
let url = `${ghostPaths().apiRoot}${this.get('uploadUrl')}`;
|
||||
|
||||
let tracker = new UploadTracker({file});
|
||||
this.get('_uploadTrackers').pushObject(tracker);
|
||||
|
||||
try {
|
||||
let response = yield ajax.post(url, {
|
||||
data: formData,
|
||||
|
@ -242,7 +245,7 @@ export default Component.extend({
|
|||
this.get('errors').pushObject(result);
|
||||
this.onUploadFailure(result);
|
||||
}
|
||||
}),
|
||||
}).maxConcurrency(MAX_SIMULTANEOUS_UPLOADS).enqueue(),
|
||||
|
||||
// NOTE: this is necessary because the API doesn't accept direct file uploads
|
||||
_getFormData(file) {
|
||||
|
|
Loading…
Add table
Reference in a new issue