Skip to content

Commit

Permalink
feat: optimized multipartUpload progress close #1139 (#1141)
Browse files Browse the repository at this point in the history
* feat: optimized multipartUpload progress close #1139

* feat: optimized multipartUpload progress close #1139 #1141

* feat: optimized multipartUpload progress

* feat: optimized multipartUpload progress
  • Loading branch information
taotao7 authored Jul 26, 2022
1 parent 014ecba commit 12fcfd1
Show file tree
Hide file tree
Showing 6 changed files with 200 additions and 150 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ package-lock.json
/example/public/index.js

es
.eslintcache
4 changes: 1 addition & 3 deletions lib/browser/managed-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ const mime = require('mime');
const copy = require('copy-to');
const { isBlob } = require('../common/utils/isBlob');
const { isFile } = require('../common/utils/isFile');
const { isArray } = require('../common/utils/isArray');
const { isBuffer } = require('../common/utils/isBuffer');
const { retry } = require('../common/utils/retry');

const proto = exports;

Expand Down Expand Up @@ -160,7 +158,7 @@ proto._resumeMultipart = async function _resumeMultipart(checkpoint, options) {
});

if (options.progress) {
await options.progress(doneParts.length / numParts, checkpoint, result.res);
await options.progress(doneParts.length / (numParts + 1), checkpoint, result.res);
}

resolve({
Expand Down
4 changes: 4 additions & 0 deletions lib/common/multipart.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ proto.completeMultipartUpload = async function completeMultipartUpload(name, upl
params.successStatuses = [200];
const result = await this.request(params);

if (options.progress) {
await options.progress(1, null, result.res);
}

const ret = {
res: result.res,
bucket: params.bucket,
Expand Down
17 changes: 11 additions & 6 deletions lib/managed-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ proto._resumeMultipart = async function _resumeMultipart(checkpoint, options) {
checkpoint.doneParts = doneParts;

if (options.progress) {
await options.progress(doneParts.length / numParts, checkpoint, result.res);
await options.progress(doneParts.length / (numParts + 1), checkpoint, result.res);
}
}
}
Expand Down Expand Up @@ -208,12 +208,17 @@ proto._resumeMultipart = async function _resumeMultipart(checkpoint, options) {
}
} else {
// upload in parallel
const jobErr = await this._parallel(todo, parallel,
const jobErr = await this._parallel(
todo,
parallel,
value => new Promise((resolve, reject) => {
uploadPartJob(that, value).then(() => {
resolve();
}).catch(reject);
}));
uploadPartJob(that, value)
.then(() => {
resolve();
})
.catch(reject);
})
);

const abortEvent = jobErr.find(err => err.name === 'abort');
if (abortEvent) throw abortEvent;
Expand Down
4 changes: 2 additions & 2 deletions test/browser/browser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1329,7 +1329,7 @@ describe('browser', () => {
});
sinon.restore();
assert.equal(result.res.status, 200);
assert.equal(progress, 12);
assert.equal(progress, 13);

const object = await store.get(name);
assert.equal(object.res.status, 200);
Expand Down Expand Up @@ -1362,7 +1362,7 @@ describe('browser', () => {
});
sinon.restore();
assert.equal(result.res.status, 200);
assert.equal(progress, 12);
assert.equal(progress, 13);

const object = await store.get(name);
assert.equal(object.res.status, 200);
Expand Down
Loading

0 comments on commit 12fcfd1

Please sign in to comment.