cos-wx-sdk-v5 1.7.2 → 1.8.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-album/lib → dist}/cos-wx-sdk-v5.js +159 -88
- package/dist/cos-wx-sdk-v5.min.js +1 -0
- package/package.json +6 -4
- package/scripts/patch-check.js +14 -0
- package/src/base.js +14 -12
- package/src/tracker.js +26 -46
- package/src/util.js +44 -7
- package/.babelrc +0 -3
- package/.github/workflows/auto-changelog.yml +0 -55
- package/.prettierrc +0 -10
- package/CHANGELOG.md +0 -615
- package/build.js +0 -130
- package/demo/app.js +0 -30
- package/demo/app.json +0 -12
- package/demo/app.wxss +0 -10
- package/demo/ciDemo/asr.js +0 -255
- package/demo/ciDemo/audit.js +0 -271
- package/demo/ciDemo/docPreview.js +0 -379
- package/demo/ciDemo/fileProcess.js +0 -506
- package/demo/ciDemo/mediaProcess.js +0 -83
- package/demo/ciDemo/meta.js +0 -683
- package/demo/ciDemo/other.js +0 -101
- package/demo/ciDemo/picProcess.js +0 -1455
- package/demo/config.js +0 -5
- package/demo/demo-ci.js +0 -19
- package/demo/demo-post-policy.js +0 -92
- package/demo/demo-sdk.js +0 -628
- package/demo/lib/beacon_mp.min.js +0 -2
- package/demo/lib/cls.min.js +0 -25
- package/demo/lib/cos-auth.js +0 -1
- package/demo/lib/cos-wx-sdk-v5.js +0 -11083
- package/demo/lib/cos-wx-sdk-v5.min.js +0 -1
- package/demo/pages/index/index.js +0 -64
- package/demo/pages/index/index.json +0 -1
- package/demo/pages/index/index.wxml +0 -30
- package/demo/pages/index/index.wxss +0 -52
- package/demo/project.config.json +0 -59
- package/demo/sitemap.json +0 -7
- package/demo/test.js +0 -3607
- package/demo/tools.js +0 -131
- package/demo-album/app.js +0 -1
- package/demo-album/app.json +0 -14
- package/demo-album/app.wxss +0 -8
- package/demo-album/config.js +0 -6
- package/demo-album/images/camera.png +0 -0
- package/demo-album/images/wave.png +0 -0
- package/demo-album/lib/api.js +0 -2
- package/demo-album/lib/cos-wx-sdk-v5.min.js +0 -1
- package/demo-album/lib/cos.js +0 -22
- package/demo-album/lib/request.js +0 -17
- package/demo-album/lib/util.js +0 -28
- package/demo-album/pages/album/album.js +0 -259
- package/demo-album/pages/album/album.json +0 -1
- package/demo-album/pages/album/album.wxml +0 -40
- package/demo-album/pages/album/album.wxss +0 -138
- package/demo-album/pages/index/index.js +0 -77
- package/demo-album/pages/index/index.json +0 -5
- package/demo-album/pages/index/index.wxml +0 -14
- package/demo-album/pages/index/index.wxss +0 -87
- package/demo-album/pages/preview/preview.js +0 -55
- package/demo-album/pages/preview/preview.json +0 -2
- package/demo-album/pages/preview/preview.wxml +0 -19
- package/demo-album/pages/preview/preview.wxss +0 -81
- package/demo-album/project.config.json +0 -32
- package/demo-album/sitemap.json +0 -7
- package/server/sts.js +0 -186
|
@@ -87,7 +87,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|
|
87
87
|
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
|
88
88
|
/******/
|
|
89
89
|
/******/ // __webpack_public_path__
|
|
90
|
-
/******/ __webpack_require__.p = "/Users/chrisftian/Documents/projects/cos-sdk/cos-wx-sdk-v5/
|
|
90
|
+
/******/ __webpack_require__.p = "/Users/chrisftian/Documents/projects/cos-sdk/cos-wx-sdk-v5/dist";
|
|
91
91
|
/******/
|
|
92
92
|
/******/
|
|
93
93
|
/******/ // Load entry module and return exports
|
|
@@ -1405,6 +1405,36 @@ module.exports = {
|
|
|
1405
1405
|
|
|
1406
1406
|
/***/ }),
|
|
1407
1407
|
|
|
1408
|
+
/***/ "./node_modules/fast-xml-parser/src/ignoreAttributes.js":
|
|
1409
|
+
/*!**************************************************************!*\
|
|
1410
|
+
!*** ./node_modules/fast-xml-parser/src/ignoreAttributes.js ***!
|
|
1411
|
+
\**************************************************************/
|
|
1412
|
+
/*! no static exports found */
|
|
1413
|
+
/***/ (function(module, exports) {
|
|
1414
|
+
|
|
1415
|
+
function getIgnoreAttributesFn(ignoreAttributes) {
|
|
1416
|
+
if (typeof ignoreAttributes === 'function') {
|
|
1417
|
+
return ignoreAttributes
|
|
1418
|
+
}
|
|
1419
|
+
if (Array.isArray(ignoreAttributes)) {
|
|
1420
|
+
return (attrName) => {
|
|
1421
|
+
for (const pattern of ignoreAttributes) {
|
|
1422
|
+
if (typeof pattern === 'string' && attrName === pattern) {
|
|
1423
|
+
return true
|
|
1424
|
+
}
|
|
1425
|
+
if (pattern instanceof RegExp && pattern.test(attrName)) {
|
|
1426
|
+
return true
|
|
1427
|
+
}
|
|
1428
|
+
}
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
return () => false
|
|
1432
|
+
}
|
|
1433
|
+
|
|
1434
|
+
module.exports = getIgnoreAttributesFn
|
|
1435
|
+
|
|
1436
|
+
/***/ }),
|
|
1437
|
+
|
|
1408
1438
|
/***/ "./node_modules/fast-xml-parser/src/util.js":
|
|
1409
1439
|
/*!**************************************************!*\
|
|
1410
1440
|
!*** ./node_modules/fast-xml-parser/src/util.js ***!
|
|
@@ -1937,6 +1967,7 @@ function getPositionFromMatch(match) {
|
|
|
1937
1967
|
|
|
1938
1968
|
//parse Empty Node as self closing node
|
|
1939
1969
|
const buildFromOrderedJs = __webpack_require__(/*! ./orderedJs2Xml */ "./node_modules/fast-xml-parser/src/xmlbuilder/orderedJs2Xml.js");
|
|
1970
|
+
const getIgnoreAttributesFn = __webpack_require__(/*! ../ignoreAttributes */ "./node_modules/fast-xml-parser/src/ignoreAttributes.js")
|
|
1940
1971
|
|
|
1941
1972
|
const defaultOptions = {
|
|
1942
1973
|
attributeNamePrefix: '@_',
|
|
@@ -1974,11 +2005,12 @@ const defaultOptions = {
|
|
|
1974
2005
|
|
|
1975
2006
|
function Builder(options) {
|
|
1976
2007
|
this.options = Object.assign({}, defaultOptions, options);
|
|
1977
|
-
if (this.options.ignoreAttributes || this.options.attributesGroupName) {
|
|
2008
|
+
if (this.options.ignoreAttributes === true || this.options.attributesGroupName) {
|
|
1978
2009
|
this.isAttribute = function(/*a*/) {
|
|
1979
2010
|
return false;
|
|
1980
2011
|
};
|
|
1981
2012
|
} else {
|
|
2013
|
+
this.ignoreAttributesFn = getIgnoreAttributesFn(this.options.ignoreAttributes)
|
|
1982
2014
|
this.attrPrefixLen = this.options.attributeNamePrefix.length;
|
|
1983
2015
|
this.isAttribute = isAttribute;
|
|
1984
2016
|
}
|
|
@@ -2007,13 +2039,14 @@ Builder.prototype.build = function(jObj) {
|
|
|
2007
2039
|
[this.options.arrayNodeName] : jObj
|
|
2008
2040
|
}
|
|
2009
2041
|
}
|
|
2010
|
-
return this.j2x(jObj, 0).val;
|
|
2042
|
+
return this.j2x(jObj, 0, []).val;
|
|
2011
2043
|
}
|
|
2012
2044
|
};
|
|
2013
2045
|
|
|
2014
|
-
Builder.prototype.j2x = function(jObj, level) {
|
|
2046
|
+
Builder.prototype.j2x = function(jObj, level, ajPath) {
|
|
2015
2047
|
let attrStr = '';
|
|
2016
2048
|
let val = '';
|
|
2049
|
+
const jPath = ajPath.join('.')
|
|
2017
2050
|
for (let key in jObj) {
|
|
2018
2051
|
if(!Object.prototype.hasOwnProperty.call(jObj, key)) continue;
|
|
2019
2052
|
if (typeof jObj[key] === 'undefined') {
|
|
@@ -2036,9 +2069,9 @@ Builder.prototype.j2x = function(jObj, level) {
|
|
|
2036
2069
|
} else if (typeof jObj[key] !== 'object') {
|
|
2037
2070
|
//premitive type
|
|
2038
2071
|
const attr = this.isAttribute(key);
|
|
2039
|
-
if (attr) {
|
|
2072
|
+
if (attr && !this.ignoreAttributesFn(attr, jPath)) {
|
|
2040
2073
|
attrStr += this.buildAttrPairStr(attr, '' + jObj[key]);
|
|
2041
|
-
}else {
|
|
2074
|
+
} else if (!attr) {
|
|
2042
2075
|
//tag value
|
|
2043
2076
|
if (key === this.options.textNodeName) {
|
|
2044
2077
|
let newval = this.options.tagValueProcessor(key, '' + jObj[key]);
|
|
@@ -2051,6 +2084,7 @@ Builder.prototype.j2x = function(jObj, level) {
|
|
|
2051
2084
|
//repeated nodes
|
|
2052
2085
|
const arrLen = jObj[key].length;
|
|
2053
2086
|
let listTagVal = "";
|
|
2087
|
+
let listTagAttr = "";
|
|
2054
2088
|
for (let j = 0; j < arrLen; j++) {
|
|
2055
2089
|
const item = jObj[key][j];
|
|
2056
2090
|
if (typeof item === 'undefined') {
|
|
@@ -2060,17 +2094,27 @@ Builder.prototype.j2x = function(jObj, level) {
|
|
|
2060
2094
|
else val += this.indentate(level) + '<' + key + '/' + this.tagEndChar;
|
|
2061
2095
|
// val += this.indentate(level) + '<' + key + '/' + this.tagEndChar;
|
|
2062
2096
|
} else if (typeof item === 'object') {
|
|
2063
|
-
if(this.options.oneListGroup
|
|
2064
|
-
|
|
2097
|
+
if(this.options.oneListGroup){
|
|
2098
|
+
const result = this.j2x(item, level + 1, ajPath.concat(key));
|
|
2099
|
+
listTagVal += result.val;
|
|
2100
|
+
if (this.options.attributesGroupName && item.hasOwnProperty(this.options.attributesGroupName)) {
|
|
2101
|
+
listTagAttr += result.attrStr
|
|
2102
|
+
}
|
|
2065
2103
|
}else{
|
|
2066
|
-
listTagVal += this.processTextOrObjNode(item, key, level)
|
|
2104
|
+
listTagVal += this.processTextOrObjNode(item, key, level, ajPath)
|
|
2067
2105
|
}
|
|
2068
2106
|
} else {
|
|
2069
|
-
|
|
2107
|
+
if (this.options.oneListGroup) {
|
|
2108
|
+
let textValue = this.options.tagValueProcessor(key, item);
|
|
2109
|
+
textValue = this.replaceEntitiesValue(textValue);
|
|
2110
|
+
listTagVal += textValue;
|
|
2111
|
+
} else {
|
|
2112
|
+
listTagVal += this.buildTextValNode(item, key, '', level);
|
|
2113
|
+
}
|
|
2070
2114
|
}
|
|
2071
2115
|
}
|
|
2072
2116
|
if(this.options.oneListGroup){
|
|
2073
|
-
listTagVal = this.buildObjectNode(listTagVal, key,
|
|
2117
|
+
listTagVal = this.buildObjectNode(listTagVal, key, listTagAttr, level);
|
|
2074
2118
|
}
|
|
2075
2119
|
val += listTagVal;
|
|
2076
2120
|
} else {
|
|
@@ -2082,7 +2126,7 @@ Builder.prototype.j2x = function(jObj, level) {
|
|
|
2082
2126
|
attrStr += this.buildAttrPairStr(Ks[j], '' + jObj[key][Ks[j]]);
|
|
2083
2127
|
}
|
|
2084
2128
|
} else {
|
|
2085
|
-
val += this.processTextOrObjNode(jObj[key], key, level)
|
|
2129
|
+
val += this.processTextOrObjNode(jObj[key], key, level, ajPath)
|
|
2086
2130
|
}
|
|
2087
2131
|
}
|
|
2088
2132
|
}
|
|
@@ -2097,8 +2141,8 @@ Builder.prototype.buildAttrPairStr = function(attrName, val){
|
|
|
2097
2141
|
} else return ' ' + attrName + '="' + val + '"';
|
|
2098
2142
|
}
|
|
2099
2143
|
|
|
2100
|
-
function processTextOrObjNode (object, key, level) {
|
|
2101
|
-
const result = this.j2x(object, level + 1);
|
|
2144
|
+
function processTextOrObjNode (object, key, level, ajPath) {
|
|
2145
|
+
const result = this.j2x(object, level + 1, ajPath.concat(key));
|
|
2102
2146
|
if (object[this.options.textNodeName] !== undefined && Object.keys(object).length === 1) {
|
|
2103
2147
|
return this.buildTextValNode(object[this.options.textNodeName], key, result.attrStr, level);
|
|
2104
2148
|
} else {
|
|
@@ -2590,6 +2634,7 @@ const util = __webpack_require__(/*! ../util */ "./node_modules/fast-xml-parser/
|
|
|
2590
2634
|
const xmlNode = __webpack_require__(/*! ./xmlNode */ "./node_modules/fast-xml-parser/src/xmlparser/xmlNode.js");
|
|
2591
2635
|
const readDocType = __webpack_require__(/*! ./DocTypeReader */ "./node_modules/fast-xml-parser/src/xmlparser/DocTypeReader.js");
|
|
2592
2636
|
const toNumber = __webpack_require__(/*! strnum */ "./node_modules/strnum/strnum.js");
|
|
2637
|
+
const getIgnoreAttributesFn = __webpack_require__(/*! ../ignoreAttributes */ "./node_modules/fast-xml-parser/src/ignoreAttributes.js")
|
|
2593
2638
|
|
|
2594
2639
|
// const regx =
|
|
2595
2640
|
// '<((!\\[CDATA\\[([\\s\\S]*?)(]]>))|((NAME:)?(NAME))([^>]*)>|((\\/)(NAME)\\s*>))([^<]*)'
|
|
@@ -2638,6 +2683,7 @@ class OrderedObjParser{
|
|
|
2638
2683
|
this.readStopNodeData = readStopNodeData;
|
|
2639
2684
|
this.saveTextToParentTag = saveTextToParentTag;
|
|
2640
2685
|
this.addChild = addChild;
|
|
2686
|
+
this.ignoreAttributesFn = getIgnoreAttributesFn(this.options.ignoreAttributes)
|
|
2641
2687
|
}
|
|
2642
2688
|
|
|
2643
2689
|
}
|
|
@@ -2710,7 +2756,7 @@ function resolveNameSpace(tagname) {
|
|
|
2710
2756
|
const attrsRegx = new RegExp('([^\\s=]+)\\s*(=\\s*([\'"])([\\s\\S]*?)\\3)?', 'gm');
|
|
2711
2757
|
|
|
2712
2758
|
function buildAttributesMap(attrStr, jPath, tagName) {
|
|
2713
|
-
if (
|
|
2759
|
+
if (this.options.ignoreAttributes !== true && typeof attrStr === 'string') {
|
|
2714
2760
|
// attrStr = attrStr.replace(/\r?\n/g, ' ');
|
|
2715
2761
|
//attrStr = attrStr || attrStr.trim();
|
|
2716
2762
|
|
|
@@ -2719,6 +2765,9 @@ function buildAttributesMap(attrStr, jPath, tagName) {
|
|
|
2719
2765
|
const attrs = {};
|
|
2720
2766
|
for (let i = 0; i < len; i++) {
|
|
2721
2767
|
const attrName = this.resolveNameSpace(matches[i][1]);
|
|
2768
|
+
if (this.ignoreAttributesFn(attrName, jPath)) {
|
|
2769
|
+
continue
|
|
2770
|
+
}
|
|
2722
2771
|
let oldVal = matches[i][4];
|
|
2723
2772
|
let aName = this.options.attributeNamePrefix + attrName;
|
|
2724
2773
|
if (attrName.length) {
|
|
@@ -2764,7 +2813,7 @@ function buildAttributesMap(attrStr, jPath, tagName) {
|
|
|
2764
2813
|
}
|
|
2765
2814
|
|
|
2766
2815
|
const parseXml = function(xmlData) {
|
|
2767
|
-
xmlData = xmlData.replace(/\r\n?/g, "\n"); //TODO: remove this line
|
|
2816
|
+
// xmlData = xmlData.replace(/\r\n?/g, "\n"); //TODO: remove this line
|
|
2768
2817
|
const xmlObj = new xmlNode('!xml');
|
|
2769
2818
|
let currentNode = xmlObj;
|
|
2770
2819
|
let textData = "";
|
|
@@ -3753,7 +3802,7 @@ module.exports = function(module) {
|
|
|
3753
3802
|
/*! exports provided: name, version, description, main, scripts, repository, author, license, dependencies, devDependencies, default */
|
|
3754
3803
|
/***/ (function(module) {
|
|
3755
3804
|
|
|
3756
|
-
module.exports = JSON.parse("{\"name\":\"cos-wx-sdk-v5\",\"version\":\"1.
|
|
3805
|
+
module.exports = JSON.parse("{\"name\":\"cos-wx-sdk-v5\",\"version\":\"1.8.0\",\"description\":\"小程序 SDK for [腾讯云对象存储服务](https://cloud.tencent.com/product/cos)\",\"main\":\"dist/cos-wx-sdk-v5.min.js\",\"scripts\":{\"prettier\":\"prettier --write src demo/demo-sdk.js demo/test.js demo/ciDemo\",\"dev\":\"cross-env NODE_ENV=development node build.js --mode=development\",\"build\":\"cross-env NODE_ENV=production node build.js --mode=production\",\"sts.js\":\"node server/sts.js\",\"postinstall\":\"patch-package\"},\"repository\":{\"type\":\"git\",\"url\":\"http://github.com/tencentyun/cos-wx-sdk-v5.git\"},\"author\":\"carsonxu\",\"license\":\"ISC\",\"dependencies\":{\"fast-xml-parser\":\"4.5.0\",\"mime\":\"^2.4.6\"},\"devDependencies\":{\"@babel/core\":\"7.17.9\",\"@babel/preset-env\":\"7.16.11\",\"babel-loader\":\"8.2.5\",\"body-parser\":\"^1.18.3\",\"cross-env\":\"^7.0.3\",\"express\":\"^4.17.1\",\"patch-package\":\"^8.0.0\",\"prettier\":\"^3.0.1\",\"qcloud-cos-sts\":\"^3.0.2\",\"terser-webpack-plugin\":\"4.2.3\",\"webpack\":\"4.46.0\",\"webpack-cli\":\"4.10.0\"}}");
|
|
3757
3806
|
|
|
3758
3807
|
/***/ }),
|
|
3759
3808
|
|
|
@@ -7239,7 +7288,9 @@ function putObject(params, callback) {
|
|
|
7239
7288
|
// 特殊处理 Cache-Control、Content-Type,避免代理更改这两个字段导致写入到 Object 属性里
|
|
7240
7289
|
var headers = params.Headers;
|
|
7241
7290
|
if (!headers['Cache-Control'] && !headers['cache-control']) headers['Cache-Control'] = '';
|
|
7242
|
-
if (!headers['Content-Type'] && !headers['content-type'])
|
|
7291
|
+
if (!headers['Content-Type'] && !headers['content-type']) {
|
|
7292
|
+
headers['Content-Type'] = mime.getType(params.Key) || 'application/octet-stream';
|
|
7293
|
+
}
|
|
7243
7294
|
var needCalcMd5 = params.UploadAddMetaMd5 || self.options.UploadAddMetaMd5 || self.options.UploadCheckContentMd5;
|
|
7244
7295
|
var tracker = params.tracker;
|
|
7245
7296
|
needCalcMd5 && tracker && tracker.setParams({
|
|
@@ -7936,7 +7987,9 @@ function multipartInit(params, callback) {
|
|
|
7936
7987
|
|
|
7937
7988
|
// 特殊处理 Cache-Control、Content-Type
|
|
7938
7989
|
if (!headers['Cache-Control'] && !headers['cache-control']) headers['Cache-Control'] = '';
|
|
7939
|
-
if (!headers['Content-Type'] && !headers['content-type'])
|
|
7990
|
+
if (!headers['Content-Type'] && !headers['content-type']) {
|
|
7991
|
+
headers['Content-Type'] = mime.getType(params.Key) || 'application/octet-stream';
|
|
7992
|
+
}
|
|
7940
7993
|
submitRequest.call(self, {
|
|
7941
7994
|
Action: 'name/cos:InitiateMultipartUpload',
|
|
7942
7995
|
method: 'POST',
|
|
@@ -8088,7 +8141,7 @@ function multipartComplete(params, callback) {
|
|
|
8088
8141
|
protocol: self.options.Protocol,
|
|
8089
8142
|
domain: self.options.Domain,
|
|
8090
8143
|
bucket: params.Bucket,
|
|
8091
|
-
region: params.Region,
|
|
8144
|
+
region: !self.options.UseAccelerate ? params.Region : 'accelerate',
|
|
8092
8145
|
object: params.Key,
|
|
8093
8146
|
isLocation: true
|
|
8094
8147
|
});
|
|
@@ -8816,7 +8869,15 @@ function allowRetry(err) {
|
|
|
8816
8869
|
canRetry = true;
|
|
8817
8870
|
}
|
|
8818
8871
|
} else if (Math.floor(err.statusCode / 100) === 5) {
|
|
8819
|
-
|
|
8872
|
+
return {
|
|
8873
|
+
canRetry: true,
|
|
8874
|
+
networkError: false
|
|
8875
|
+
};
|
|
8876
|
+
} else if (err.message === 'timeout') {
|
|
8877
|
+
return {
|
|
8878
|
+
canRetry: true,
|
|
8879
|
+
networkError: self.options.AutoSwitchHost
|
|
8880
|
+
};
|
|
8820
8881
|
}
|
|
8821
8882
|
/**
|
|
8822
8883
|
* 归为网络错误
|
|
@@ -8824,8 +8885,8 @@ function allowRetry(err) {
|
|
|
8824
8885
|
* 2、statusCode === 3xx || 4xx || 5xx && no requestId
|
|
8825
8886
|
*/
|
|
8826
8887
|
if (!err.statusCode) {
|
|
8827
|
-
canRetry =
|
|
8828
|
-
networkError =
|
|
8888
|
+
canRetry = true;
|
|
8889
|
+
networkError = self.options.AutoSwitchHost;
|
|
8829
8890
|
} else {
|
|
8830
8891
|
var statusCode = Math.floor(err.statusCode / 100);
|
|
8831
8892
|
var requestId = (err === null || err === void 0 ? void 0 : err.headers) && (err === null || err === void 0 ? void 0 : err.headers['x-cos-request-id']);
|
|
@@ -8928,7 +8989,7 @@ function submitRequest(params, callback) {
|
|
|
8928
8989
|
tracker && tracker.setParams({
|
|
8929
8990
|
httpEndTime: new Date().getTime()
|
|
8930
8991
|
});
|
|
8931
|
-
if (err && tryTimes <
|
|
8992
|
+
if (err && tryTimes < 4 && canRetry) {
|
|
8932
8993
|
if (params.headers) {
|
|
8933
8994
|
delete params.headers.Authorization;
|
|
8934
8995
|
delete params.headers['token'];
|
|
@@ -8944,7 +9005,8 @@ function submitRequest(params, callback) {
|
|
|
8944
9005
|
networkError: networkError
|
|
8945
9006
|
});
|
|
8946
9007
|
params.SwitchHost = switchHost;
|
|
8947
|
-
|
|
9008
|
+
// 重试时增加请求头,小程序里传字符串类型
|
|
9009
|
+
params.headers['x-cos-sdk-retry'] = 'true';
|
|
8948
9010
|
next(tryTimes + 1);
|
|
8949
9011
|
} else {
|
|
8950
9012
|
callback(err, data);
|
|
@@ -9025,9 +9087,6 @@ function _submitRequest(params, callback) {
|
|
|
9025
9087
|
|
|
9026
9088
|
// 清理 undefined 和 null 字段
|
|
9027
9089
|
opt.headers && (opt.headers = util.clearKey(opt.headers));
|
|
9028
|
-
if (params.retry) {
|
|
9029
|
-
opt.headers['x-cos-sdk-retry'] = true;
|
|
9030
|
-
}
|
|
9031
9090
|
opt = util.clearKey(opt);
|
|
9032
9091
|
|
|
9033
9092
|
// progress
|
|
@@ -9866,62 +9925,38 @@ var utils = {
|
|
|
9866
9925
|
},
|
|
9867
9926
|
// 获取系统信息
|
|
9868
9927
|
getSystemInfo: function getSystemInfo() {
|
|
9869
|
-
var
|
|
9870
|
-
|
|
9871
|
-
|
|
9872
|
-
|
|
9873
|
-
|
|
9928
|
+
var baseInfo = {
|
|
9929
|
+
// ↓上报项
|
|
9930
|
+
devicePlatform: 'can_not_get_system_info',
|
|
9931
|
+
// ios/anroid/windows/mac/devtools
|
|
9932
|
+
wxVersion: 'can_not_get_system_info',
|
|
9933
|
+
wxSystem: 'can_not_get_system_info',
|
|
9934
|
+
wxSdkVersion: 'can_not_get_system_info'
|
|
9874
9935
|
};
|
|
9875
|
-
|
|
9876
|
-
|
|
9877
|
-
|
|
9878
|
-
|
|
9879
|
-
|
|
9880
|
-
|
|
9881
|
-
|
|
9882
|
-
|
|
9883
|
-
|
|
9884
|
-
|
|
9885
|
-
|
|
9886
|
-
|
|
9887
|
-
|
|
9888
|
-
|
|
9889
|
-
|
|
9890
|
-
|
|
9891
|
-
|
|
9892
|
-
|
|
9893
|
-
|
|
9894
|
-
resolve({
|
|
9895
|
-
devicePlatform: 'can_not_get_system_info',
|
|
9896
|
-
wxVersion: 'can_not_get_system_info',
|
|
9897
|
-
wxSystem: 'can_not_get_system_info',
|
|
9898
|
-
wxSdkVersion: 'can_not_get_system_info'
|
|
9899
|
-
});
|
|
9900
|
-
}
|
|
9901
|
-
} else {
|
|
9902
|
-
resolve({
|
|
9903
|
-
devicePlatform: 'can_not_get_system_info',
|
|
9904
|
-
wxVersion: 'can_not_get_system_info',
|
|
9905
|
-
wxSystem: 'can_not_get_system_info',
|
|
9906
|
-
wxSdkVersion: 'can_not_get_system_info'
|
|
9907
|
-
});
|
|
9908
|
-
}
|
|
9909
|
-
});
|
|
9936
|
+
var appBaseInfo = {};
|
|
9937
|
+
var deviceInfo = {};
|
|
9938
|
+
if (wx.canIUse('getAppBaseInfo')) {
|
|
9939
|
+
appBaseInfo = wx.getAppBaseInfo() || {};
|
|
9940
|
+
}
|
|
9941
|
+
if (wx.canIUse('getDeviceInfo')) {
|
|
9942
|
+
deviceInfo = wx.getDeviceInfo() || {};
|
|
9943
|
+
}
|
|
9944
|
+
var sdkVersion = appBaseInfo.SDKVersion || 'can_not_get_system_info';
|
|
9945
|
+
var version = appBaseInfo.version || 'can_not_get_system_info';
|
|
9946
|
+
var platform = deviceInfo.platform || 'can_not_get_system_info';
|
|
9947
|
+
var system = deviceInfo.system || 'can_not_get_system_info';
|
|
9948
|
+
Object.assign(baseInfo, {
|
|
9949
|
+
devicePlatform: platform,
|
|
9950
|
+
wxVersion: version,
|
|
9951
|
+
wxSystem: system,
|
|
9952
|
+
wxSdkVersion: sdkVersion
|
|
9953
|
+
});
|
|
9954
|
+
return baseInfo;
|
|
9910
9955
|
}
|
|
9911
9956
|
};
|
|
9912
9957
|
|
|
9913
9958
|
// 设备信息,只取一次值
|
|
9914
|
-
var deviceInfo =
|
|
9915
|
-
// ↓上报项
|
|
9916
|
-
devicePlatform: '',
|
|
9917
|
-
// ios/anroid/windows/mac/devtools
|
|
9918
|
-
wxVersion: '',
|
|
9919
|
-
wxSystem: '',
|
|
9920
|
-
wxSdkVersion: ''
|
|
9921
|
-
};
|
|
9922
|
-
utils.getSystemInfo().then(function (res) {
|
|
9923
|
-
Object.assign(deviceInfo, res);
|
|
9924
|
-
});
|
|
9959
|
+
var deviceInfo = utils.getSystemInfo();
|
|
9925
9960
|
var transApiName = function transApiName(api) {
|
|
9926
9961
|
if (['putObject', 'sliceUploadFile', 'uploadFile', 'uploadFiles'].includes(api)) {
|
|
9927
9962
|
return 'UploadTask';
|
|
@@ -10269,14 +10304,37 @@ var xmlParser = new XMLParser({
|
|
|
10269
10304
|
// 忽略 XML 声明
|
|
10270
10305
|
ignoreAttributes: true,
|
|
10271
10306
|
// 忽略属性
|
|
10272
|
-
parseTagValue: false
|
|
10307
|
+
parseTagValue: false,
|
|
10308
|
+
// 关闭自动解析
|
|
10309
|
+
trimValues: false // 关闭默认 trim
|
|
10273
10310
|
});
|
|
10274
10311
|
var xmlBuilder = new XMLBuilder();
|
|
10275
10312
|
|
|
10313
|
+
// 删掉不需要的#text
|
|
10314
|
+
var textNodeName = '#text';
|
|
10315
|
+
var deleteTextNodes = function deleteTextNodes(obj) {
|
|
10316
|
+
if (!isObject(obj)) return;
|
|
10317
|
+
for (var i in obj) {
|
|
10318
|
+
var item = obj[i];
|
|
10319
|
+
if (typeof item === 'string') {
|
|
10320
|
+
if (i === textNodeName) {
|
|
10321
|
+
delete obj[i];
|
|
10322
|
+
}
|
|
10323
|
+
} else if (Array.isArray(item)) {
|
|
10324
|
+
item.forEach(function (i) {
|
|
10325
|
+
deleteTextNodes(i);
|
|
10326
|
+
});
|
|
10327
|
+
} else if (isObject(item)) {
|
|
10328
|
+
deleteTextNodes(item);
|
|
10329
|
+
}
|
|
10330
|
+
}
|
|
10331
|
+
};
|
|
10332
|
+
|
|
10276
10333
|
// XML 对象转 JSON 对象
|
|
10277
10334
|
var xml2json = function xml2json(bodyStr) {
|
|
10278
|
-
var
|
|
10279
|
-
|
|
10335
|
+
var json = xmlParser.parse(bodyStr);
|
|
10336
|
+
deleteTextNodes(json);
|
|
10337
|
+
return json;
|
|
10280
10338
|
};
|
|
10281
10339
|
|
|
10282
10340
|
// JSON 对象转 XML 对象
|
|
@@ -10322,12 +10380,12 @@ var obj2str = function obj2str(obj, lowerCaseKey) {
|
|
|
10322
10380
|
};
|
|
10323
10381
|
|
|
10324
10382
|
// 可以签入签名的headers
|
|
10325
|
-
var signHeaders = ['cache-control', 'content-disposition', 'content-encoding', 'content-length', 'content-md5', 'expect', 'expires', 'host', 'if-match', 'if-modified-since', 'if-none-match', 'if-unmodified-since', 'origin', 'range', 'transfer-encoding', 'pic-operations'];
|
|
10383
|
+
var signHeaders = ['cache-control', 'content-disposition', 'content-encoding', 'content-length', 'content-md5', 'content-type', 'expect', 'expires', 'host', 'if-match', 'if-modified-since', 'if-none-match', 'if-unmodified-since', 'origin', 'range', 'transfer-encoding', 'pic-operations'];
|
|
10326
10384
|
var getSignHeaderObj = function getSignHeaderObj(headers) {
|
|
10327
10385
|
var signHeaderObj = {};
|
|
10328
10386
|
for (var i in headers) {
|
|
10329
10387
|
var key = i.toLowerCase();
|
|
10330
|
-
if (key.indexOf('x-cos-') > -1 || signHeaders.indexOf(key) > -1) {
|
|
10388
|
+
if (key.indexOf('x-cos-') > -1 || key.indexOf('x-ci-') > -1 || signHeaders.indexOf(key) > -1) {
|
|
10331
10389
|
signHeaderObj[i] = headers[i];
|
|
10332
10390
|
}
|
|
10333
10391
|
}
|
|
@@ -10477,6 +10535,9 @@ function extend(target, source) {
|
|
|
10477
10535
|
function isArray(arr) {
|
|
10478
10536
|
return arr instanceof Array;
|
|
10479
10537
|
}
|
|
10538
|
+
function isObject(obj) {
|
|
10539
|
+
return Object.prototype.toString.call(obj) === '[object Object]';
|
|
10540
|
+
}
|
|
10480
10541
|
function isInArray(arr, item) {
|
|
10481
10542
|
var flag = false;
|
|
10482
10543
|
for (var i = 0; i < arr.length; i++) {
|
|
@@ -10673,8 +10734,8 @@ var apiWrapper = function apiWrapper(apiName, apiFn) {
|
|
|
10673
10734
|
// 代理回调函数
|
|
10674
10735
|
var formatResult = function formatResult(result) {
|
|
10675
10736
|
if (result && result.headers) {
|
|
10676
|
-
result.headers['x-cos-request-id'] && (result.RequestId = result.headers['x-cos-request-id']);
|
|
10677
10737
|
result.headers['x-ci-request-id'] && (result.RequestId = result.headers['x-ci-request-id']);
|
|
10738
|
+
result.headers['x-cos-request-id'] && (result.RequestId = result.headers['x-cos-request-id']);
|
|
10678
10739
|
result.headers['x-cos-version-id'] && (result.VersionId = result.headers['x-cos-version-id']);
|
|
10679
10740
|
result.headers['x-cos-delete-marker'] && (result.DeleteMarker = result.headers['x-cos-delete-marker']);
|
|
10680
10741
|
}
|
|
@@ -10905,6 +10966,7 @@ var getSkewTime = function getSkewTime(offset) {
|
|
|
10905
10966
|
return Date.now() + (offset || 0);
|
|
10906
10967
|
};
|
|
10907
10968
|
var compareVersion = function compareVersion(v1, v2) {
|
|
10969
|
+
if (!v1 || !v2) return -1;
|
|
10908
10970
|
v1 = v1.split('.');
|
|
10909
10971
|
v2 = v2.split('.');
|
|
10910
10972
|
var len = Math.max(v1.length, v2.length);
|
|
@@ -10926,9 +10988,18 @@ var compareVersion = function compareVersion(v1, v2) {
|
|
|
10926
10988
|
return 0;
|
|
10927
10989
|
};
|
|
10928
10990
|
var canFileSlice = function () {
|
|
10929
|
-
var
|
|
10930
|
-
var
|
|
10931
|
-
|
|
10991
|
+
var appBaseInfo = {};
|
|
10992
|
+
var deviceInfo = {};
|
|
10993
|
+
if (wx.canIUse('getAppBaseInfo')) {
|
|
10994
|
+
appBaseInfo = wx.getAppBaseInfo() || {};
|
|
10995
|
+
}
|
|
10996
|
+
if (wx.canIUse('getDeviceInfo')) {
|
|
10997
|
+
deviceInfo = wx.getDeviceInfo() || {};
|
|
10998
|
+
}
|
|
10999
|
+
var sdkVersion = appBaseInfo.SDKVersion;
|
|
11000
|
+
var platform = deviceInfo.platform;
|
|
11001
|
+
var support = compareVersion(sdkVersion, '2.10.0') >= 0;
|
|
11002
|
+
var needWarning = !support && platform === 'devtools';
|
|
10932
11003
|
return function () {
|
|
10933
11004
|
if (needWarning) console.warn('当前小程序版本小于 2.10.0,不支持分片上传,请更新软件。');
|
|
10934
11005
|
needWarning = false;
|