@@ -7882,10 +7882,12 @@ var defaultOptions = {
78827882 AppId: '',
78837883 SecretId: '',
78847884 SecretKey: '',
7885- ProgressInterval: 1000,
78867885 FileParallelLimit: 3,
78877886 ChunkParallelLimit: 3,
7888- ChunkSize: 1024 * 1024
7887+ ChunkSize: 1024 * 1024,
7888+ ProgressInterval: 1000,
7889+ Domain: '',
7890+ ServiceDomain: ''
78897891};
78907892
78917893// 对外暴露的类
@@ -15396,11 +15398,23 @@ function getService(params, callback) {
1539615398 callback = params;
1539715399 params = {};
1539815400 }
15399-
1540015401 var protocol = util.isBrowser && location.protocol === 'https:' ? 'https:' : 'http:';
15402+ var domain = this.options.ServiceDomain;
15403+ var appId = params.AppId || this.options.appId;
15404+ if (domain) {
15405+ domain = domain.replace(/\{\{AppId\}\}/ig, appId || '').replace(/\{\{.*?\}\}/ig, '');
15406+ if (!/^[a-zA-Z]+:\/\//.test(domain)) {
15407+ domain = protocol + '//' + domain;
15408+ }
15409+ if (domain.slice(-1) === '/') {
15410+ domain = domain.slice(0, -1);
15411+ }
15412+ } else {
15413+ domain = protocol + '//service.cos.myqcloud.com';
15414+ }
1540115415
1540215416 submitRequest.call(this, {
15403- url: protocol + '//service.cos.myqcloud.com' ,
15417+ url: domain ,
1540415418 method: 'GET'
1540515419 }, function (err, data) {
1540615420 if (err) {
@@ -15525,6 +15539,7 @@ function getBucket(params, callback) {
1552515539 * @return {String} data.Location 操作地址
1552615540 */
1552715541function putBucket(params, callback) {
15542+ var self = this;
1552815543 var headers = {};
1552915544 headers['x-cos-acl'] = params['ACL'];
1553015545 headers['x-cos-grant-read'] = params['GrantRead'];
@@ -15542,6 +15557,7 @@ function putBucket(params, callback) {
1554215557 return callback(err);
1554315558 }
1554415559 var url = getUrl({
15560+ domain: self.options.Domain,
1554515561 bucket: params.Bucket,
1554615562 region: params.Region,
1554715563 appId: appId
@@ -16307,7 +16323,7 @@ function _putObject(params, callback) {
1630716323 update();
1630816324 } else {
1630916325 if (progressTimer) return;
16310- progressTimer = setTimeout(update, self.options.ProgressInterval || 100 );
16326+ progressTimer = setTimeout(update, self.options.ProgressInterval || 1000 );
1631116327 }
1631216328 };
1631316329 }();
@@ -16736,7 +16752,6 @@ function multipartUpload(params, callback) {
1673616752 var self = this;
1673716753 var TaskId = params.TaskId;
1673816754 var headers = {};
16739- console.log(TaskId, params);
1674016755
1674116756 headers['Content-Length'] = params['ContentLength'];
1674216757 headers['Expect'] = params['Expect'];
@@ -16758,7 +16773,7 @@ function multipartUpload(params, callback) {
1675816773 body: params.Body || null,
1675916774 onProgress: params.onProgress
1676016775 }, function (err, data) {
16761- // if (TaskId) self.off('inner-kill-task', killTask);
16776+ if (TaskId) self.off('inner-kill-task', killTask);
1676216777 if (err) {
1676316778 return callback(err);
1676416779 }
@@ -16771,16 +16786,14 @@ function multipartUpload(params, callback) {
1677116786 });
1677216787
1677316788 var killTask = function (data) {
16774- console.log(count, TaskId, data.TaskId);
1677516789 if (data.TaskId === TaskId) {
1677616790 sender && sender.abort && sender.abort();
1677716791 self.off('inner-kill-task', killTask);
1677816792 }
1677916793 };
16780- killTask.id = count++;
1678116794 TaskId && this.on('inner-kill-task', killTask);
1678216795}
16783- var count = 0;
16796+
1678416797/**
1678516798 * 完成分块上传
1678616799 * @param {Object} params 参数对象,必须
@@ -17008,14 +17021,25 @@ function getAuth(params) {
1700817021
1700917022// 生成操作 url
1701017023function getUrl(params) {
17024+ var domain = params.domain;
1701117025 var bucket = params.bucket;
1701217026 var region = params.region;
1701317027 var object = params.object;
1701417028 var action = params.action;
1701517029 var appId = params.appId;
1701617030 var protocol = util.isBrowser && location.protocol === 'https:' ? 'https:' : 'http:';
17017-
17018- var url = protocol + '//' + bucket + '-' + appId + '.' + region + '.myqcloud.com';
17031+ if (domain) {
17032+ domain = domain.replace(/\{\{AppId\}\}/ig, appId).replace(/\{\{Bucket\}\}/ig, bucket).replace(/\{\{Region\}\}/ig, region).replace(/\{\{.*?\}\}/ig, '');
17033+ if (!/^[a-zA-Z]+:\/\//.test(domain)) {
17034+ domain = protocol + '//' + domain;
17035+ }
17036+ if (domain.slice(-1) === '/') {
17037+ domain = domain.slice(0, -1);
17038+ }
17039+ } else {
17040+ domain = protocol + '//' + bucket + '-' + appId + '.' + region + '.myqcloud.com';
17041+ }
17042+ var url = domain;
1701917043
1702017044 if (object) {
1702117045 url += '/' + encodeURIComponent(object);
@@ -17043,14 +17067,15 @@ function submitRequest(params, callback) {
1704317067
1704417068 var opt = {
1704517069 url: url || getUrl({
17070+ domain: this.options.Domain,
1704617071 bucket: bucket,
1704717072 region: region,
1704817073 object: object,
1704917074 action: action,
1705017075 appId: params.AppId || this.options.AppId
1705117076 }),
1705217077 method: method,
17053- headers: headers,
17078+ headers: headers || {} ,
1705417079 qs: qs,
1705517080 body: body,
1705617081 json: json
@@ -21911,7 +21936,7 @@ function getUploadIdAndPartList(params, callback) {
2191121936 }
2191221937 } else {
2191321938 if (progressTimer) return;
21914- progressTimer = setTimeout(update, self.options.ProgressInterval || 100 );
21939+ progressTimer = setTimeout(update, self.options.ProgressInterval || 1000 );
2191521940 }
2191621941 };
2191721942 var getChunkETag = function (PartNumber, callback) {
@@ -22213,7 +22238,7 @@ function uploadSliceList(params, cb) {
2221322238 update();
2221422239 } else {
2221522240 if (progressTimer) return;
22216- progressTimer = setTimeout(update, self.options.ProgressInterval || 100 );
22241+ progressTimer = setTimeout(update, self.options.ProgressInterval || 1000 );
2221722242 }
2221822243 };
2221922244 }();
@@ -29231,7 +29256,7 @@ function plural(ms, n, name) {
2923129256
2923229257module.exports = {
2923329258 "name": "cos-js-sdk-v5",
29234- "version": "0.0.5 ",
29259+ "version": "0.0.6 ",
2923529260 "description": "cos js sdk v5",
2923629261 "main": "index.js",
2923729262 "scripts": {
0 commit comments