Skip to content

Commit cafc412

Browse files
authored
feat: 丰富上报参数 (#223)
* feat: 丰富上报参数
1 parent bf87152 commit cafc412

File tree

4 files changed

+74
-21
lines changed

4 files changed

+74
-21
lines changed

dist/cos-js-sdk-v5.js

Lines changed: 69 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,6 +1487,36 @@ module.exports = {
14871487

14881488
/***/ }),
14891489

1490+
/***/ "./node_modules/fast-xml-parser/src/ignoreAttributes.js":
1491+
/*!**************************************************************!*\
1492+
!*** ./node_modules/fast-xml-parser/src/ignoreAttributes.js ***!
1493+
\**************************************************************/
1494+
/*! no static exports found */
1495+
/***/ (function(module, exports) {
1496+
1497+
function getIgnoreAttributesFn(ignoreAttributes) {
1498+
if (typeof ignoreAttributes === 'function') {
1499+
return ignoreAttributes
1500+
}
1501+
if (Array.isArray(ignoreAttributes)) {
1502+
return (attrName) => {
1503+
for (const pattern of ignoreAttributes) {
1504+
if (typeof pattern === 'string' && attrName === pattern) {
1505+
return true
1506+
}
1507+
if (pattern instanceof RegExp && pattern.test(attrName)) {
1508+
return true
1509+
}
1510+
}
1511+
}
1512+
}
1513+
return () => false
1514+
}
1515+
1516+
module.exports = getIgnoreAttributesFn
1517+
1518+
/***/ }),
1519+
14901520
/***/ "./node_modules/fast-xml-parser/src/util.js":
14911521
/*!**************************************************!*\
14921522
!*** ./node_modules/fast-xml-parser/src/util.js ***!
@@ -2019,6 +2049,7 @@ function getPositionFromMatch(match) {
20192049

20202050
//parse Empty Node as self closing node
20212051
const buildFromOrderedJs = __webpack_require__(/*! ./orderedJs2Xml */ "./node_modules/fast-xml-parser/src/xmlbuilder/orderedJs2Xml.js");
2052+
const getIgnoreAttributesFn = __webpack_require__(/*! ../ignoreAttributes */ "./node_modules/fast-xml-parser/src/ignoreAttributes.js")
20222053

