Skip to content

Commit

Permalink
Feat/1.4.9 (#161)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
livehigh authored Oct 20, 2022
1 parent d4d85c6 commit 10df7f7
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 31 deletions.
59 changes: 44 additions & 15 deletions dist/cos-js-sdk-v5.js
Original file line number Diff line number Diff line change
Expand Up @@ -7212,7 +7212,7 @@ module.exports = function(module) {
/*! exports provided: name, version, description, main, types, scripts, repository, keywords, author, license, bugs, homepage, dependencies, devDependencies, default */
/***/ (function(module) {

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\"}}");
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\"}}");

/***/ }),

Expand Down Expand Up @@ -11087,9 +11087,9 @@ function putObjectCopy(params, callback) {
return;
}

var SourceBucket = m[1];
var SourceRegion = m[3];
var SourceKey = decodeURIComponent(m[4]);
var SourceBucket = m.Bucket;
var SourceRegion = m.Region;
var SourceKey = decodeURIComponent(m.Key);
submitRequest.call(this, {
Scope: [{
action: 'name/cos:GetObject',
Expand Down Expand Up @@ -11138,9 +11138,9 @@ function uploadPartCopy(params, callback) {
return;
}

var SourceBucket = m[1];
var SourceRegion = m[3];
var SourceKey = decodeURIComponent(m[4]);
var SourceBucket = m.Bucket;
var SourceRegion = m.Region;
var SourceKey = decodeURIComponent(m.Key);
submitRequest.call(this, {
Scope: [{
action: 'name/cos:GetObject',
Expand Down Expand Up @@ -12130,6 +12130,11 @@ function getUrl(params) {
Bucket: longBucket,
Region: region
});
} // 兼容不带冒号的http、https


if (['http', 'https'].includes(params.protocol)) {
params.protocol = params.protocol + ':';
}

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

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

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

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

var BeaconAction = __webpack_require__(/*! ../lib/beacon.min */ "./lib/beacon.min.js");

var beacon = null;

var getBeacon = function getBeacon(delay) {
if (!beacon) {
// 不放在顶层是避免首次引入就被加载,从而避免在某些环境比如webworker里加载灯塔sdk内window相关对象报错
var BeaconAction = __webpack_require__(/*! ../lib/beacon.min */ "./lib/beacon.min.js");

beacon = new BeaconAction({
appkey: "0AND0VEVB24UBGDU",
versionCode: pkg.version,
Expand Down Expand Up @@ -14112,12 +14119,12 @@ var parseSelectPayload = function parseSelectPayload(chunk) {
var getSourceParams = function getSourceParams(source) {
var parser = this.options.CopySourceParser;
if (parser) return parser(source);
var m = source.match(/^([^.]+-\d+)\.cos(v6|-cdc)?\.([^.]+)\.myqcloud\.com\/(.+)$/);
var m = source.match(/^([^.]+-\d+)\.cos(v6|-cdc|-internal)?\.([^.]+)\.((myqcloud\.com)|(tencentcos\.cn))\/(.+)$/);
if (!m) return null;
return {
Bucket: m[1],
Region: m[3],
Key: m[4]
Key: m[7]
};
};

Expand Down Expand Up @@ -14584,7 +14591,7 @@ var apiWrapper = function apiWrapper(apiName, apiFn) {
};

var errMsg = checkParams();
var isSync = apiName === 'getAuth' || apiName === 'getObjectUrl';
var isSync = apiName === 'getAuth';

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

var isCIHost = function isCIHost(url) {
return /^https?:\/\/([^/]+\.)?ci\.[^/]+/.test(url);
};
}; //判断是否是ios


var isIOS = function () {
if ((typeof navigator === "undefined" ? "undefined" : _typeof(navigator)) !== 'object') {
return false;
}

var u = navigator.userAgent;
var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端

return isIOS;
}(); // 判断是qq内置浏览器


var isQQ = function () {
if ((typeof navigator === "undefined" ? "undefined" : _typeof(navigator)) !== 'object') {
return false;
}

return /\sQQ/i.test(navigator.userAgent);
}();

var util = {
noop: noop,
Expand Down Expand Up @@ -14760,7 +14788,8 @@ var util = {
getSourceParams: getSourceParams,
isBrowser: true,
isNode: isNode,
isCIHost: isCIHost
isCIHost: isCIHost,
isIOS_QQ: isIOS && isQQ
};
module.exports = util;
/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../node_modules/process/browser.js */ "./node_modules/process/browser.js")))
Expand Down
2 changes: 1 addition & 1 deletion dist/cos-js-sdk-v5.min.js

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ declare namespace COS {
ExpiredTime: number,
/** 该临时密钥是否仅用于相同 Scope 权限范围的请求 */
ScopeLimit?: boolean,
/** 签名 */
Authorization?: string,
}

/** 用于发请求的签名字符串,会放在请求 Header 里的 Authorization 字段 */
Expand Down Expand Up @@ -1272,7 +1274,9 @@ declare namespace COS {
Key: Key,
/** 要删除的对象版本 ID */
VersionId?: string
}[]
}[],
/** 是否启动 Quiet 模式 */
Quiet?: boolean,
}
/** deleteMultipleObject 接口返回值 */
interface DeleteMultipleObjectResult extends GeneralResult {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cos-js-sdk-v5",
"version": "1.4.8",
"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",
Expand Down
19 changes: 12 additions & 7 deletions src/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -2214,9 +2214,9 @@ function putObjectCopy(params, callback) {
return;
}

var SourceBucket = m[1];
var SourceRegion = m[3];
var SourceKey = decodeURIComponent(m[4]);
var SourceBucket = m.Bucket;
var SourceRegion = m.Region;
var SourceKey = decodeURIComponent(m.Key);

submitRequest.call(this, {
Scope: [{
Expand Down Expand Up @@ -2266,9 +2266,9 @@ function uploadPartCopy(params, callback) {
return;
}

var SourceBucket = m[1];
var SourceRegion = m[3];
var SourceKey = decodeURIComponent(m[4]);
var SourceBucket = m.Bucket;
var SourceRegion = m.Region;
var SourceKey = decodeURIComponent(m.Key);

submitRequest.call(this, {
Scope: [{
Expand Down Expand Up @@ -3190,6 +3190,10 @@ function getUrl(params) {
if (typeof domain === 'function') {
domain = domain({Bucket: longBucket, Region: region});
}
// 兼容不带冒号的http、https
if (['http', 'https'].includes(params.protocol)) {
params.protocol = params.protocol + ':';
}
var protocol = params.protocol || (util.isBrowser && location.protocol === 'http:' ? 'http:' : 'https:');
if (!domain) {
if (['cn-south', 'cn-south-2', 'cn-north', 'cn-east', 'cn-southwest', 'sg'].indexOf(region) > -1) {
Expand Down Expand Up @@ -3578,7 +3582,8 @@ function _submitRequest(params, callback) {
object: object,
});
if (params.action) {
url = url + '?' + params.action;
// 已知问题,某些版本的qq会对url自动拼接(比如/upload被拼接成/upload=(null))导致签名错误,这里做下兼容。
url = url + '?' + (util.isIOS_QQ ? `${params.action}=` : params.action);
}
if (params.qsStr) {
if(url.indexOf('?') > -1){
Expand Down
3 changes: 2 additions & 1 deletion src/tracker.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@

const pkg = require('../package.json');
const BeaconAction = require('../lib/beacon.min');
let beacon = null;

const getBeacon = (delay) => {
if (!beacon) {
// 不放在顶层是避免首次引入就被加载,从而避免在某些环境比如webworker里加载灯塔sdk内window相关对象报错
const BeaconAction = require('../lib/beacon.min');
beacon = new BeaconAction({
appkey: "0AND0VEVB24UBGDU",
versionCode: pkg.version,
Expand Down
27 changes: 22 additions & 5 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@ var parseSelectPayload = function (chunk) {
var getSourceParams = function (source) {
var parser = this.options.CopySourceParser;
if (parser) return parser(source);
var m = source.match(/^([^.]+-\d+)\.cos(v6|-cdc)?\.([^.]+)\.myqcloud\.com\/(.+)$/);
var m = source.match(/^([^.]+-\d+)\.cos(v6|-cdc|-internal)?\.([^.]+)\.((myqcloud\.com)|(tencentcos\.cn))\/(.+)$/);
if (!m) return null;
return { Bucket: m[1], Region: m[3], Key: m[4] };
return { Bucket: m[1], Region: m[3], Key: m[7] };
};

var noop = function () {
Expand Down Expand Up @@ -631,7 +631,7 @@ var apiWrapper = function (apiName, apiFn) {
};

var errMsg = checkParams();
var isSync = apiName === 'getAuth' || apiName === 'getObjectUrl';
var isSync = apiName === 'getAuth';
if (typeof Promise === 'function' && !isSync && !callback) {
return new Promise(function (resolve, reject) {
callback = function (err, data) {
Expand Down Expand Up @@ -750,12 +750,28 @@ var isNode = function () {
return typeof window !== 'object' && typeof process === 'object' && typeof require === 'function' && !isWebWorker();
}



var isCIHost = function(url) {
return /^https?:\/\/([^/]+\.)?ci\.[^/]+/.test(url);
}

//判断是否是ios
var isIOS = (function(){
if (typeof navigator !== 'object') {
return false;
}
var u = navigator.userAgent;
var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
return isIOS;
})();

// 判断是qq内置浏览器
var isQQ = (function () {
if (typeof navigator !== 'object') {
return false;
}
return /\sQQ/i.test(navigator.userAgent)
})();

var util = {
noop: noop,
formatParams: formatParams,
Expand Down Expand Up @@ -790,6 +806,7 @@ var util = {
isBrowser: true,
isNode: isNode,
isCIHost: isCIHost,
isIOS_QQ: isIOS && isQQ,
};

module.exports = util;

0 comments on commit 10df7f7

Please sign in to comment.