Skip to content

Commit

Permalink
修改队列清理,修改 userAgent 容错
Browse files Browse the repository at this point in the history
  • Loading branch information
carsonxu committed Mar 12, 2019
1 parent e805e62 commit b478fd3
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 18 deletions.
20 changes: 11 additions & 9 deletions dist/cos-js-sdk-v5.js
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ var fileSliceNeedCopy = function () {
var need = ChromeVersion && compareVersion(ChromeVersion, '53.0.2785.116') < 0 && QBCoreVersion && compareVersion(QBCoreVersion, '3.53.991.400') < 0 && QQBrowserVersion && compareVersion(QQBrowserVersion, '9.0.2524.400') <= 0 || false;
return need;
};
return check(navigator.userAgent);
return check(navigator && navigator.userAgent);
}();
util.fileSlice = function (file, start, end, isUseToUpload, callback) {
var blob;
Expand Down Expand Up @@ -1983,7 +1983,7 @@ base.init(COS, task);
advance.init(COS, task);

COS.getAuthorization = util.getAuth;
COS.version = '0.5.10';
COS.version = '0.5.11';

module.exports = COS;

Expand Down Expand Up @@ -3721,7 +3721,9 @@ var initTask = function (cos) {
for (i = 0; i < queue.length && queue.length > cos.options.UploadQueueSize && // 大于队列才处理
i < nextUploadIndex; // 小于当前操作的 index 才处理
i++) {
if (!queue[i] || queue[i].state !== 'waiting') {
var isActive = queue[i].state === 'waiting' || queue[i].state === 'checking' || queue[i].state === 'uploading';
if (!queue[i] || !isActive) {
tasks[queue[i].id] && delete tasks[queue[i].id];
queue.splice(i, 1);
nextUploadIndex--;
}
Expand All @@ -3732,6 +3734,7 @@ var initTask = function (cos) {
var startNextTask = function () {
if (nextUploadIndex < queue.length && uploadingFileCount < cos.options.FileParallelLimit) {
var task = queue[nextUploadIndex];
nextUploadIndex++;
if (task.state === 'waiting') {
uploadingFileCount++;
task.state = 'checking';
Expand Down Expand Up @@ -3759,7 +3762,6 @@ var initTask = function (cos) {
});
emitListUpdate();
}
nextUploadIndex++;
startNextTask(cos);
}
};
Expand Down Expand Up @@ -5144,7 +5146,7 @@ function optionsObject(params, callback) {
* @param {String} CopySourceIfUnmodifiedSince 当Object在指定时间后未被修改,则执行操作,否则返回412。可与x-cos-copy-source-If-Match一起使用,与其他条件联合使用返回冲突。
* @param {String} CopySourceIfMatch 当Object的Etag和给定一致时,则执行操作,否则返回412。可与x-cos-copy-source-If-Unmodified-Since一起使用,与其他条件联合使用返回冲突。
* @param {String} CopySourceIfNoneMatch 当Object的Etag和给定不一致时,则执行操作,否则返回412。可与x-cos-copy-source-If-Modified-Since一起使用,与其他条件联合使用返回冲突。
* @param {String} StorageClass 存储级别,枚举值:存储级别,枚举值:Standard, Standard_IA,Nearline;默认值:Standard
* @param {String} StorageClass 存储级别,枚举值:存储级别,枚举值:Standard, Standard_IA,Archive;默认值:Standard
* @param {String} CacheControl 指定所有缓存机制在整个请求/响应链中必须服从的指令。
* @param {String} ContentDisposition MIME 协议的扩展,MIME 协议指示 MIME 用户代理如何显示附加的文件
* @param {String} ContentEncoding HTTP 中用来对「采用何种编码格式传输正文」进行协定的一对头部字段
Expand Down Expand Up @@ -5349,7 +5351,7 @@ function restoreObject(params, callback) {
* @param {String} params.GrantRead 赋予被授权者读的权限 ,非必须
* @param {String} params.GrantWrite 赋予被授权者写的权限 ,非必须
* @param {String} params.GrantFullControl 赋予被授权者读写权限 ,非必须
* @param {String} params.StorageClass 设置Object的存储级别,枚举值:Standard,Standard_IA,Nearline,非必须
* @param {String} params.StorageClass 设置Object的存储级别,枚举值:Standard,Standard_IA,Archive,非必须
* @param {String} params.ServerSideEncryption 支持按照指定的加密算法进行服务端数据加密,格式 x-cos-server-side-encryption: "AES256",非必须
* @param {Function} callback 回调函数,必须
* @return {Object} err 请求失败的错误,如果请求成功,则为空。https://cloud.tencent.com/document/product/436/7730
Expand All @@ -5359,7 +5361,7 @@ function multipartInit(params, callback) {

var xml;
var headers = params.Headers;
var userAgent = navigator.userAgent || '';
var userAgent = navigator && navigator.userAgent || '';
var m = userAgent.match(/ TBS\/(\d{6}) /);
if (location.protocol === 'http:' && m && m[1].length <= 6 && m[1] < '044429') {
xml = util.json2xml({});
Expand Down Expand Up @@ -11163,7 +11165,7 @@ function wholeMultipartList(params, callback) {
self.multipartList(sendParams, function (err, data) {
if (err) return callback(err);
UploadList.push.apply(UploadList, data.Upload || []);
if (data.IsTruncated == 'true') {
if (data.IsTruncated === 'true') {
// 列表不完整
sendParams.KeyMarker = data.NextKeyMarker;
sendParams.UploadIdMarker = data.NextUploadIdMarker;
Expand All @@ -11190,7 +11192,7 @@ function wholeMultipartListPart(params, callback) {
self.multipartListPart(sendParams, function (err, data) {
if (err) return callback(err);
PartList.push.apply(PartList, data.Part || []);
if (data.IsTruncated == 'true') {
if (data.IsTruncated === 'true') {
// 列表不完整
sendParams.PartNumberMarker = data.NextPartNumberMarker;
next();
Expand Down
2 changes: 1 addition & 1 deletion dist/cos-js-sdk-v5.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cos-js-sdk-v5",
"version": "0.5.10",
"version": "0.5.11",
"description": "JavaScript SDK for [腾讯云对象存储](https://cloud.tencent.com/product/cos)",
"main": "index.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions src/advance.js
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ function wholeMultipartList(params, callback) {
self.multipartList(sendParams, function (err, data) {
if (err) return callback(err);
UploadList.push.apply(UploadList, data.Upload || []);
if (data.IsTruncated == 'true') { // 列表不完整
if (data.IsTruncated === 'true') { // 列表不完整
sendParams.KeyMarker = data.NextKeyMarker;
sendParams.UploadIdMarker = data.NextUploadIdMarker;
next();
Expand All @@ -545,7 +545,7 @@ function wholeMultipartListPart(params, callback) {
self.multipartListPart(sendParams, function (err, data) {
if (err) return callback(err);
PartList.push.apply(PartList, data.Part || []);
if (data.IsTruncated == 'true') { // 列表不完整
if (data.IsTruncated === 'true') { // 列表不完整
sendParams.PartNumberMarker = data.NextPartNumberMarker;
next();
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -1465,7 +1465,7 @@ function multipartInit(params, callback) {

var xml;
var headers = params.Headers;
var userAgent = navigator.userAgent || '';
var userAgent = navigator && navigator.userAgent || '';
var m = userAgent.match(/ TBS\/(\d{6}) /);
if (location.protocol === 'http:' && m && m[1].length <= 6 && m[1] < '044429') {
xml = util.json2xml({});
Expand Down
2 changes: 1 addition & 1 deletion src/cos.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ base.init(COS, task);
advance.init(COS, task);

COS.getAuthorization = util.getAuth;
COS.version = '0.5.10';
COS.version = '0.5.11';

module.exports = COS;
6 changes: 4 additions & 2 deletions src/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ var initTask = function (cos) {
queue.length > cos.options.UploadQueueSize && // 大于队列才处理
i < nextUploadIndex; // 小于当前操作的 index 才处理
i++) {
if (!queue[i] || queue[i].state !== 'waiting') {
var isActive = queue[i].state === 'waiting' || queue[i].state === 'checking' || queue[i].state === 'uploading';
if (!queue[i] || !isActive) {
tasks[queue[i].id] && (delete tasks[queue[i].id]);
queue.splice(i, 1);
nextUploadIndex--;
}
Expand All @@ -64,6 +66,7 @@ var initTask = function (cos) {
if (nextUploadIndex < queue.length &&
uploadingFileCount < cos.options.FileParallelLimit) {
var task = queue[nextUploadIndex];
nextUploadIndex++;
if (task.state === 'waiting') {
uploadingFileCount++;
task.state = 'checking';
Expand Down Expand Up @@ -91,7 +94,6 @@ var initTask = function (cos) {
});
emitListUpdate();
}
nextUploadIndex++;
startNextTask(cos);
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ var fileSliceNeedCopy = (function () {
&& QQBrowserVersion && compareVersion(QQBrowserVersion, '9.0.2524.400') <= 0 || false;
return need;
};
return check(navigator.userAgent);
return check(navigator && navigator.userAgent);
})();
util.fileSlice = function (file, start, end, isUseToUpload, callback) {
var blob;
Expand Down

0 comments on commit b478fd3

Please sign in to comment.