Skip to content

Commit

Permalink
add onTaskStart
Browse files Browse the repository at this point in the history
change TaskReady to onTaskReady
  • Loading branch information
carsonxu committed Apr 3, 2019
1 parent 2112bac commit cc8bc75
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 29 deletions.
12 changes: 8 additions & 4 deletions demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -581,8 +581,12 @@ function putObject() {
Region: config.Region,
Key: filename, /* 必须 */
Body: blob,
TaskReady: function (tid) {
onTaskReady: function (tid) {
TaskId = tid;
console.log('onTaskReady', tid);
},
onTaskStart: function (info) {
console.log('onTaskStart', info);
},
onProgress: function (progressData) {
logger.log(JSON.stringify(progressData));
Expand Down Expand Up @@ -725,7 +729,7 @@ function sliceUploadFile() {
Region: config.Region,
Key: '3mb.zip', /* 必须 */
Body: blob,
TaskReady: function (tid) {
onTaskReady: function (tid) {
TaskId = tid;
},
onHashProgress: function (progressData) {
Expand All @@ -751,7 +755,7 @@ function selectFileToUpload() {
Region: config.Region,
Key: file.name,
Body: file,
TaskReady: function (tid) {
onTaskReady: function (tid) {
TaskId = tid;
},
onHashProgress: function (progressData) {
Expand All @@ -769,7 +773,7 @@ function selectFileToUpload() {
Region: config.Region,
Key: file.name,
Body: file,
TaskReady: function (tid) {
onTaskReady: function (tid) {
TaskId = tid;
},
onProgress: function (progressData) {
Expand Down
19 changes: 13 additions & 6 deletions dist/cos-js-sdk-v5.js
Original file line number Diff line number Diff line change
Expand Up @@ -1983,7 +1983,7 @@ base.init(COS, task);
advance.init(COS, task);

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

module.exports = COS;

Expand Down Expand Up @@ -3738,6 +3738,7 @@ var initTask = function (cos) {
if (task.state === 'waiting') {
uploadingFileCount++;
task.state = 'checking';
task.params.onTaskStart && task.params.onTaskStart(formatTask(task));
!task.params.UploadData && (task.params.UploadData = {});
var apiParams = util.formatParams(task.api, task.params);
originApiMap[task.api].call(cos, apiParams, function (err, data) {
Expand Down Expand Up @@ -3802,6 +3803,7 @@ var initTask = function (cos) {
emitListUpdate();
};

var isTaskReadyWarning = true;
cos._addTask = function (api, params, callback, ignoreAddEvent) {

// 复制参数对象
Expand All @@ -3810,7 +3812,12 @@ var initTask = function (cos) {
// 生成 id
var id = util.uuid();
params.TaskId = id;
params.TaskReady && params.TaskReady(id);
params.onTaskReady && params.onTaskReady(id);
if (params.TaskReady) {
params.TaskReady(id);
isTaskReadyWarning && console.warn('warning: Param "TaskReady" has been deprecated. Please use "onTaskReady" instead.');
isTaskReadyWarning = false;
}

var task = {
// env
Expand Down Expand Up @@ -11557,12 +11564,12 @@ function uploadFiles(params, callback) {
});

// 处理单个文件 TaskReady
var _TaskReady = fileParams.TaskReady;
var TaskReady = function (tid) {
var _onTaskReady = fileParams.onTaskReady;
var onTaskReady = function (tid) {
fileInfo.TaskId = tid;
_TaskReady && _TaskReady(tid);
_onTaskReady && _onTaskReady(tid);
};
fileParams.TaskReady = TaskReady;
fileParams.onTaskReady = onTaskReady;

// 处理单个文件进度
var PreAddSize = 0;
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.11",
"version": "0.5.12",
"description": "JavaScript SDK for [腾讯云对象存储](https://cloud.tencent.com/product/cos)",
"main": "index.js",
"scripts": {
Expand Down
1 change: 0 additions & 1 deletion server/sts.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ app.all('/sts', function (req, res, next) {
'statement': [{
'action': config.allowActions,
'effect': 'allow',
'principal': {'qcs': ['*']},
'resource': [
'qcs::cos:ap-guangzhou:uid/' + AppId + ':prefix//' + AppId + '/' + ShortBucketName + '/' + config.allowPrefix,
],
Expand Down
2 changes: 1 addition & 1 deletion server/sts.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
'url' => 'https://sts.tencentcloudapi.com/',
'domain' => 'sts.tencentcloudapi.com',
'proxy' => '',
'secretId' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', // 固定密钥
'secretId' => 'AKIDxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', // 固定密钥
'secretKey' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', // 固定密钥
'bucket' => 'test-1250000000', // 换成你的 bucket
'region' => 'ap-guangzhou', // 换成 bucket 所在园区
Expand Down
8 changes: 4 additions & 4 deletions src/advance.js
Original file line number Diff line number Diff line change
Expand Up @@ -911,12 +911,12 @@ function uploadFiles(params, callback) {
});

// 处理单个文件 TaskReady
var _TaskReady = fileParams.TaskReady;
var TaskReady = function (tid) {
var _onTaskReady = fileParams.onTaskReady;
var onTaskReady = function (tid) {
fileInfo.TaskId = tid;
_TaskReady && _TaskReady(tid);
_onTaskReady && _onTaskReady(tid);
};
fileParams.TaskReady = TaskReady;
fileParams.onTaskReady = onTaskReady;

// 处理单个文件进度
var PreAddSize = 0;
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.11';
COS.version = '0.5.12';

module.exports = COS;
9 changes: 8 additions & 1 deletion src/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ var initTask = function (cos) {
if (task.state === 'waiting') {
uploadingFileCount++;
task.state = 'checking';
task.params.onTaskStart && task.params.onTaskStart(formatTask(task));
!task.params.UploadData && (task.params.UploadData = {});
var apiParams = util.formatParams(task.api, task.params);
originApiMap[task.api].call(cos, apiParams, function (err, data) {
Expand Down Expand Up @@ -136,6 +137,7 @@ var initTask = function (cos) {
emitListUpdate();
};

var isTaskReadyWarning = true;
cos._addTask = function (api, params, callback, ignoreAddEvent) {

// 复制参数对象
Expand All @@ -144,7 +146,12 @@ var initTask = function (cos) {
// 生成 id
var id = util.uuid();
params.TaskId = id;
params.TaskReady && params.TaskReady(id);
params.onTaskReady && params.onTaskReady(id);
if (params.TaskReady) {
params.TaskReady(id);
isTaskReadyWarning && console.warn('warning: Param "TaskReady" has been deprecated. Please use "onTaskReady" instead.');
isTaskReadyWarning = false;
}

var task = {
// env
Expand Down
18 changes: 9 additions & 9 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ group('mock readAsBinaryString', function () {
Region: config.Region,
Key: filename,
Body: blob,
TaskReady: function (taskId) {
onTaskReady: function (taskId) {
TaskId = taskId;
},
onProgress: function (info) {
Expand All @@ -293,7 +293,7 @@ group('mock readAsBinaryString', function () {
Region: config.Region,
Key: filename,
Body: blob,
TaskReady: function (taskId) {
onTaskReady: function (taskId) {
TaskId = taskId;
},
onProgress: function (info) {
Expand Down Expand Up @@ -436,7 +436,7 @@ group('putObject(),cancelTask()', function () {
Region: config.Region,
Key: filename,
Body: util.createFile({size: 1024 * 1024 * 10}),
TaskReady: function (taskId) {
onTaskReady: function (taskId) {
TaskId = taskId;
},
onProgress: function (info) {
Expand Down Expand Up @@ -474,7 +474,7 @@ group('sliceUploadFile() 完整上传文件', function () {
Region: config.Region,
Key: filename,
Body: blob,
TaskReady: function (taskId) {
onTaskReady: function (taskId) {
TaskId = taskId;
},
onProgress: function (info) {
Expand Down Expand Up @@ -513,7 +513,7 @@ group('sliceUploadFile(),pauseTask(),restartTask()', function () {
Region: config.Region,
Key: filename,
Body: blob,
TaskReady: function (taskId) {
onTaskReady: function (taskId) {
TaskId = taskId;
},
onProgress: function (info) {
Expand Down Expand Up @@ -549,7 +549,7 @@ group('sliceUploadFile(),cancelTask()', function () {
Region: config.Region,
Key: filename,
Body: blob,
TaskReady: function (taskId) {
onTaskReady: function (taskId) {
TaskId = taskId;
},
onProgress: function (info) {
Expand Down Expand Up @@ -605,7 +605,7 @@ group('abortUploadTask()', function () {
Region: config.Region,
Key: filename,
Body: blob,
TaskReady: function (taskId) {
onTaskReady: function (taskId) {
TaskId = taskId;
},
onProgress: function (info) {
Expand All @@ -632,7 +632,7 @@ group('abortUploadTask()', function () {
Region: config.Region,
Key: filename,
Body: blob,
TaskReady: function (taskId) {
onTaskReady: function (taskId) {
TaskId = taskId;
},
onProgress: function (info) {
Expand Down Expand Up @@ -2377,4 +2377,4 @@ group('Cache-Control', function () {
});
});
});
});
});

0 comments on commit cc8bc75

Please sign in to comment.