cos-wx-sdk-v5 1.1.8 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/demo/demo-sdk.js CHANGED
@@ -22,7 +22,7 @@ var getAuthorization = function(options, callback) {
22
22
  callback({
23
23
  TmpSecretId: credentials.tmpSecretId,
24
24
  TmpSecretKey: credentials.tmpSecretKey,
25
- XCosSecurityToken: credentials.sessionToken,
25
+ SecurityToken: credentials.sessionToken,
26
26
  StartTime: data.startTime, // 时间戳,单位秒,如:1580000000,建议返回服务器时间作为签名的开始时间,避免用户浏览器本地时间偏差过大导致签名错误
27
27
  ExpiredTime: data.expiredTime, // 时间戳,单位秒,如:1580000900
28
28
  });
@@ -159,7 +159,11 @@ var toolsDao = {
159
159
  Region: config.Region,
160
160
  Key: file.name,
161
161
  FilePath: file.path,
162
+ FileSize: file.size,
162
163
  SliceSize: 1024 * 1024 * 5, // 文件大于5mb自动使用分块上传
164
+ onTaskReady: function(taskId) {
165
+ TaskId = taskId
166
+ },
163
167
  onProgress: function (info) {
164
168
  var percent = parseInt(info.percent * 10000) / 100;
165
169
  var speed = parseInt(info.speed / 1024 / 1024 * 100) / 100;
@@ -681,7 +685,7 @@ var objectDao = {
681
685
  Position: 0,
682
686
  },
683
687
  function(err, data) {
684
- logger.log('putObject:', err || data);
688
+ console.log('putObject:', err || data);
685
689
  })
686
690
  },
687
691
  'appendObject_continue 继续追加上传': function() {
@@ -704,7 +708,7 @@ var objectDao = {
704
708
  function(err, data) {
705
709
  // 也可以取到下一次上传的position继续追加上传
706
710
  // var nextPosition = data.headers['x-cos-next-append-position'];
707
- logger.log('putObject:', err || data);
711
+ console.log('putObject:', err || data);
708
712
  })
709
713
  });
710
714
  },
@@ -947,6 +951,285 @@ var ciObjectDao = {
947
951
  console.log(err || data);
948
952
  });
949
953
  },
