Skip to content

Commit

Permalink
Dev/1.4.19 (#192)
Browse files Browse the repository at this point in the history
* feat: 支持postBucketInventory;优化d.ts

* fix: 修复单测

* dev/demo (merge request !15)

Squash merge branch 'dev/demo' into 'master'
Merge branch 'master' into dev/demo

* feat: 1、新增base64方法 2、优化d.ts
  • Loading branch information
livehigh authored Aug 3, 2023
1 parent f1be36f commit b2c71b5
Show file tree
Hide file tree
Showing 10 changed files with 378 additions and 12 deletions.
2 changes: 1 addition & 1 deletion demo/ciDemo.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,8 @@ function postTextAuditing() {
var body = COS.util.json2xml({
Request: {
Input: {
Content: COS.util.encodeBase64('乳沟'), // 经过base64编码过的文本”乳沟“,查询结果同步返回
// Object: 'hello.txt', // 存在cos里的资源,审核结果异步返回,可以调用查询文本审核结果api查询
Content: '5Lmz5rKf', // 经过base64编码过的文本”乳沟“,查询结果同步返回
},
Conf: {
BizType: '',
Expand Down
1 change: 1 addition & 0 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ <h1>cos-js-sdk-v5
window.cos = cos;
window.util = util;
window.logger = logger;
window.camSafeUrlEncode = camSafeUrlEncode;
})();
</script>

Expand Down
185 changes: 180 additions & 5 deletions dist/cos-js-sdk-v5.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,167 @@ module.exports = COS;

/***/ }),

/***/ "./lib/base64.js":
/*!***********************!*\
!*** ./lib/base64.js ***!
\***********************/
/*! no static exports found */
/***/ (function(module, exports) {

/*
* $Id: base64.js,v 2.15 2014/04/05 12:58:57 dankogai Exp dankogai $
*
* Licensed under the BSD 3-Clause License.
* http://opensource.org/licenses/BSD-3-Clause
*
* References:
* http://en.wikipedia.org/wiki/Base64
*/
var Base64 = function (global) {
global = global || {};
'use strict'; // existing version for noConflict()


var _Base64 = global.Base64;
var version = "2.1.9"; // if node.js, we use Buffer

var buffer; // constants

var b64chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';

var b64tab = function (bin) {
var t = {};

for (var i = 0, l = bin.length; i < l; i++) {
t[bin.charAt(i)] = i;
}

return t;
}(b64chars);

var fromCharCode = String.fromCharCode; // encoder stuff

var cb_utob = function cb_utob(c) {
if (c.length < 2) {
var cc = c.charCodeAt(0);
return cc < 0x80 ? c : cc < 0x800 ? fromCharCode(0xc0 | cc >>> 6) + fromCharCode(0x80 | cc & 0x3f) : fromCharCode(0xe0 | cc >>> 12 & 0x0f) + fromCharCode(0x80 | cc >>> 6 & 0x3f) + fromCharCode(0x80 | cc & 0x3f);
} else {
var cc = 0x10000 + (c.charCodeAt(0) - 0xD800) * 0x400 + (c.charCodeAt(1) - 0xDC00);
return fromCharCode(0xf0 | cc >>> 18 & 0x07) + fromCharCode(0x80 | cc >>> 12 & 0x3f) + fromCharCode(0x80 | cc >>> 6 & 0x3f) + fromCharCode(0x80 | cc & 0x3f);
}
};

var re_utob = /[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g;

var utob = function utob(u) {
return u.replace(re_utob, cb_utob);
};

var cb_encode = function cb_encode(ccc) {
var padlen = [0, 2, 1][ccc.length % 3],
ord = ccc.charCodeAt(0) << 16 | (ccc.length > 1 ? ccc.charCodeAt(1) : 0) << 8 | (ccc.length > 2 ? ccc.charCodeAt(2) : 0),
chars = [b64chars.charAt(ord >>> 18), b64chars.charAt(ord >>> 12 & 63), padlen >= 2 ? '=' : b64chars.charAt(ord >>> 6 & 63), padlen >= 1 ? '=' : b64chars.charAt(ord & 63)];
return chars.join('');
};

var btoa = global.btoa ? function (b) {
return global.btoa(b);
} : function (b) {
return b.replace(/[\s\S]{1,3}/g, cb_encode);
};

var _encode = buffer ? function (u) {
return (u.constructor === buffer.constructor ? u : new buffer(u)).toString('base64');
} : function (u) {
return btoa(utob(u));
};

var encode = function encode(u, urisafe) {
return !urisafe ? _encode(String(u)) : _encode(String(u)).replace(/[+\/]/g, function (m0) {
return m0 == '+' ? '-' : '_';
}).replace(/=/g, '');
};

var encodeURI = function encodeURI(u) {
return encode(u, true);
}; // decoder stuff


var re_btou = new RegExp(['[\xC0-\xDF][\x80-\xBF]', '[\xE0-\xEF][\x80-\xBF]{2}', '[\xF0-\xF7][\x80-\xBF]{3}'].join('|'), 'g');

var cb_btou = function cb_btou(cccc) {
switch (cccc.length) {
case 4:
var cp = (0x07 & cccc.charCodeAt(0)) << 18 | (0x3f & cccc.charCodeAt(1)) << 12 | (0x3f & cccc.charCodeAt(2)) << 6 | 0x3f & cccc.charCodeAt(3),
offset = cp - 0x10000;
return fromCharCode((offset >>> 10) + 0xD800) + fromCharCode((offset & 0x3FF) + 0xDC00);

case 3:
return fromCharCode((0x0f & cccc.charCodeAt(0)) << 12 | (0x3f & cccc.charCodeAt(1)) << 6 | 0x3f & cccc.charCodeAt(2));

default:
return fromCharCode((0x1f & cccc.charCodeAt(0)) << 6 | 0x3f & cccc.charCodeAt(1));
}
};

var btou = function btou(b) {
return b.replace(re_btou, cb_btou);
};

var cb_decode = function cb_decode(cccc) {
var len = cccc.length,
padlen = len % 4,
n = (len > 0 ? b64tab[cccc.charAt(0)] << 18 : 0) | (len > 1 ? b64tab[cccc.charAt(1)] << 12 : 0) | (len > 2 ? b64tab[cccc.charAt(2)] << 6 : 0) | (len > 3 ? b64tab[cccc.charAt(3)] : 0),
chars = [fromCharCode(n >>> 16), fromCharCode(n >>> 8 & 0xff), fromCharCode(n & 0xff)];
chars.length -= [0, 0, 2, 1][padlen];
return chars.join('');
};

var atob = global.atob ? function (a) {
return global.atob(a);
} : function (a) {
return a.replace(/[\s\S]{1,4}/g, cb_decode);
};

var _decode = buffer ? function (a) {
return (a.constructor === buffer.constructor ? a : new buffer(a, 'base64')).toString();
} : function (a) {
return btou(atob(a));
};

var decode = function decode(a) {
return _decode(String(a).replace(/[-_]/g, function (m0) {
return m0 == '-' ? '+' : '/';
}).replace(/[^A-Za-z0-9\+\/]/g, ''));
};

var noConflict = function noConflict() {
var Base64 = global.Base64;
global.Base64 = _Base64;
return Base64;
}; // export Base64


var Base64 = {
VERSION: version,
atob: atob,
btoa: btoa,
fromBase64: decode,
toBase64: encode,
utob: utob,
encode: encode,
encodeURI: encodeURI,
btou: btou,
decode: decode,
noConflict: noConflict
};
return Base64;
}();

module.exports = Base64;

/***/ }),

/***/ "./lib/beacon.min.js":
/*!***************************!*\
!*** ./lib/beacon.min.js ***!
Expand Down Expand Up @@ -6948,7 +7109,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.18\",\"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 test/test.js server/sts.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\":{\"@xmldom/xmldom\":\"^0.8.6\"},\"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\":\"2.8.8\",\"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\"}}");
module.exports = JSON.parse("{\"name\":\"cos-js-sdk-v5\",\"version\":\"1.4.19\",\"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 test/test.js server/sts.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\":{\"@xmldom/xmldom\":\"^0.8.6\"},\"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\"}}");

/***/ }),

Expand Down Expand Up @@ -10061,15 +10222,15 @@ function submitBucketInventory(method, params, callback) {
}
/**
* 创建一个清单任务
*/
*/


function putBucketInventory(params, callback) {
return submitBucketInventory.call(this, 'PUT', params, callback);
}
/**
* 创建一个一次性清单任务 会立即执行
*/
*/


function postBucketInventory(params, callback) {
Expand Down Expand Up @@ -12717,7 +12878,8 @@ advance.init(COS, task);
COS.util = {
md5: util.md5,
xml2json: util.xml2json,
json2xml: util.json2xml
json2xml: util.json2xml,
encodeBase64: util.encodeBase64
};
COS.getAuthorization = util.getAuth;
COS.version = pkg.version;
Expand Down Expand Up @@ -13682,6 +13844,8 @@ var xml2json = __webpack_require__(/*! ../lib/xml2json */ "./lib/xml2json.js");

var json2xml = __webpack_require__(/*! ../lib/json2xml */ "./lib/json2xml.js");

var base64 = __webpack_require__(/*! ../lib/base64 */ "./lib/base64.js");

var Tracker = __webpack_require__(/*! ./tracker */ "./src/tracker.js");

function camSafeUrlEncode(str) {
Expand Down Expand Up @@ -14512,6 +14676,16 @@ var isQQ = function () {
return /\sQQ/i.test(navigator.userAgent);
}();

var encodeBase64 = function encodeBase64(str, safe) {
var base64Str = base64.encode(str); // 万象使用的安全base64格式需要特殊处理

if (safe) {
base64Str = base64Str.replaceAll('+', '-').replaceAll('/', '_').replaceAll('=', '');
}

return base64Str;
};

var util = {
noop: noop,
formatParams: formatParams,
Expand Down Expand Up @@ -14546,7 +14720,8 @@ var util = {
isBrowser: true,
isNode: isNode,
isCIHost: isCIHost,
isIOS_QQ: isIOS && isQQ
isIOS_QQ: isIOS && isQQ,
encodeBase64: encodeBase64
};
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.

11 changes: 9 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ declare namespace COS {
| 'public-read'
| 'authenticated-read'
| 'bucket-owner-read'
| 'bucket-owner-full-contro';
| 'bucket-owner-full-control';
/** 二进制值的字符串,'true' | 'false' */
type BooleanString = 'true' | 'false';
/** 所有者的信息 */
Expand Down Expand Up @@ -207,6 +207,7 @@ declare namespace COS {
md5: (str: String, encoding?: string) => string;
xml2json: (bodyStr: string) => any;
json2xml: (json: any) => string;
encodeBase64: (str: string, safe?: boolean) => string;
}

interface StaticGetAuthorizationOptions {
Expand Down Expand Up @@ -1506,7 +1507,13 @@ Bulk:批量模式,恢复时间为24 - 48小时。 */
'x-cos-meta-*'?: string;
}
/** putObjectCopy 接口返回值 */
interface PutObjectCopyResult extends GeneralResult {}
interface PutObjectCopyResult extends GeneralResult {
ETag: string;
CRC64: string;
LastModified: string;
VersionId: string;
Location: Location;
}

// putObjectTagging
/** putObjectTagging 接口参数 */
Expand Down
Loading

0 comments on commit b2c71b5

Please sign in to comment.