20232054
const defaultOptions = {
20242055
attributeNamePrefix: '@_',
@@ -2056,11 +2087,12 @@ const defaultOptions = {
20562087

20572088
function Builder(options) {
20582089
this.options = Object.assign({}, defaultOptions, options);
2059-
if (this.options.ignoreAttributes || this.options.attributesGroupName) {
2090+
if (this.options.ignoreAttributes === true || this.options.attributesGroupName) {
20602091
this.isAttribute = function(/*a*/) {
20612092
return false;
20622093
};
20632094
} else {
2095+
this.ignoreAttributesFn = getIgnoreAttributesFn(this.options.ignoreAttributes)
20642096
this.attrPrefixLen = this.options.attributeNamePrefix.length;
20652097
this.isAttribute = isAttribute;
20662098
}
@@ -2089,13 +2121,14 @@ Builder.prototype.build = function(jObj) {
20892121
[this.options.arrayNodeName] : jObj
20902122
}
20912123
}
2092-
return this.j2x(jObj, 0).val;
2124+
return this.j2x(jObj, 0, []).val;
20932125
}
20942126
};
20952127

2096-
Builder.prototype.j2x = function(jObj, level) {
2128+
Builder.prototype.j2x = function(jObj, level, ajPath) {
20972129
let attrStr = '';
20982130
let val = '';
2131+
const jPath = ajPath.join('.')
20992132
for (let key in jObj) {
21002133
if(!Object.prototype.hasOwnProperty.call(jObj, key)) continue;
21012134
if (typeof jObj[key] === 'undefined') {
@@ -2118,9 +2151,9 @@ Builder.prototype.j2x = function(jObj, level) {
21182151
} else if (typeof jObj[key] !== 'object') {
21192152
//premitive type
21202153
const attr = this.isAttribute(key);
2121-
if (attr) {
2154+
if (attr && !this.ignoreAttributesFn(attr, jPath)) {
21222155
attrStr += this.buildAttrPairStr(attr, '' + jObj[key]);
2123-
}else {
2156+
} else if (!attr) {
21242157
//tag value
21252158
if (key === this.options.textNodeName) {
21262159
let newval = this.options.tagValueProcessor(key, '' + jObj[key]);
@@ -2133,6 +2166,7 @@ Builder.prototype.j2x = function(jObj, level) {
21332166
//repeated nodes
21342167
const arrLen = jObj[key].length;
21352168
let listTagVal = "";
2169+
let listTagAttr = "";
21362170
for (let j = 0; j < arrLen; j++) {
21372171
const item = jObj[key][j];
21382172
if (typeof item === 'undefined') {
@@ -2142,17 +2176,27 @@ Builder.prototype.j2x = function(jObj, level) {
21422176
else val += this.indentate(level) + '<' + key + '/' + this.tagEndChar;
21432177
// val += this.indentate(level) + '<' + key + '/' + this.tagEndChar;
21442178
} else if (typeof item === 'object') {
2145-
if(this.options.oneListGroup ){
2146-
listTagVal += this.j2x(item, level + 1).val;
2179+
if(this.options.oneListGroup){
2180+
const result = this.j2x(item, level + 1, ajPath.concat(key));
2181+
listTagVal += result.val;
2182+
if (this.options.attributesGroupName && item.hasOwnProperty(this.options.attributesGroupName)) {
2183+
listTagAttr += result.attrStr
2184+
}
21472185
}else{
2148-
listTagVal += this.processTextOrObjNode(item, key, level)
2186+
listTagVal += this.processTextOrObjNode(item, key, level, ajPath)
21492187
}
21502188
} else {
2151-
listTagVal += this.buildTextValNode(item, key, '', level);
2189+
if (this.options.oneListGroup) {
2190+
let textValue = this.options.tagValueProcessor(key, item);
2191+
textValue = this.replaceEntitiesValue(textValue);
2192+
listTagVal += textValue;
2193+
} else {
2194+
listTagVal += this.buildTextValNode(item, key, '', level);
2195+
}
21522196
}
21532197
}
21542198
if(this.options.oneListGroup){
2155-
listTagVal = this.buildObjectNode(listTagVal, key, '', level);
2199+
listTagVal = this.buildObjectNode(listTagVal, key, listTagAttr, level);
21562200
}
21572201
val += listTagVal;
21582202
} else {
@@ -2164,7 +2208,7 @@ Builder.prototype.j2x = function(jObj, level) {
21642208
attrStr += this.buildAttrPairStr(Ks[j], '' + jObj[key][Ks[j]]);
21652209
}
21662210
} else {
2167-
val += this.processTextOrObjNode(jObj[key], key, level)
2211+
val += this.processTextOrObjNode(jObj[key], key, level, ajPath)
21682212
}
21692213
}
21702214
}
@@ -2179,8 +2223,8 @@ Builder.prototype.buildAttrPairStr = function(attrName, val){
21792223
} else return ' ' + attrName + '="' + val + '"';
21802224
}
21812225

2182-
function processTextOrObjNode (object, key, level) {
2183-
const result = this.j2x(object, level + 1);
2226+
function processTextOrObjNode (object, key, level, ajPath) {
2227+
const result = this.j2x(object, level + 1, ajPath.concat(key));
21842228
if (object[this.options.textNodeName] !== undefined && Object.keys(object).length === 1) {
21852229
return this.buildTextValNode(object[this.options.textNodeName], key, result.attrStr, level);
21862230
} else {
@@ -2672,6 +2716,7 @@ const util = __webpack_require__(/*! ../util */ "./node_modules/fast-xml-parser/
26722716
const xmlNode = __webpack_require__(/*! ./xmlNode */ "./node_modules/fast-xml-parser/src/xmlparser/xmlNode.js");
26732717
const readDocType = __webpack_require__(/*! ./DocTypeReader */ "./node_modules/fast-xml-parser/src/xmlparser/DocTypeReader.js");
26742718
const toNumber = __webpack_require__(/*! strnum */ "./node_modules/strnum/strnum.js");
2719+
const getIgnoreAttributesFn = __webpack_require__(/*! ../ignoreAttributes */ "./node_modules/fast-xml-parser/src/ignoreAttributes.js")
26752720

26762721
// const regx =
26772722
// '<((!\\[CDATA\\[([\\s\\S]*?)(]]>))|((NAME:)?(NAME))([^>]*)>|((\\/)(NAME)\\s*>))([^<]*)'
@@ -2720,6 +2765,7 @@ class OrderedObjParser{
27202765
this.readStopNodeData = readStopNodeData;
27212766
this.saveTextToParentTag = saveTextToParentTag;
27222767
this.addChild = addChild;
2768+
this.ignoreAttributesFn = getIgnoreAttributesFn(this.options.ignoreAttributes)
27232769
}
27242770

27252771
}
@@ -2792,7 +2838,7 @@ function resolveNameSpace(tagname) {
27922838
const attrsRegx = new RegExp('([^\\s=]+)\\s*(=\\s*([\'"])([\\s\\S]*?)\\3)?', 'gm');
27932839

27942840
function buildAttributesMap(attrStr, jPath, tagName) {
2795-
if (!this.options.ignoreAttributes && typeof attrStr === 'string') {
2841+
if (this.options.ignoreAttributes !== true && typeof attrStr === 'string') {
27962842
// attrStr = attrStr.replace(/\r?\n/g, ' ');
27972843
//attrStr = attrStr || attrStr.trim();
27982844

@@ -2801,6 +2847,9 @@ function buildAttributesMap(attrStr, jPath, tagName) {
28012847
const attrs = {};
28022848
for (let i = 0; i < len; i++) {
28032849
const attrName = this.resolveNameSpace(matches[i][1]);
2850+
if (this.ignoreAttributesFn(attrName, jPath)) {
2851+
continue
2852+
}
28042853
let oldVal = matches[i][4];
28052854
let aName = this.options.attributeNamePrefix + attrName;
28062855
if (attrName.length) {
@@ -3883,7 +3932,7 @@ module.exports = function(module) {
38833932
/*! exports provided: name, version, description, main, types, scripts, repository, keywords, author, license, bugs, homepage, dependencies, devDependencies, default */
38843933
/***/ (function(module) {
38853934

3886-
module.exports = JSON.parse("{\"name\":\"cos-js-sdk-v5\",\"version\":\"1.8.6\",\"description\":\"JavaScript SDK for [腾讯云对象存储](https://cloud.tencent.com/product/cos)\",\"main\":\"dist/cos-js-sdk-v5.js\",\"types\":\"index.d.ts\",\"scripts\":{\"prettier\":\"prettier --write src demo/demo.js demo/CIDemos/*.js test/test.js server/sts.js lib/request.js index.d.ts\",\"server\":\"node server/sts.js\",\"dev\":\"cross-env NODE_ENV=development webpack -w --mode=development\",\"build\":\"cross-env NODE_ENV=production webpack --mode=production\",\"cos-auth.min.js\":\"uglifyjs ./demo/common/cos-auth.js -o ./demo/common/cos-auth.min.js -c -m\",\"test\":\"jest --runInBand --coverage\"},\"repository\":{\"type\":\"git\",\"url\":\"git+https://github.com/tencentyun/cos-js-sdk-v5.git\"},\"keywords\":[],\"author\":\"carsonxu\",\"license\":\"ISC\",\"bugs\":{\"url\":\"https://github.com/tencentyun/cos-js-sdk-v5/issues\"},\"homepage\":\"https://github.com/tencentyun/cos-js-sdk-v5#readme\",\"dependencies\":{\"fast-xml-parser\":\"^4.4.0\"},\"devDependencies\":{\"@babel/core\":\"7.17.9\",\"@babel/plugin-transform-runtime\":\"7.18.10\",\"@babel/preset-env\":\"7.16.11\",\"babel-loader\":\"8.2.5\",\"body-parser\":\"^1.18.3\",\"cross-env\":\"^5.2.0\",\"express\":\"^4.16.4\",\"jest\":\"^29.3.1\",\"jest-environment-jsdom\":\"^29.3.1\",\"prettier\":\"^3.0.1\",\"qcloud-cos-sts\":\"^3.0.2\",\"request\":\"^2.87.0\",\"terser-webpack-plugin\":\"4.2.3\",\"uglifyjs\":\"^2.4.11\",\"webpack\":\"4.46.0\",\"webpack-cli\":\"4.10.0\"}}");
3935+
module.exports = JSON.parse("{\"name\":\"cos-js-sdk-v5\",\"version\":\"1.8.7\",\"description\":\"JavaScript SDK for [腾讯云对象存储](https://cloud.tencent.com/product/cos)\",\"main\":\"dist/cos-js-sdk-v5.js\",\"types\":\"index.d.ts\",\"scripts\":{\"prettier\":\"prettier --write src demo/demo.js demo/CIDemos/*.js test/test.js server/sts.js lib/request.js index.d.ts\",\"server\":\"node server/sts.js\",\"dev\":\"cross-env NODE_ENV=development webpack -w --mode=development\",\"build\":\"cross-env NODE_ENV=production webpack --mode=production\",\"cos-auth.min.js\":\"uglifyjs ./demo/common/cos-auth.js -o ./demo/common/cos-auth.min.js -c -m\",\"test\":\"jest --runInBand --coverage\"},\"repository\":{\"type\":\"git\",\"url\":\"git+https://github.com/tencentyun/cos-js-sdk-v5.git\"},\"keywords\":[],\"author\":\"carsonxu\",\"license\":\"ISC\",\"bugs\":{\"url\":\"https://github.com/tencentyun/cos-js-sdk-v5/issues\"},\"homepage\":\"https://github.com/tencentyun/cos-js-sdk-v5#readme\",\"dependencies\":{\"fast-xml-parser\":\"4.5.0\"},\"devDependencies\":{\"@babel/core\":\"7.17.9\",\"@babel/plugin-transform-runtime\":\"7.18.10\",\"@babel/preset-env\":\"7.16.11\",\"babel-loader\":\"8.2.5\",\"body-parser\":\"^1.18.3\",\"cross-env\":\"^5.2.0\",\"express\":\"^4.16.4\",\"jest\":\"^29.3.1\",\"jest-environment-jsdom\":\"^29.3.1\",\"prettier\":\"^3.0.1\",\"qcloud-cos-sts\":\"^3.0.2\",\"request\":\"^2.87.0\",\"terser-webpack-plugin\":\"4.2.3\",\"uglifyjs\":\"^2.4.11\",\"webpack\":\"4.46.0\",\"webpack-cli\":\"4.10.0\"}}");
38873936

38883937
/***/ }),
38893938

@@ -9135,6 +9184,8 @@ function _submitRequest(params, callback) {
91359184
params.AuthData.ClientIP && (opt.headers['clientIP'] = params.AuthData.ClientIP);
91369185
params.AuthData.ClientUA && (opt.headers['clientUA'] = params.AuthData.ClientUA);
91379186
params.AuthData.SecurityToken && (opt.headers[token] = params.AuthData.SecurityToken);
9187+
params.Action && (opt.action = params.Action);
9188+
opt.key = params.Key || params.ResourceKey;
91389189

91399190
// 清理 undefined 和 null 字段
91409191
opt.headers && (opt.headers = util.clearKey(opt.headers));
@@ -10394,9 +10445,9 @@ module.exports = Tracker;
1039410445
/* WEBPACK VAR INJECTION */(function(process) {
1039510446

1039610447
var _typeof = __webpack_require__(/*! @babel/runtime/helpers/typeof */ "./node_modules/@babel/runtime/helpers/typeof.js");
10397-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
10398-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
10399-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
10448+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
10449+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
10450+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
1040010451
var md5 = __webpack_require__(/*! ../lib/md5 */ "./lib/md5.js");
1040110452
var CryptoJS = __webpack_require__(/*! ../lib/crypto */ "./lib/crypto.js");
1040210453
var _require = __webpack_require__(/*! fast-xml-parser */ "./node_modules/fast-xml-parser/src/fxp.js"),

dist/cos-js-sdk-v5.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cos-js-sdk-v5",
3-
"version": "1.8.6",
3+
"version": "1.8.7",
44
"description": "JavaScript SDK for [腾讯云对象存储](https://cloud.tencent.com/product/cos)",
55
"main": "dist/cos-js-sdk-v5.js",
66
"types": "index.d.ts",
@@ -24,7 +24,7 @@
2424
},
2525
"homepage": "https://github.com/tencentyun/cos-js-sdk-v5#readme",
2626
"dependencies": {
27-
"fast-xml-parser": "^4.4.0"
27+
"fast-xml-parser": "4.5.0"
2828
},
2929
"devDependencies": {
3030
"@babel/core": "7.17.9",

src/base.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4153,6 +4153,8 @@ function _submitRequest(params, callback) {
41534153
params.AuthData.ClientIP && (opt.headers['clientIP'] = params.AuthData.ClientIP);
41544154
params.AuthData.ClientUA && (opt.headers['clientUA'] = params.AuthData.ClientUA);
41554155
params.AuthData.SecurityToken && (opt.headers[token] = params.AuthData.SecurityToken);
4156+
params.Action && (opt.action = params.Action);
4157+
opt.key = params.Key || params.ResourceKey;
41564158

41574159
// 清理 undefined 和 null 字段
41584160
opt.headers && (opt.headers = util.clearKey(opt.headers));

0 commit comments

Comments
 (0)