954
+ '图片同步审核 getImageAuditing': function () {
955
+ cos.request({
956
+ Bucket: config.Bucket,
957
+ Region: config.Region,
958
+ Method: 'GET',
959
+ Key: '1.png',
960
+ Query: {
961
+ 'ci-process': 'sensitive-content-recognition', /** 固定值,必须 */
962
+ 'biz-type': '', /** 审核类型,非必须 */
963
+ 'detect-type': 'porn,ads', /** 审核策略,不填写则使用默认策略,非必须 */
964
+ 'detect-url': '', /** 审核任意公网可访问的图片链接,非必须 */
965
+ 'interval': 5, /** 审核 GIF 动图时,每隔interval帧截取一帧,非必须 */
966
+ 'max-frames': 5, /** 审核 GIF 动图时,最大截帧数,非必须 */
967
+ 'large-image-detect': '0', /** 是否需要压缩图片后再审核,非必须 */
968
+ },
969
+ },
970
+ function(err, data){
971
+ console.log(err || data);
972
+ });
973
+ },
974
+ '图片批量审核 postImagesAuditing': function () {
975
+ var host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com';
976
+ var url = 'https://' + host + '/image/auditing';
977
+ var body = COS.util.json2xml({
978
+ Request: {
979
+ Input: [{
980
+ Object: '1.png',
981
+ }, {
982
+ Object: '6.png',
983
+ }],
984
+ Conf: {
985
+ BizType: '',
986
+ DetectType: 'Porn'
987
+ }
988
+ }
989
+ });
990
+ cos.request({
991
+ Bucket: config.Bucket,
992
+ Region: config.Region,
993
+ Method: 'POST',
994
+ Url: url,
995
+ Key: '/image/auditing',
996
+ ContentType: 'application/xml',
997
+ Body: body
998
+ },
999
+ function(err, data){
1000
+ console.log(err || data);
1001
+ });
1002
+ },
1003
+ '查询图片审核任务结果 getImageAuditingResult': function () {
1004
+ var jobId = 'si8263213daf3711eca0d1525400d88xxx'; // jobId可以通过图片批量审核返回
1005
+ var host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com';
1006
+ var url = 'https://' + host + '/image/auditing/' + jobId;
1007
+ cos.request({
1008
+ Bucket: config.Bucket,
1009
+ Region: config.Region,
1010
+ Method: 'GET',
1011
+ Key: '/image/auditing/' + jobId,
1012
+ Url: url,
1013
+ },
1014
+ function(err, data){
1015
+ console.log(err || data);
1016
+ });
1017
+ },
1018
+ '提交视频审核任务 postVideoAuditing': function() {
1019
+ var host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com';
1020
+ var url = 'https://' + host + '/video/auditing';
1021
+ var body = COS.util.json2xml({
1022
+ Request: {
1023
+ Input: {
1024
+ Object: '1.mp4',
1025
+ },
1026
+ Conf: {
1027
+ BizType: '',
1028
+ DetectType: 'Porn',
1029
+ Snapshot: {
1030
+ Count: 1000, // 视频截帧数量
1031
+ },
1032
+ DetectContent: 1, // 是否审核视频声音,0-只审核视频不审核声音;1-审核视频+声音
1033
+ }
1034
+ }
1035
+ });
1036
+ cos.request({
1037
+ Bucket: config.Bucket,
1038
+ Region: config.Region,
1039
+ Method: 'POST',
1040
+ Url: url,
1041
+ Key: '/video/auditing',
1042
+ ContentType: 'application/xml',
1043
+ Body: body
1044
+ },
1045
+ function(err, data){
1046
+ console.log(err || data);
1047
+ });
1048
+ },
1049
+ '查询视频审核任务结果 getVideoAuditingResult': function () {
1050
+ var jobId = 'av5bd873d9f39011ecb6c95254009a49da'; // jobId可以通过提交视频审核任务返回
1051
+ var host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com';
1052
+ var url = 'https://' + host + '/video/auditing/' + jobId;
1053
+ cos.request({
1054
+ Bucket: config.Bucket,
1055
+ Region: config.Region,
1056
+ Method: 'GET',
1057
+ Key: '/video/auditing/' + jobId,
1058
+ Url: url,
1059
+ },
1060
+ function(err, data){
1061
+ console.log(err || data);
1062
+ });
1063
+ },
1064
+ '提交音频审核任务 postAudioAuditing': function () {
1065
+ var host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com';
1066
+ var url = 'https://' + host + '/audio/auditing';
1067
+ var body = COS.util.json2xml({
1068
+ Request: {
1069
+ Input: {
1070
+ Object: '1.mp3',
1071
+ },
1072
+ Conf: {
1073
+ BizType: '',
1074
+ DetectType: 'Porn',
1075
+ }
1076
+ }
1077
+ });
1078
+ cos.request({
1079
+ Bucket: config.Bucket,
1080
+ Region: config.Region,
1081
+ Method: 'POST',
1082
+ Url: url,
1083
+ Key: '/audio/auditing',
1084
+ ContentType: 'application/xml',
1085
+ Body: body
1086
+ },
1087
+ function(err, data){
1088
+ console.log(err || data);
1089
+ });
1090
+ },
1091
+ '查询音频审核任务结果 getAudioAuditingResult': function () {
1092
+ var jobId = 'sa0c28d41daff411ecb23352540078cxxx'; // jobId可以通过提交音频审核任务返回
1093
+ var host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com';
1094
+ var url = 'https://' + host + '/audio/auditing/' + jobId;
1095
+ cos.request({
1096
+ Bucket: config.Bucket,
1097
+ Region: config.Region,
1098
+ Method: 'GET',
1099
+ Key: '/audio/auditing/' + jobId,
1100
+ Url: url,
1101
+ },
1102
+ function(err, data){
1103
+ console.log(err || data);
1104
+ });
1105
+ },
1106
+ '提交文本审核任务 postTextAuditing': function () {
1107
+ var host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com';
1108
+ var url = 'https://' + host + '/text/auditing';
1109
+ var body = COS.util.json2xml({
1110
+ Request: {
1111
+ Input: {
1112
+ // Object: 'hello.txt', // 存在cos里的资源,审核结果异步返回,可以调用查询文本审核结果api查询
1113
+ Content: '5Lmz5rKf', // 经过base64编码过的文本”乳沟“,查询结果同步返回
1114
+ },
1115
+ Conf: {
1116
+ BizType: '',
1117
+ DetectType: 'Porn',
1118
+ }
1119
+ }
1120
+ });
1121
+ cos.request({
1122
+ Bucket: config.Bucket,
1123
+ Region: config.Region,
1124
+ Method: 'POST',
1125
+ Url: url,
1126
+ Key: '/text/auditing',
1127
+ ContentType: 'application/xml',
1128
+ Body: body
1129
+ },
1130
+ function(err, data){
1131
+ console.log(err || data);
1132
+ });
1133
+ },
1134
+ '查询文本审核任务结果 getTextAuditingResult': function () {
1135
+ var jobId = 'st8d88c664aff511ecb23352540078cxxx'; // jobId可以通过提交文本审核任务返回(Input传入Object)
1136
+ var host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com';
1137
+ var url = 'https://' + host + '/text/auditing/' + jobId;
1138
+ cos.request({
1139
+ Bucket: config.Bucket,
1140
+ Region: config.Region,
1141
+ Method: 'GET',
1142
+ Key: '/text/auditing/' + jobId,
1143
+ Url: url,
1144
+ },
1145
+ function(err, data){
1146
+ console.log(err || data);
1147
+ });
1148
+ },
1149
+ '提交文档审核任务 postDocumentAuditing': function () {
1150
+ var host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com';
1151
+ var url = 'https://' + host + '/document/auditing';
1152
+ var body = COS.util.json2xml({
1153
+ Request: {
1154
+ Input: {
1155
+ Object: 'test.xlsx', // 存在cos里的资源,审核结果异步返回,可以调用查询文本审核结果api查询
1156
+ },
1157
+ Conf: {
1158
+ BizType: '',
1159
+ DetectType: 'Porn',
1160
+ }
1161
+ }
1162
+ });
1163
+ cos.request({
1164
+ Bucket: config.Bucket,
1165
+ Region: config.Region,
1166
+ Method: 'POST',
1167
+ Url: url,
1168
+ Key: '/document/auditing',
1169
+ ContentType: 'application/xml',
1170
+ Body: body
1171
+ },
1172
+ function(err, data){
1173
+ console.log(err || data);
1174
+ });
1175
+ },
1176
+ '查询文档审核任务结果 getDocumentAuditingResult': function () {
1177
+ var jobId = 'sd7815c21caff611eca12f525400d88560'; // jobId可以通过提交文档审核任务返回
1178
+ var host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com';
1179
+ var url = 'https://' + host + '/document/auditing/' + jobId;
1180
+ cos.request({
1181
+ Bucket: config.Bucket,
1182
+ Region: config.Region,
1183
+ Method: 'GET',
1184
+ Key: '/document/auditing/' + jobId,
1185
+ Url: url,
1186
+ },
1187
+ function(err, data){
1188
+ console.log(err || data);
1189
+ });
1190
+ },
1191
+ '提交网页审核任务 postWebpageAuditing': function () {
1192
+ var host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com';
1193
+ var url = 'https://' + host + '/webpage/auditing';
1194
+ var body = COS.util.json2xml({
1195
+ Request: {
1196
+ Input: {
1197
+ Url: 'https://cloud.tencent.com/', // 存在cos里的资源,审核结果异步返回,可以调用查询文本审核结果api查询
1198
+ },
1199
+ Conf: {
1200
+ BizType: '',
1201
+ DetectType: 'Porn,Ads',
1202
+ }
1203
+ }
1204
+ });
1205
+ cos.request({
1206
+ Bucket: config.Bucket,
1207
+ Region: config.Region,
1208
+ Method: 'POST',
1209
+ Url: url,
1210
+ Key: '/webpage/auditing',
1211
+ ContentType: 'application/xml',
1212
+ Body: body
1213
+ },
1214
+ function(err, data){
1215
+ console.log(err || data);
1216
+ });
1217
+ },
1218
+ '查询网页审核任务结果 getWebpageAuditingResult': function () {
1219
+ var jobId = 'shce868019aff611ecb1155254009a4xxx'; // jobId可以通过提交网页审核任务返回
1220
+ var host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com';
1221
+ var url = 'https://' + host + '/webpage/auditing/' + jobId;
1222
+ cos.request({
1223
+ Bucket: config.Bucket,
1224
+ Region: config.Region,
1225
+ Method: 'GET',
1226
+ Key: '/webpage/auditing/' + jobId,
1227
+ Url: url,
1228
+ },
1229
+ function(err, data){
1230
+ console.log(err || data);
1231
+ });
1232
+ },
950
1233
  }
