Skip to content

Commit 10df7f7

Browse files
authored
Feat/1.4.9 (#161)
* fix 1.4.8 * upd * feat:1.4.9 1、修复getSourceParams使用不当部分 2、protocol兼容不带冒号的http、https 3、合法域名校验支持cos内网、cn域名 4、d.ts补充 * upd:ios qq里兼容处理 * upd tracker
1 parent d4d85c6 commit 10df7f7

File tree

7 files changed

+87
-31
lines changed

7 files changed

+87
-31
lines changed

dist/cos-js-sdk-v5.js

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7212,7 +7212,7 @@ module.exports = function(module) {
72127212
/*! exports provided: name, version, description, main, types, scripts, repository, keywords, author, license, bugs, homepage, dependencies, devDependencies, default */
72137213
/***/ (function(module) {
72147214

7215-
module.exports = JSON.parse("{\"name\":\"cos-js-sdk-v5\",\"version\":\"1.4.8\",\"description\":\"JavaScript SDK for [腾讯云对象存储](https://cloud.tencent.com/product/cos)\",\"main\":\"dist/cos-js-sdk-v5.js\",\"types\":\"index.d.ts\",\"scripts\":{\"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\"},\"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\":{\"@xmldom/xmldom\":\"^0.8.2\"},\"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\",\"qcloud-cos-sts\":\"^3.0.2\",\"request\":\"^2.87.0\",\"terser-webpack-plugin\":\"4.2.3\",\"webpack\":\"4.46.0\",\"webpack-cli\":\"4.10.0\"}}");
7215+
module.exports = JSON.parse("{\"name\":\"cos-js-sdk-v5\",\"version\":\"1.4.9\",\"description\":\"JavaScript SDK for [腾讯云对象存储](https://cloud.tencent.com/product/cos)\",\"main\":\"dist/cos-js-sdk-v5.js\",\"types\":\"index.d.ts\",\"scripts\":{\"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\"},\"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\":{\"@xmldom/xmldom\":\"^0.8.2\"},\"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\",\"qcloud-cos-sts\":\"^3.0.2\",\"request\":\"^2.87.0\",\"terser-webpack-plugin\":\"4.2.3\",\"webpack\":\"4.46.0\",\"webpack-cli\":\"4.10.0\"}}");
72167216

72177217
/***/ }),
72187218

@@ -11087,9 +11087,9 @@ function putObjectCopy(params, callback) {
1108711087
return;
1108811088
}
1108911089

11090-
var SourceBucket = m[1];
11091-
var SourceRegion = m[3];
11092-
var SourceKey = decodeURIComponent(m[4]);
11090+
var SourceBucket = m.Bucket;
11091+
var SourceRegion = m.Region;
11092+
var SourceKey = decodeURIComponent(m.Key);
1109311093
submitRequest.call(this, {
1109411094
Scope: [{
1109511095
action: 'name/cos:GetObject',
@@ -11138,9 +11138,9 @@ function uploadPartCopy(params, callback) {
1113811138
return;
1113911139
}
1114011140

11141-
var SourceBucket = m[1];
11142-
var SourceRegion = m[3];
11143-
var SourceKey = decodeURIComponent(m[4]);
11141+
var SourceBucket = m.Bucket;
11142+
var SourceRegion = m.Region;
11143+
var SourceKey = decodeURIComponent(m.Key);
1114411144
submitRequest.call(this, {
1114511145
Scope: [{
1114611146
action: 'name/cos:GetObject',
@@ -12130,6 +12130,11 @@ function getUrl(params) {
1213012130
Bucket: longBucket,
1213112131
Region: region
1213212132
});
12133+
} // 兼容不带冒号的http、https
12134+
12135+
12136+
if (['http', 'https'].includes(params.protocol)) {
12137+
params.protocol = params.protocol + ':';
1213312138
}
1213412139

1213512140
var protocol = params.protocol || (util.isBrowser && location.protocol === 'http:' ? 'http:' : 'https:');
@@ -12550,7 +12555,8 @@ function _submitRequest(params, callback) {
1255012555
});
1255112556

1255212557
if (params.action) {
12553-
url = url + '?' + params.action;
12558+
// 已知问题,某些版本的qq会对url自动拼接(比如/upload被拼接成/upload=(null))导致签名错误,这里做下兼容。
12559+
url = url + '?' + (util.isIOS_QQ ? "".concat(params.action, "=") : params.action);
1255412560
}
1255512561

1255612562
if (params.qsStr) {
@@ -13462,12 +13468,13 @@ var _typeof = __webpack_require__(/*! @babel/runtime/helpers/typeof */ "./node_m
1346213468

1346313469
var pkg = __webpack_require__(/*! ../package.json */ "./package.json");
1346413470

13465-
var BeaconAction = __webpack_require__(/*! ../lib/beacon.min */ "./lib/beacon.min.js");
13466-
1346713471
var beacon = null;
1346813472

1346913473
var getBeacon = function getBeacon(delay) {
1347013474
if (!beacon) {
13475+
// 不放在顶层是避免首次引入就被加载,从而避免在某些环境比如webworker里加载灯塔sdk内window相关对象报错
13476+
var BeaconAction = __webpack_require__(/*! ../lib/beacon.min */ "./lib/beacon.min.js");
13477+
1347113478
beacon = new BeaconAction({
1347213479
appkey: "0AND0VEVB24UBGDU",
1347313480
versionCode: pkg.version,
@@ -14112,12 +14119,12 @@ var parseSelectPayload = function parseSelectPayload(chunk) {
1411214119
var getSourceParams = function getSourceParams(source) {
1411314120
var parser = this.options.CopySourceParser;
1411414121
if (parser) return parser(source);
14115-
var m = source.match(/^([^.]+-\d+)\.cos(v6|-cdc)?\.([^.]+)\.myqcloud\.com\/(.+)$/);
14122+
var m = source.match(/^([^.]+-\d+)\.cos(v6|-cdc|-internal)?\.([^.]+)\.((myqcloud\.com)|(tencentcos\.cn))\/(.+)$/);
1411614123
if (!m) return null;
1411714124
return {
1411814125
Bucket: m[1],
1411914126
Region: m[3],
14120-
Key: m[4]
14127+
Key: m[7]
1412114128
};
1412214129
};
1412314130

@@ -14584,7 +14591,7 @@ var apiWrapper = function apiWrapper(apiName, apiFn) {
1458414591
};
1458514592

1458614593
var errMsg = checkParams();
14587-
var isSync = apiName === 'getAuth' || apiName === 'getObjectUrl';
14594+
var isSync = apiName === 'getAuth';
1458814595

1458914596
if (typeof Promise === 'function' && !isSync && !callback) {
1459014597
return new Promise(function (resolve, reject) {
@@ -14725,7 +14732,28 @@ var isNode = function isNode() {
1472514732

1472614733
var isCIHost = function isCIHost(url) {
1472714734
return /^https?:\/\/([^/]+\.)?ci\.[^/]+/.test(url);
14728-
};
14735+
}; //判断是否是ios
14736+
14737+
14738+
var isIOS = function () {
14739+
if ((typeof navigator === "undefined" ? "undefined" : _typeof(navigator)) !== 'object') {
14740+
return false;
14741+
}
14742+
14743+
var u = navigator.userAgent;
14744+
var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
14745+
14746+
return isIOS;
14747+
}(); // 判断是qq内置浏览器
14748+
14749+
14750+
var isQQ = function () {
14751+
if ((typeof navigator === "undefined" ? "undefined" : _typeof(navigator)) !== 'object') {
14752+
return false;
14753+
}
14754+
14755+
return /\sQQ/i.test(navigator.userAgent);
14756+
}();
1472914757

1473014758
var util = {
1473114759
noop: noop,
@@ -14760,7 +14788,8 @@ var util = {
1476014788
getSourceParams: getSourceParams,
1476114789
isBrowser: true,
1476214790
isNode: isNode,
14763-
isCIHost: isCIHost
14791+
isCIHost: isCIHost,
14792+
isIOS_QQ: isIOS && isQQ
1476414793
};
1476514794
module.exports = util;
1476614795
/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../node_modules/process/browser.js */ "./node_modules/process/browser.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.

index.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ declare namespace COS {
259259
ExpiredTime: number,
260260
/** 该临时密钥是否仅用于相同 Scope 权限范围的请求 */
261261
ScopeLimit?: boolean,
262+
/** 签名 */
263+
Authorization?: string,
262264
}
263265

264266
/** 用于发请求的签名字符串,会放在请求 Header 里的 Authorization 字段 */
@@ -1272,7 +1274,9 @@ declare namespace COS {
12721274
Key: Key,
12731275
/** 要删除的对象版本 ID */
12741276
VersionId?: string
1275-
}[]
1277+
}[],
1278+
/** 是否启动 Quiet 模式 */
1279+
Quiet?: boolean,
12761280
}
12771281
/** deleteMultipleObject 接口返回值 */
12781282
interface DeleteMultipleObjectResult extends GeneralResult {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cos-js-sdk-v5",
3-
"version": "1.4.8",
3+
"version": "1.4.9",
44
"description": "JavaScript SDK for [腾讯云对象存储](https://cloud.tencent.com/product/cos)",
55
"main": "dist/cos-js-sdk-v5.js",
66
"types": "index.d.ts",

src/base.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2214,9 +2214,9 @@ function putObjectCopy(params, callback) {
22142214
return;
22152215
}
22162216

2217-
var SourceBucket = m[1];
2218-
var SourceRegion = m[3];
2219-
var SourceKey = decodeURIComponent(m[4]);
2217+
var SourceBucket = m.Bucket;
2218+
var SourceRegion = m.Region;
2219+
var SourceKey = decodeURIComponent(m.Key);
22202220

22212221
submitRequest.call(this, {
22222222
Scope: [{
@@ -2266,9 +2266,9 @@ function uploadPartCopy(params, callback) {
22662266
return;
22672267
}
22682268

2269-
var SourceBucket = m[1];
2270-
var SourceRegion = m[3];
2271-
var SourceKey = decodeURIComponent(m[4]);
2269+
var SourceBucket = m.Bucket;
2270+
var SourceRegion = m.Region;
2271+
var SourceKey = decodeURIComponent(m.Key);
22722272

22732273
submitRequest.call(this, {
22742274
Scope: [{
@@ -3190,6 +3190,10 @@ function getUrl(params) {
31903190
if (typeof domain === 'function') {
31913191
domain = domain({Bucket: longBucket, Region: region});
31923192
}
3193+
// 兼容不带冒号的http、https
3194+
if (['http', 'https'].includes(params.protocol)) {
3195+
params.protocol = params.protocol + ':';
3196+
}
31933197
var protocol = params.protocol || (util.isBrowser && location.protocol === 'http:' ? 'http:' : 'https:');
31943198
if (!domain) {
31953199
if (['cn-south', 'cn-south-2', 'cn-north', 'cn-east', 'cn-southwest', 'sg'].indexOf(region) > -1) {
@@ -3578,7 +3582,8 @@ function _submitRequest(params, callback) {
35783582
object: object,
35793583
});
35803584
if (params.action) {
3581-
url = url + '?' + params.action;
3585+
// 已知问题,某些版本的qq会对url自动拼接(比如/upload被拼接成/upload=(null))导致签名错误,这里做下兼容。
3586+
url = url + '?' + (util.isIOS_QQ ? `${params.action}=` : params.action);
35823587
}
35833588
if (params.qsStr) {
35843589
if(url.indexOf('?') > -1){

src/tracker.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11

22
const pkg = require('../package.json');
3-
const BeaconAction = require('../lib/beacon.min');
43
let beacon = null;
54

65
const getBeacon = (delay) => {
76
if (!beacon) {
7+
// 不放在顶层是避免首次引入就被加载,从而避免在某些环境比如webworker里加载灯塔sdk内window相关对象报错
8+
const BeaconAction = require('../lib/beacon.min');
89
beacon = new BeaconAction({
910
appkey: "0AND0VEVB24UBGDU",
1011
versionCode: pkg.version,

src/util.js

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,9 @@ var parseSelectPayload = function (chunk) {
205205
var getSourceParams = function (source) {
206206
var parser = this.options.CopySourceParser;
207207
if (parser) return parser(source);
208-
var m = source.match(/^([^.]+-\d+)\.cos(v6|-cdc)?\.([^.]+)\.myqcloud\.com\/(.+)$/);
208+
var m = source.match(/^([^.]+-\d+)\.cos(v6|-cdc|-internal)?\.([^.]+)\.((myqcloud\.com)|(tencentcos\.cn))\/(.+)$/);
209209
if (!m) return null;
210-
return { Bucket: m[1], Region: m[3], Key: m[4] };
210+
return { Bucket: m[1], Region: m[3], Key: m[7] };
211211
};
212212

213213
var noop = function () {
@@ -631,7 +631,7 @@ var apiWrapper = function (apiName, apiFn) {
631631
};
632632

633633
var errMsg = checkParams();
634-
var isSync = apiName === 'getAuth' || apiName === 'getObjectUrl';
634+
var isSync = apiName === 'getAuth';
635635
if (typeof Promise === 'function' && !isSync && !callback) {
636636
return new Promise(function (resolve, reject) {
637637
callback = function (err, data) {
@@ -750,12 +750,28 @@ var isNode = function () {
750750
return typeof window !== 'object' && typeof process === 'object' && typeof require === 'function' && !isWebWorker();
751751
}
752752

753-
754-
755753
var isCIHost = function(url) {
756754
return /^https?:\/\/([^/]+\.)?ci\.[^/]+/.test(url);
757755
}
758756

757+
//判断是否是ios
758+
var isIOS = (function(){
759+
if (typeof navigator !== 'object') {
760+
return false;
761+
}
762+
var u = navigator.userAgent;
763+
var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
764+
return isIOS;
765+
})();
766+
767+
// 判断是qq内置浏览器
768+
var isQQ = (function () {
769+
if (typeof navigator !== 'object') {
770+
return false;
771+
}
772+
return /\sQQ/i.test(navigator.userAgent)
773+
})();
774+
759775
var util = {
760776
noop: noop,
761777
formatParams: formatParams,
@@ -790,6 +806,7 @@ var util = {
790806
isBrowser: true,
791807
isNode: isNode,
792808
isCIHost: isCIHost,
809+
isIOS_QQ: isIOS && isQQ,
793810
};
794811

795812
module.exports = util;

0 commit comments

Comments
 (0)