Skip to content

修复 sdk 最近的一些 issue #400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Feb 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "qiniu-js",
"jsName": "qiniu",
"version": "2.5.3",
"version": "2.5.4",
"private": false,
"description": "Javascript SDK for Qiniu Resource (Cloud) Storage AP",
"main": "dist/qiniu.min.js",
Expand Down
13 changes: 6 additions & 7 deletions src/statisticsLog.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,23 @@ export class StatisticsLogger{
log(info, token) {
let logString = "";
Object.keys(info).forEach(k => logString += info[k] + ",");
this.send(logString, token);
this.send(logString, token, 0);
}

send(logString, token){
send(logString, token, retryCount) {
let xhr = createXHR();
let count = 0;
let self = this;
xhr.open("POST", "https://uplog.qbox.me/log/3");
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.setRequestHeader("Authorization", "UpToken " + token);
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
if (xhr.status !== 200) {
count++;
count <= 3 ? xhr.send(logString) : "";
}
++retryCount <= 3 && self.send(logString, token, retryCount);
}
}
};
xhr.send(logString);
}

}
}
16 changes: 13 additions & 3 deletions src/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ export class UploadManager {
removeLocalFileInfo(this.file);
return;
}
setLocalFileInfo(this.file, this.ctxList);
}
);
return result;
Expand Down Expand Up @@ -231,12 +230,16 @@ export class UploadManager {
onProgress,
onCreate
}).then(response => {
// 在某些浏览器环境下,xhr 的 progress 事件无法被触发,progress 为 null,这里在每次分片上传完成后都手动更新下 progress
onProgress({ loaded: chunk.size });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

确认一下 progress 多触发一两次没问题吗?
另外触发顺序检查了吗?(确保 progress 一定是增的或者说不减的,并且一定在 complete 前触发)


this.ctxList[index] = {
time: new Date().getTime(),
ctx: response.data.ctx,
size: chunk.size,
md5: md5
};
setLocalFileInfo(this.file, this.ctxList);
});
});
}
Expand Down Expand Up @@ -272,9 +275,16 @@ export class UploadManager {
this.onData(this.progress);
}

finishDirectProgress(){
finishDirectProgress() {
// 在某些浏览器环境下,xhr 的 progress 事件无法被触发,progress 为 null, 这里 fake 下
if (!this.progress) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

整体流程上看 progress 为 null 的情况确认只需要处理这一处吗?
记得之前出 bug 好像有不止一个地方会因为 progress 出 null 的问题的…

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

有两处啊,毕竟上传方式有两种

this.progress = { total: this.getProgressInfoItem(this.file.size, this.file.size) };
this.onData(this.progress);
return;
}

let total = this.progress.total;
this.progress.total = this.getProgressInfoItem(total.loaded + 1, total.size);
this.progress = { total: this.getProgressInfoItem(total.loaded + 1, total.size) };
this.onData(this.progress);
}

Expand Down
2 changes: 1 addition & 1 deletion test/demo2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.6.0",
"babel-runtime": "^6.26.0",
"qiniu-js":"^2.0.2",
"es3ify-loader": "^0.2.0",
"open-browser-webpack-plugin": "0.0.5",
"qiniu-js": "^2.5.4",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

只需要更新一个 demo 的依赖?

Copy link
Contributor Author

@winddies winddies Feb 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是的,只有这个是单独有自己的node_modules

"uglifyjs-webpack-plugin": "^1.1.6",
"webpack": "^3.6.0",
"webpack-dev-server": "^2.9.1"
Expand Down