951
1234
 
952
1235
  // require('./test');
@@ -646,6 +646,32 @@ var isCIHost = function isCIHost(url) {
646
646
  );
647
647
  };
648
648
 
649
+ var error = function error(err, opt) {
650
+ var sourceErr = err;
651
+ err.message = err.message || null;
652
+
653
+ if (typeof opt === 'string') {
654
+ err.error = opt;
655
+ err.message = opt;
656
+ } else if ((typeof opt === 'undefined' ? 'undefined' : _typeof(opt)) === 'object' && opt !== null) {
657
+ extend(err, opt);
658
+ if (opt.code || opt.name) err.code = opt.code || opt.name;
659
+ if (opt.message) err.message = opt.message;
660
+ if (opt.stack) err.stack = opt.stack;
661
+ }
662
+
663
+ if (typeof Object.defineProperty === 'function') {
664
+ Object.defineProperty(err, 'name', { writable: true, enumerable: false });
665
+ Object.defineProperty(err, 'message', { enumerable: true });
666
+ }
667
+
668
+ err.name = opt && opt.name || err.name || err.code || 'Error';
669
+ if (!err.code) err.code = err.name;
670
+ if (!err.error) err.error = clone(sourceErr); // 兼容老的错误格式
671
+
672
+ return err;
673
+ };
674
+
649
675
  var util = {
650
676
  noop: noop,
651
677
  formatParams: formatParams,
@@ -676,7 +702,8 @@ var util = {
676
702
  getAuth: getAuth,
677
703
  compareVersion: compareVersion,
678
704
  canFileSlice: canFileSlice,
679
- isCIHost: isCIHost
705
+ isCIHost: isCIHost,
706
+ error: error
680
707
  };
681
708
 
682
709
  module.exports = util;
@@ -2722,7 +2749,7 @@ var advance = __webpack_require__(27);
2722
2749
  var defaultOptions = {
2723
2750
  SecretId: '',
2724
2751
  SecretKey: '',
2725
- XCosSecurityToken: '', // 使用临时密钥需要注意自行刷新 Token
2752
+ SecurityToken: '', // 使用临时密钥需要注意自行刷新 Token
2726
2753
  ChunkRetryTimes: 2,
2727
2754
  FileParallelLimit: 3,
2728
2755
  ChunkParallelLimit: 3,
@@ -2784,7 +2811,7 @@ COS.util = {
2784
2811
  json2xml: util.json2xml
2785
2812
  };
2786
2813
  COS.getAuthorization = util.getAuth;
2787
- COS.version = '1.1.8';
2814
+ COS.version = '1.2.0';
2788
2815
 
2789
2816
  module.exports = COS;
2790
2817
 
@@ -8152,6 +8179,7 @@ function postObject(params, callback) {
8152
8179
  headers: headers,
8153
8180
  qs: params.Query,
8154
8181
  filePath: filePath,
8182
+ TaskId: params.TaskId,
8155
8183
  onProgress: onProgress
8156
8184
  }, function (err, data) {
8157
8185
  onProgress(null, true);
@@ -9164,7 +9192,7 @@ function getObjectUrl(params, callback) {
9164
9192
 
9165
9193
  var signUrl = url;
9166
9194
  signUrl += '?' + (AuthData.Authorization.indexOf('q-signature') > -1 ? replaceUrlParamList(AuthData.Authorization) : 'sign=' + encodeURIComponent(AuthData.Authorization));
9167
- AuthData.XCosSecurityToken && (signUrl += '&x-cos-security-token=' + AuthData.XCosSecurityToken);
9195
+ AuthData.SecurityToken && (signUrl += '&x-cos-security-token=' + AuthData.SecurityToken);
9168
9196
  AuthData.ClientIP && (signUrl += '&clientIP=' + AuthData.ClientIP);
9169
9197
  AuthData.ClientUA && (signUrl += '&clientUA=' + AuthData.ClientUA);
9170
9198
  AuthData.Token && (signUrl += '&token=' + AuthData.Token);
@@ -9175,7 +9203,7 @@ function getObjectUrl(params, callback) {
9175
9203
  });
9176
9204
 
9177
9205
  if (AuthData) {
9178
- syncUrl += '?' + AuthData.Authorization + (AuthData.XCosSecurityToken ? '&x-cos-security-token=' + AuthData.XCosSecurityToken : '');
9206
+ syncUrl += '?' + AuthData.Authorization + (AuthData.SecurityToken ? '&x-cos-security-token=' + AuthData.SecurityToken : '');
9179
9207
  queryParamsStr && (syncUrl += '&' + queryParamsStr);
9180
9208
  } else {
9181
9209
  queryParamsStr && (syncUrl += '?' + queryParamsStr);
@@ -9309,7 +9337,6 @@ var getSignHost = function getSignHost(opt) {
9309
9337
 
9310
9338
  // 异步获取签名
9311
9339
  function getAuthorizationAsync(params, callback) {
9312
-
9313
9340
  var headers = util.clone(params.Headers);
9314
9341
  var headerHost = '';
9315
9342
  util.each(headers, function (v, k) {
@@ -9322,30 +9349,17 @@ function getAuthorizationAsync(params, callback) {
9322
9349
  // Host 加入签名计算
9323
9350
  if (!headerHost && params.SignHost && forceSignHost) headers.Host = params.SignHost;
9324
9351
 
9325
- var cb = function cb(AuthData) {
9326
-
9327
- // 检查签名格式
9328
- var formatAllow = false;
9329
- var auth = AuthData.Authorization;
9330
- if (auth) {
9331
- if (auth.indexOf(' ') > -1) {
9332
- formatAllow = false;
9333
- } else if (auth.indexOf('q-sign-algorithm=') > -1 && auth.indexOf('q-ak=') > -1 && auth.indexOf('q-sign-time=') > -1 && auth.indexOf('q-key-time=') > -1 && auth.indexOf('q-url-param-list=') > -1) {
9334
- formatAllow = true;
9335
- } else {
9336
- try {
9337
- auth = base64.atob(auth);
9338
- if (auth.indexOf('a=') > -1 && auth.indexOf('k=') > -1 && auth.indexOf('t=') > -1 && auth.indexOf('r=') > -1 && auth.indexOf('b=') > -1) {
9339
- formatAllow = true;
9340
- }
9341
- } catch (e) {}
9342
- }
9343
- }
9344
- if (formatAllow) {
9345
- callback && callback(null, AuthData);
9346
- } else {
9347
- callback && callback('authorization error');
9348
- }
9352
+ // 获取凭证的回调,避免用户 callback 多次
9353
+ var cbDone = false;
9354
+ var cb = function cb(err, AuthData) {
9355
+ if (cbDone) return;
9356
+ cbDone = true;
9357
+ if (AuthData && AuthData.XCosSecurityToken && !AuthData.SecurityToken) {
9358
+ AuthData = util.clone(AuthData);
9359
+ AuthData.SecurityToken = AuthData.XCosSecurityToken;
9360
+ delete AuthData.XCosSecurityToken;
9361
+ }
9362
+ callback && callback(err, AuthData);
9349
9363
  };
9350
9364
 
9351
9365
  var self = this;
@@ -9413,12 +9427,43 @@ function getAuthorizationAsync(params, callback) {
9413
9427
  });
9414
9428
  var AuthData = {
9415
9429
  Authorization: Authorization,
9416
- XCosSecurityToken: StsData.XCosSecurityToken || '',
9430
+ SecurityToken: StsData.SecurityToken || StsData.XCosSecurityToken || '',
9417
9431
  Token: StsData.Token || '',
9418
9432
  ClientIP: StsData.ClientIP || '',
9419
9433
  ClientUA: StsData.ClientUA || ''
9420
9434
  };
9421
- cb(AuthData);
9435
+ cb(null, AuthData);
9436
+ };
9437
+
9438
+ var checkAuthError = function checkAuthError(AuthData) {
9439
+ if (AuthData.Authorization) {
9440
+ // 检查签名格式
9441
+ var formatAllow = false;
9442
+ var auth = AuthData.Authorization;
9443
+ if (auth) {
9444
+ if (auth.indexOf(' ') > -1) {
9445
+ formatAllow = false;
9446
+ } else if (auth.indexOf('q-sign-algorithm=') > -1 && auth.indexOf('q-ak=') > -1 && auth.indexOf('q-sign-time=') > -1 && auth.indexOf('q-key-time=') > -1 && auth.indexOf('q-url-param-list=') > -1) {
9447
+ formatAllow = true;
9448
+ } else {
9449
+ try {
9450
+ auth = atob(auth);
9451
+ if (auth.indexOf('a=') > -1 && auth.indexOf('k=') > -1 && auth.indexOf('t=') > -1 && auth.indexOf('r=') > -1 && auth.indexOf('b=') > -1) {
9452
+ formatAllow = true;
9453
+ }
9454
+ } catch (e) {}
9455
+ }
9456
+ }
9457
+ if (!formatAllow) return util.error(new Error('getAuthorization callback params format error'));
9458
+ } else {
9459
+ if (!AuthData.TmpSecretId) return util.error(new Error('getAuthorization callback params missing "TmpSecretId"'));
9460
+ if (!AuthData.TmpSecretKey) return util.error(new Error('getAuthorization callback params missing "TmpSecretKey"'));
9461
+ if (!AuthData.SecurityToken && !AuthData.XCosSecurityToken) return util.error(new Error('getAuthorization callback params missing "SecurityToken"'));
9462
+ if (!AuthData.ExpiredTime) return util.error(new Error('getAuthorization callback params missing "ExpiredTime"'));
9463
+ if (AuthData.ExpiredTime && AuthData.ExpiredTime.toString().length !== 10) return util.error(new Error('getAuthorization callback params "ExpiredTime" should be 10 digits'));
9464
+ if (AuthData.StartTime && AuthData.StartTime.toString().length !== 10) return util.error(new Error('getAuthorization callback params "StartTime" should be 10 StartTime'));
9465
+ }
9466
+ return false;
9422
9467
  };
9423
9468
 
9424
9469
  // 先判断是否有临时密钥
@@ -9442,14 +9487,16 @@ function getAuthorizationAsync(params, callback) {
9442
9487
  if (typeof AuthData === 'string') {
9443
9488
  AuthData = { Authorization: AuthData };
9444
9489
  }
9445
- if (AuthData.TmpSecretId && AuthData.TmpSecretKey && AuthData.XCosSecurityToken && AuthData.ExpiredTime) {
9490
+ var AuthError = checkAuthError(AuthData);
9491
+ if (AuthError) return cb(AuthError);
9492
+ if (AuthData.Authorization) {
9493
+ cb(null, AuthData);
9494
+ } else {
9446
9495
  StsData = AuthData || {};
9447
9496
  StsData.Scope = Scope;
9448
9497
  StsData.ScopeKey = ScopeKey;
9449
9498
  self._StsCache.push(StsData);
9450
9499
  calcAuthByTmpKey();
9451
- } else {
9452
- cb(AuthData);
9453
9500
  }
9454
9501
  });
9455
9502
  } else if (self.options.getSTS) {
@@ -9461,8 +9508,10 @@ function getAuthorizationAsync(params, callback) {
9461
9508
  StsData = data || {};
9462
9509
  StsData.Scope = Scope;
9463
9510
  StsData.ScopeKey = ScopeKey;
9464
- StsData.TmpSecretId = StsData.SecretId;
9465
- StsData.TmpSecretKey = StsData.SecretKey;
9511
+ if (!StsData.TmpSecretId) StsData.TmpSecretId = StsData.SecretId;
9512
+ if (!StsData.TmpSecretKey) StsData.TmpSecretKey = StsData.SecretKey;
9513
+ var AuthError = checkAuthError(StsData);
9514
+ if (AuthError) return cb(AuthError);
9466
9515
  self._StsCache.push(StsData);
9467
9516
  calcAuthByTmpKey();
9468
9517
  });
@@ -9482,9 +9531,9 @@ function getAuthorizationAsync(params, callback) {
9482
9531
  });
9483
9532
  var AuthData = {
9484
9533
  Authorization: Authorization,
9485
- XCosSecurityToken: self.options.XCosSecurityToken
9534
+ SecurityToken: self.options.SecurityToken || self.options.XCosSecurityToken
9486
9535
  };
9487
- cb(AuthData);
9536
+ cb(null, AuthData);
9488
9537
  return AuthData;
9489
9538
  }();
9490
9539
  }
@@ -9637,7 +9686,7 @@ function _submitRequest(params, callback) {
9637
9686
  params.AuthData.Token && (opt.headers['token'] = params.AuthData.Token);
9638
9687
  params.AuthData.ClientIP && (opt.headers['clientIP'] = params.AuthData.ClientIP);
9639
9688
  params.AuthData.ClientUA && (opt.headers['clientUA'] = params.AuthData.ClientUA);
9640
- params.AuthData.XCosSecurityToken && (opt.headers[token] = params.AuthData.XCosSecurityToken);
9689
+ params.AuthData.SecurityToken && (opt.headers[token] = params.AuthData.SecurityToken);
9641
9690
 
9642
9691
  // 清理 undefined 和 null 字段
9643
9692
  opt.headers && (opt.headers = util.clearKey(opt.headers));