cos-wx-sdk-v5 1.1.7 → 1.2.1
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 +287 -3
- package/demo/lib/cos-wx-sdk-v5.js +116 -46
- package/demo/lib/cos-wx-sdk-v5.min.js +1 -1
- package/demo/project.config.json +1 -1
- package/demo-album/lib/cos-wx-sdk-v5.js +116 -46
- package/demo-album/lib/cos-wx-sdk-v5.min.js +1 -1
- package/lib/request.js +10 -2
- package/package.json +1 -1
- package/src/base.js +81 -50
- package/src/cos.js +3 -2
- package/src/util.js +27 -0
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
|
-
|
|
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;
|
|
@@ -402,6 +406,7 @@ var bucketDao = {
|
|
|
402
406
|
cos.putBucketCors({
|
|
403
407
|
Bucket: config.Bucket,
|
|
404
408
|
Region: config.Region,
|
|
409
|
+
ResponseVary: "true",
|
|
405
410
|
CORSRules: [{
|
|
406
411
|
"AllowedOrigin": ["*"],
|
|
407
412
|
"AllowedMethod": ["GET", "POST", "PUT", "DELETE", "HEAD"],
|
|
@@ -680,7 +685,7 @@ var objectDao = {
|
|
|
680
685
|
Position: 0,
|
|
681
686
|
},
|
|
682
687
|
function(err, data) {
|
|
683
|
-
|
|
688
|
+
console.log('putObject:', err || data);
|
|
684
689
|
})
|
|
685
690
|
},
|
|
686
691
|
'appendObject_continue 继续追加上传': function() {
|
|
@@ -703,7 +708,7 @@ var objectDao = {
|
|
|
703
708
|
function(err, data) {
|
|
704
709
|
// 也可以取到下一次上传的position继续追加上传
|
|
705
710
|
// var nextPosition = data.headers['x-cos-next-append-position'];
|
|
706
|
-
|
|
711
|
+
console.log('putObject:', err || data);
|
|
707
712
|
})
|
|
708
713
|
});
|
|
709
714
|
},
|
|
@@ -946,6 +951,285 @@ var ciObjectDao = {
|
|
|
946
951
|
console.log(err || data);
|
|
947
952
|
});
|
|
948
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
|
+
},
|
|
949
1233
|
}
|
|
950
1234
|
|
|
951
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
|
-
|
|
2752
|
+
SecurityToken: '', // 使用临时密钥需要注意自行刷新 Token
|
|
2726
2753
|
ChunkRetryTimes: 2,
|
|
2727
2754
|
FileParallelLimit: 3,
|
|
2728
2755
|
ChunkParallelLimit: 3,
|
|
@@ -2745,7 +2772,8 @@ var defaultOptions = {
|
|
|
2745
2772
|
UploadCheckContentMd5: false,
|
|
2746
2773
|
UploadIdCacheLimit: 50,
|
|
2747
2774
|
UseAccelerate: false,
|
|
2748
|
-
ForceSignHost: true // 默认将host加入签名计算,关闭后可能导致越权风险,建议保持为true
|
|
2775
|
+
ForceSignHost: true, // 默认将host加入签名计算,关闭后可能导致越权风险,建议保持为true
|
|
2776
|
+
HttpDNSServiceId: '' // HttpDNS 服务商 Id,填写后代表开启 HttpDNS 服务。HttpDNS 用法详见https://developers.weixin.qq.com/miniprogram/dev/framework/ability/HTTPDNS.html
|
|
2749
2777
|
};
|
|
2750
2778
|
|
|
2751
2779
|
// 对外暴露的类
|
|
@@ -2784,7 +2812,7 @@ COS.util = {
|
|
|
2784
2812
|
json2xml: util.json2xml
|
|
2785
2813
|
};
|
|
2786
2814
|
COS.getAuthorization = util.getAuth;
|
|
2787
|
-
COS.version = '1.1
|
|
2815
|
+
COS.version = '1.2.1';
|
|
2788
2816
|
|
|
2789
2817
|
module.exports = COS;
|
|
2790
2818
|
|
|
@@ -6524,7 +6552,10 @@ function putBucketCors(params, callback) {
|
|
|
6524
6552
|
});
|
|
6525
6553
|
});
|
|
6526
6554
|
|
|
6527
|
-
var
|
|
6555
|
+
var Conf = { CORSRule: CORSRules };
|
|
6556
|
+
if (params.ResponseVary) Conf.ResponseVary = params.ResponseVary;
|
|
6557
|
+
|
|
6558
|
+
var xml = util.json2xml({ CORSConfiguration: Conf });
|
|
6528
6559
|
|
|
6529
6560
|
var headers = params.Headers;
|
|
6530
6561
|
headers['Content-Type'] = 'application/xml';
|
|
@@ -6582,6 +6613,7 @@ function getBucketCors(params, callback) {
|
|
|
6582
6613
|
var CORSConfiguration = data.CORSConfiguration || {};
|
|
6583
6614
|
var CORSRules = CORSConfiguration.CORSRules || CORSConfiguration.CORSRule || [];
|
|
6584
6615
|
CORSRules = util.clone(util.isArray(CORSRules) ? CORSRules : [CORSRules]);
|
|
6616
|
+
var ResponseVary = CORSConfiguration.ResponseVary;
|
|
6585
6617
|
|
|
6586
6618
|
util.each(CORSRules, function (rule) {
|
|
6587
6619
|
util.each(['AllowedOrigin', 'AllowedHeader', 'AllowedMethod', 'ExposeHeader'], function (key) {
|
|
@@ -6594,6 +6626,7 @@ function getBucketCors(params, callback) {
|
|
|
6594
6626
|
|
|
6595
6627
|
callback(null, {
|
|
6596
6628
|
CORSRules: CORSRules,
|
|
6629
|
+
ResponseVary: ResponseVary,
|
|
6597
6630
|
statusCode: data.statusCode,
|
|
6598
6631
|
headers: data.headers
|
|
6599
6632
|
});
|
|
@@ -8147,6 +8180,7 @@ function postObject(params, callback) {
|
|
|
8147
8180
|
headers: headers,
|
|
8148
8181
|
qs: params.Query,
|
|
8149
8182
|
filePath: filePath,
|
|
8183
|
+
TaskId: params.TaskId,
|
|
8150
8184
|
onProgress: onProgress
|
|
8151
8185
|
}, function (err, data) {
|
|
8152
8186
|
onProgress(null, true);
|
|
@@ -9159,7 +9193,7 @@ function getObjectUrl(params, callback) {
|
|
|
9159
9193
|
|
|
9160
9194
|
var signUrl = url;
|
|
9161
9195
|
signUrl += '?' + (AuthData.Authorization.indexOf('q-signature') > -1 ? replaceUrlParamList(AuthData.Authorization) : 'sign=' + encodeURIComponent(AuthData.Authorization));
|
|
9162
|
-
AuthData.
|
|
9196
|
+
AuthData.SecurityToken && (signUrl += '&x-cos-security-token=' + AuthData.SecurityToken);
|
|
9163
9197
|
AuthData.ClientIP && (signUrl += '&clientIP=' + AuthData.ClientIP);
|
|
9164
9198
|
AuthData.ClientUA && (signUrl += '&clientUA=' + AuthData.ClientUA);
|
|
9165
9199
|
AuthData.Token && (signUrl += '&token=' + AuthData.Token);
|
|
@@ -9170,7 +9204,7 @@ function getObjectUrl(params, callback) {
|
|
|
9170
9204
|
});
|
|
9171
9205
|
|
|
9172
9206
|
if (AuthData) {
|
|
9173
|
-
syncUrl += '?' + AuthData.Authorization + (AuthData.
|
|
9207
|
+
syncUrl += '?' + AuthData.Authorization + (AuthData.SecurityToken ? '&x-cos-security-token=' + AuthData.SecurityToken : '');
|
|
9174
9208
|
queryParamsStr && (syncUrl += '&' + queryParamsStr);
|
|
9175
9209
|
} else {
|
|
9176
9210
|
queryParamsStr && (syncUrl += '?' + queryParamsStr);
|
|
@@ -9304,7 +9338,6 @@ var getSignHost = function getSignHost(opt) {
|
|
|
9304
9338
|
|
|
9305
9339
|
// 异步获取签名
|
|
9306
9340
|
function getAuthorizationAsync(params, callback) {
|
|
9307
|
-
|
|
9308
9341
|
var headers = util.clone(params.Headers);
|
|
9309
9342
|
var headerHost = '';
|
|
9310
9343
|
util.each(headers, function (v, k) {
|
|
@@ -9317,30 +9350,17 @@ function getAuthorizationAsync(params, callback) {
|
|
|
9317
9350
|
// Host 加入签名计算
|
|
9318
9351
|
if (!headerHost && params.SignHost && forceSignHost) headers.Host = params.SignHost;
|
|
9319
9352
|
|
|
9320
|
-
|
|
9321
|
-
|
|
9322
|
-
|
|
9323
|
-
|
|
9324
|
-
|
|
9325
|
-
if (
|
|
9326
|
-
|
|
9327
|
-
|
|
9328
|
-
|
|
9329
|
-
|
|
9330
|
-
|
|
9331
|
-
try {
|
|
9332
|
-
auth = base64.atob(auth);
|
|
9333
|
-
if (auth.indexOf('a=') > -1 && auth.indexOf('k=') > -1 && auth.indexOf('t=') > -1 && auth.indexOf('r=') > -1 && auth.indexOf('b=') > -1) {
|
|
9334
|
-
formatAllow = true;
|
|
9335
|
-
}
|
|
9336
|
-
} catch (e) {}
|
|
9337
|
-
}
|
|
9338
|
-
}
|
|
9339
|
-
if (formatAllow) {
|
|
9340
|
-
callback && callback(null, AuthData);
|
|
9341
|
-
} else {
|
|
9342
|
-
callback && callback('authorization error');
|
|
9343
|
-
}
|
|
9353
|
+
// 获取凭证的回调,避免用户 callback 多次
|
|
9354
|
+
var cbDone = false;
|
|
9355
|
+
var cb = function cb(err, AuthData) {
|
|
9356
|
+
if (cbDone) return;
|
|
9357
|
+
cbDone = true;
|
|
9358
|
+
if (AuthData && AuthData.XCosSecurityToken && !AuthData.SecurityToken) {
|
|
9359
|
+
AuthData = util.clone(AuthData);
|
|
9360
|
+
AuthData.SecurityToken = AuthData.XCosSecurityToken;
|
|
9361
|
+
delete AuthData.XCosSecurityToken;
|
|
9362
|
+
}
|
|
9363
|
+
callback && callback(err, AuthData);
|
|
9344
9364
|
};
|
|
9345
9365
|
|
|
9346
9366
|
var self = this;
|
|
@@ -9388,7 +9408,12 @@ function getAuthorizationAsync(params, callback) {
|
|
|
9388
9408
|
})();
|
|
9389
9409
|
|
|
9390
9410
|
var calcAuthByTmpKey = function calcAuthByTmpKey() {
|
|
9391
|
-
var KeyTime =
|
|
9411
|
+
var KeyTime = '';
|
|
9412
|
+
if (StsData.StartTime && params.Expires) {
|
|
9413
|
+
KeyTime = StsData.StartTime + ';' + (StsData.StartTime + params.Expires * 1);
|
|
9414
|
+
} else if (StsData.StartTime && StsData.ExpiredTime) {
|
|
9415
|
+
KeyTime = StsData.StartTime + ';' + StsData.ExpiredTime;
|
|
9416
|
+
}
|
|
9392
9417
|
var Authorization = util.getAuth({
|
|
9393
9418
|
SecretId: StsData.TmpSecretId,
|
|
9394
9419
|
SecretKey: StsData.TmpSecretKey,
|
|
@@ -9403,12 +9428,43 @@ function getAuthorizationAsync(params, callback) {
|
|
|
9403
9428
|
});
|
|
9404
9429
|
var AuthData = {
|
|
9405
9430
|
Authorization: Authorization,
|
|
9406
|
-
|
|
9431
|
+
SecurityToken: StsData.SecurityToken || StsData.XCosSecurityToken || '',
|
|
9407
9432
|
Token: StsData.Token || '',
|
|
9408
9433
|
ClientIP: StsData.ClientIP || '',
|
|
9409
9434
|
ClientUA: StsData.ClientUA || ''
|
|
9410
9435
|
};
|
|
9411
|
-
cb(AuthData);
|
|
9436
|
+
cb(null, AuthData);
|
|
9437
|
+
};
|
|
9438
|
+
|
|
9439
|
+
var checkAuthError = function checkAuthError(AuthData) {
|
|
9440
|
+
if (AuthData.Authorization) {
|
|
9441
|
+
// 检查签名格式
|
|
9442
|
+
var formatAllow = false;
|
|
9443
|
+
var auth = AuthData.Authorization;
|
|
9444
|
+
if (auth) {
|
|
9445
|
+
if (auth.indexOf(' ') > -1) {
|
|
9446
|
+
formatAllow = false;
|
|
9447
|
+
} 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) {
|
|
9448
|
+
formatAllow = true;
|
|
9449
|
+
} else {
|
|
9450
|
+
try {
|
|
9451
|
+
auth = atob(auth);
|
|
9452
|
+
if (auth.indexOf('a=') > -1 && auth.indexOf('k=') > -1 && auth.indexOf('t=') > -1 && auth.indexOf('r=') > -1 && auth.indexOf('b=') > -1) {
|
|
9453
|
+
formatAllow = true;
|
|
9454
|
+
}
|
|
9455
|
+
} catch (e) {}
|
|
9456
|
+
}
|
|
9457
|
+
}
|
|
9458
|
+
if (!formatAllow) return util.error(new Error('getAuthorization callback params format error'));
|
|
9459
|
+
} else {
|
|
9460
|
+
if (!AuthData.TmpSecretId) return util.error(new Error('getAuthorization callback params missing "TmpSecretId"'));
|
|
9461
|
+
if (!AuthData.TmpSecretKey) return util.error(new Error('getAuthorization callback params missing "TmpSecretKey"'));
|
|
9462
|
+
if (!AuthData.SecurityToken && !AuthData.XCosSecurityToken) return util.error(new Error('getAuthorization callback params missing "SecurityToken"'));
|
|
9463
|
+
if (!AuthData.ExpiredTime) return util.error(new Error('getAuthorization callback params missing "ExpiredTime"'));
|
|
9464
|
+
if (AuthData.ExpiredTime && AuthData.ExpiredTime.toString().length !== 10) return util.error(new Error('getAuthorization callback params "ExpiredTime" should be 10 digits'));
|
|
9465
|
+
if (AuthData.StartTime && AuthData.StartTime.toString().length !== 10) return util.error(new Error('getAuthorization callback params "StartTime" should be 10 StartTime'));
|
|
9466
|
+
}
|
|
9467
|
+
return false;
|
|
9412
9468
|
};
|
|
9413
9469
|
|
|
9414
9470
|
// 先判断是否有临时密钥
|
|
@@ -9432,14 +9488,16 @@ function getAuthorizationAsync(params, callback) {
|
|
|
9432
9488
|
if (typeof AuthData === 'string') {
|
|
9433
9489
|
AuthData = { Authorization: AuthData };
|
|
9434
9490
|
}
|
|
9435
|
-
|
|
9491
|
+
var AuthError = checkAuthError(AuthData);
|
|
9492
|
+
if (AuthError) return cb(AuthError);
|
|
9493
|
+
if (AuthData.Authorization) {
|
|
9494
|
+
cb(null, AuthData);
|
|
9495
|
+
} else {
|
|
9436
9496
|
StsData = AuthData || {};
|
|
9437
9497
|
StsData.Scope = Scope;
|
|
9438
9498
|
StsData.ScopeKey = ScopeKey;
|
|
9439
9499
|
self._StsCache.push(StsData);
|
|
9440
9500
|
calcAuthByTmpKey();
|
|
9441
|
-
} else {
|
|
9442
|
-
cb(AuthData);
|
|
9443
9501
|
}
|
|
9444
9502
|
});
|
|
9445
9503
|
} else if (self.options.getSTS) {
|
|
@@ -9451,8 +9509,10 @@ function getAuthorizationAsync(params, callback) {
|
|
|
9451
9509
|
StsData = data || {};
|
|
9452
9510
|
StsData.Scope = Scope;
|
|
9453
9511
|
StsData.ScopeKey = ScopeKey;
|
|
9454
|
-
StsData.TmpSecretId = StsData.SecretId;
|
|
9455
|
-
StsData.TmpSecretKey = StsData.SecretKey;
|
|
9512
|
+
if (!StsData.TmpSecretId) StsData.TmpSecretId = StsData.SecretId;
|
|
9513
|
+
if (!StsData.TmpSecretKey) StsData.TmpSecretKey = StsData.SecretKey;
|
|
9514
|
+
var AuthError = checkAuthError(StsData);
|
|
9515
|
+
if (AuthError) return cb(AuthError);
|
|
9456
9516
|
self._StsCache.push(StsData);
|
|
9457
9517
|
calcAuthByTmpKey();
|
|
9458
9518
|
});
|
|
@@ -9472,9 +9532,9 @@ function getAuthorizationAsync(params, callback) {
|
|
|
9472
9532
|
});
|
|
9473
9533
|
var AuthData = {
|
|
9474
9534
|
Authorization: Authorization,
|
|
9475
|
-
|
|
9535
|
+
SecurityToken: self.options.SecurityToken || self.options.XCosSecurityToken
|
|
9476
9536
|
};
|
|
9477
|
-
cb(AuthData);
|
|
9537
|
+
cb(null, AuthData);
|
|
9478
9538
|
return AuthData;
|
|
9479
9539
|
}();
|
|
9480
9540
|
}
|
|
@@ -9582,6 +9642,7 @@ function _submitRequest(params, callback) {
|
|
|
9582
9642
|
var body = params.body;
|
|
9583
9643
|
var json = params.json;
|
|
9584
9644
|
var rawBody = params.rawBody;
|
|
9645
|
+
var httpDNSServiceId = self.options.HttpDNSServiceId;
|
|
9585
9646
|
|
|
9586
9647
|
// url
|
|
9587
9648
|
if (self.options.UseAccelerate) {
|
|
@@ -9613,7 +9674,8 @@ function _submitRequest(params, callback) {
|
|
|
9613
9674
|
qs: params.qs,
|
|
9614
9675
|
filePath: params.filePath,
|
|
9615
9676
|
body: body,
|
|
9616
|
-
json: json
|
|
9677
|
+
json: json,
|
|
9678
|
+
httpDNSServiceId: httpDNSServiceId
|
|
9617
9679
|
};
|
|
9618
9680
|
|
|
9619
9681
|
// 兼容ci接口
|
|
@@ -9627,7 +9689,7 @@ function _submitRequest(params, callback) {
|
|
|
9627
9689
|
params.AuthData.Token && (opt.headers['token'] = params.AuthData.Token);
|
|
9628
9690
|
params.AuthData.ClientIP && (opt.headers['clientIP'] = params.AuthData.ClientIP);
|
|
9629
9691
|
params.AuthData.ClientUA && (opt.headers['clientUA'] = params.AuthData.ClientUA);
|
|
9630
|
-
params.AuthData.
|
|
9692
|
+
params.AuthData.SecurityToken && (opt.headers[token] = params.AuthData.SecurityToken);
|
|
9631
9693
|
|
|
9632
9694
|
// 清理 undefined 和 null 字段
|
|
9633
9695
|
opt.headers && (opt.headers = util.clearKey(opt.headers));
|
|
@@ -9847,6 +9909,7 @@ var request = function request(params, callback) {
|
|
|
9847
9909
|
var url = params.url || params.Url;
|
|
9848
9910
|
var method = params.method;
|
|
9849
9911
|
var onProgress = params.onProgress;
|
|
9912
|
+
var httpDNSServiceId = params.httpDNSServiceId;
|
|
9850
9913
|
var requestTask;
|
|
9851
9914
|
|
|
9852
9915
|
var cb = function cb(err, response) {
|
|
@@ -9912,7 +9975,7 @@ var request = function request(params, callback) {
|
|
|
9912
9975
|
url += (url.indexOf('?') > -1 ? '&' : '?') + qsStr;
|
|
9913
9976
|
}
|
|
9914
9977
|
headers['Content-Length'] && delete headers['Content-Length'];
|
|
9915
|
-
|
|
9978
|
+
var requestParams = {
|
|
9916
9979
|
url: url,
|
|
9917
9980
|
method: method,
|
|
9918
9981
|
header: headers,
|
|
@@ -9925,7 +9988,14 @@ var request = function request(params, callback) {
|
|
|
9925
9988
|
fail: function fail(response) {
|
|
9926
9989
|
cb(response.errMsg, response);
|
|
9927
9990
|
}
|
|
9928
|
-
}
|
|
9991
|
+
};
|
|
9992
|
+
if (httpDNSServiceId) {
|
|
9993
|
+
Object.assign(requestParams, {
|
|
9994
|
+
enableHttpDNS: true,
|
|
9995
|
+
httpDNSServiceId: httpDNSServiceId
|
|
9996
|
+
});
|
|
9997
|
+
}
|
|
9998
|
+
requestTask = wx.request(requestParams);
|
|
9929
9999
|
}
|
|
9930
10000
|
|
|
9931
10001
|
return requestTask;
|