Skip to content

Commit

Permalink
fix task bug
Browse files Browse the repository at this point in the history
  • Loading branch information
carsonxu committed Jul 11, 2017
1 parent 93cebb3 commit 8ebb524
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 28 deletions.
21 changes: 6 additions & 15 deletions demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,27 +471,18 @@ function sliceUploadFile() {
}

function cancelTask() {
sliceUploadFile();
setTimeout(function () {
cos.cancelTask(TaskId);
console.log('canceled');
}, 2000);
cos.cancelTask(TaskId);
console.log('canceled');
}

function pauseTask() {
sliceUploadFile();
setTimeout(function () {
cos.pauseTask(TaskId);
console.log('paused');
restartTask();
}, 2000);
cos.pauseTask(TaskId);
console.log('paused');
}

function restartTask() {
setTimeout(function () {
cos.restartTask(TaskId);
console.log('restart');
}, 4000);
cos.restartTask(TaskId);
console.log('restart');
}

// getService();
Expand Down
23 changes: 17 additions & 6 deletions dist/cos-js-sdk-v5.js
Original file line number Diff line number Diff line change
Expand Up @@ -16113,7 +16113,7 @@ function _putObject(params, callback) {
headers['Content-Type'] = params['ContentType'];
headers['Expect'] = params['Expect'];
headers['Expires'] = params['Expires'];
headers['x-cos-content-sha1'] = params['ContentSha1'];
// headers['x-cos-content-sha1'] = params['ContentSha1'];
headers['x-cos-acl'] = params['ACL'];
headers['x-cos-grant-read'] = params['GrantRead'];
headers['x-cos-grant-write'] = params['GrantWrite'];
Expand Down Expand Up @@ -16448,7 +16448,7 @@ function putObjectCopy(params, callback) {
headers['Content-Type'] = params['ContentType'];
headers['Expect'] = params['Expect'];
headers['Expires'] = params['Expires'];
headers['x-cos-content-sha1'] = params['ContentSha1'];
// headers['x-cos-content-sha1'] = params['ContentSha1'];

for (var key in params) {
if (key.indexOf('x-cos-meta-') > -1) {
Expand Down Expand Up @@ -16615,7 +16615,7 @@ function multipartUpload(params, callback) {

headers['Content-Length'] = params['ContentLength'];
headers['Expect'] = params['Expect'];
headers['x-cos-content-sha1'] = params['ContentSha1'];
// headers['x-cos-content-sha1'] = params['ContentSha1'];

var PartNumber = params['PartNumber'];
var UploadId = params['UploadId'];
Expand Down Expand Up @@ -16937,6 +16937,13 @@ function submitRequest(params, callback) {
object = '/' + object;
}

var innerSender;
var outerSender = {
abort: function () {
innerSender && innerSender.abort && innerSender.abort();
}
};

// 发送请求
var getAuthorizationCallback = function (auth) {

Expand Down Expand Up @@ -16975,7 +16982,7 @@ function submitRequest(params, callback) {
};
}

var sender = REQUEST(opt, function (err, response, body) {
innerSender = REQUEST(opt, function (err, response, body) {

// 返回内容添加 状态码 和 headers
var cb = function (err, data) {
Expand Down Expand Up @@ -17041,6 +17048,8 @@ function submitRequest(params, callback) {
getAuthorizationCallback(auth);
}

return outerSender;

}


Expand Down Expand Up @@ -21478,7 +21487,7 @@ var request = function (options, callback) {
options.dataType = 'text';

// send
$.ajax(options);
return $.ajax(options);

};

Expand Down Expand Up @@ -22201,7 +22210,8 @@ function uploadSliceItem(params, callback) {
}

var Body = util.fileSlice.call(FileBody, start, end);
var ContentSha1 = UploadData.PartList[PartNumber - 1].ETag;
var PartItem = UploadData.PartList[PartNumber - 1];
var ContentSha1 = PartItem.ETag;
Async.retry(sliceRetryTimes, function (tryCallback) {
if (!self._isRunningTask(TaskId)) return;
self.multipartUpload({
Expand All @@ -22220,6 +22230,7 @@ function uploadSliceItem(params, callback) {
if (err) {
return tryCallback(err);
} else {
PartItem.Uploaded = true;
return tryCallback(null, data);
}
});
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 lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -4182,7 +4182,7 @@ var request = function (options, callback) {
options.dataType = 'text';

// send
$.ajax(options);
return $.ajax(options);

};

Expand Down
4 changes: 3 additions & 1 deletion src/advance.js
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,8 @@ function uploadSliceItem(params, callback) {
}

var Body = util.fileSlice.call(FileBody, start, end);
var ContentSha1 = UploadData.PartList[PartNumber - 1].ETag;
var PartItem = UploadData.PartList[PartNumber - 1];
var ContentSha1 = PartItem.ETag;
Async.retry(sliceRetryTimes, function (tryCallback) {
if (!self._isRunningTask(TaskId)) return;
self.multipartUpload({
Expand All @@ -561,6 +562,7 @@ function uploadSliceItem(params, callback) {
if (err) {
return tryCallback(err);
} else {
PartItem.Uploaded = true;
return tryCallback(null, data);
}
});
Expand Down
17 changes: 13 additions & 4 deletions src/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ function _putObject(params, callback) {
headers['Content-Type'] = params['ContentType'];
headers['Expect'] = params['Expect'];
headers['Expires'] = params['Expires'];
headers['x-cos-content-sha1'] = params['ContentSha1'];
// headers['x-cos-content-sha1'] = params['ContentSha1'];
headers['x-cos-acl'] = params['ACL'];
headers['x-cos-grant-read'] = params['GrantRead'];
headers['x-cos-grant-write'] = params['GrantWrite'];
Expand Down Expand Up @@ -1192,7 +1192,7 @@ function putObjectCopy(params, callback) {
headers['Content-Type'] = params['ContentType'];
headers['Expect'] = params['Expect'];
headers['Expires'] = params['Expires'];
headers['x-cos-content-sha1'] = params['ContentSha1'];
// headers['x-cos-content-sha1'] = params['ContentSha1'];

for (var key in params) {
if (key.indexOf('x-cos-meta-') > -1) {
Expand Down Expand Up @@ -1359,7 +1359,7 @@ function multipartUpload(params, callback) {

headers['Content-Length'] = params['ContentLength'];
headers['Expect'] = params['Expect'];
headers['x-cos-content-sha1'] = params['ContentSha1'];
// headers['x-cos-content-sha1'] = params['ContentSha1'];

var PartNumber = params['PartNumber'];
var UploadId = params['UploadId'];
Expand Down Expand Up @@ -1681,6 +1681,13 @@ function submitRequest(params, callback) {
object = '/' + object;
}

var innerSender;
var outerSender = {
abort: function () {
innerSender && innerSender.abort && innerSender.abort();
}
};

// 发送请求
var getAuthorizationCallback = function (auth) {

Expand Down Expand Up @@ -1719,7 +1726,7 @@ function submitRequest(params, callback) {
};
}

var sender = REQUEST(opt, function (err, response, body) {
innerSender = REQUEST(opt, function (err, response, body) {

// 返回内容添加 状态码 和 headers
var cb = function (err, data) {
Expand Down Expand Up @@ -1785,6 +1792,8 @@ function submitRequest(params, callback) {
getAuthorizationCallback(auth);
}

return outerSender;

}


Expand Down

0 comments on commit 8ebb524

Please sign in to comment.