Skip to content

Commit b2c71b5

Browse files
authored
Dev/1.4.19 (#192)
* 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
1 parent f1be36f commit b2c71b5

File tree

10 files changed

+378
-12
lines changed

10 files changed

+378
-12
lines changed

demo/ciDemo.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,8 +419,8 @@ function postTextAuditing() {
419419
var body = COS.util.json2xml({
420420
Request: {
421421
Input: {
422+
Content: COS.util.encodeBase64('乳沟'), // 经过base64编码过的文本”乳沟“,查询结果同步返回
422423
// Object: 'hello.txt', // 存在cos里的资源,审核结果异步返回,可以调用查询文本审核结果api查询
423-
Content: '5Lmz5rKf', // 经过base64编码过的文本”乳沟“,查询结果同步返回
424424
},
425425
Conf: {
426426
BizType: '',

demo/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ <h1>cos-js-sdk-v5
259259
window.cos = cos;
260260
window.util = util;
261261
window.logger = logger;
262+
window.camSafeUrlEncode = camSafeUrlEncode;
262263
})();
263264
</script>
264265

dist/cos-js-sdk-v5.js

Lines changed: 180 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,167 @@ module.exports = COS;
109109

110110
/***/ }),
111111

112+
/***/ "./lib/base64.js":
113+
/*!***********************!*\
114+
!*** ./lib/base64.js ***!
115+
\***********************/
116+
/*! no static exports found */
117+
/***/ (function(module, exports) {
118+
119+
/*
120+
* $Id: base64.js,v 2.15 2014/04/05 12:58:57 dankogai Exp dankogai $
121+
*
122+
* Licensed under the BSD 3-Clause License.
123+
* http://opensource.org/licenses/BSD-3-Clause
124+
*
125+
* References:
126+
* http://en.wikipedia.org/wiki/Base64
127+
*/
128+
var Base64 = function (global) {
129+
global = global || {};
130+
'use strict'; // existing version for noConflict()
131+
132+
133+
var _Base64 = global.Base64;
134+
var version = "2.1.9"; // if node.js, we use Buffer
135+
136+
var buffer; // constants
137+
138+
var b64chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
139+
140+
var b64tab = function (bin) {
141+
var t = {};
142+
143+
for (var i = 0, l = bin.length; i < l; i++) {
144+
t[bin.charAt(i)] = i;
145+
}
146+
147+
return t;
148+
}(b64chars);
149+
150+
var fromCharCode = String.fromCharCode; // encoder stuff
151+
152+
var cb_utob = function cb_utob(c) {
153+
if (c.length < 2) {
154+
var cc = c.charCodeAt(0);
155+
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);
156+
} else {
157+
var cc = 0x10000 + (c.charCodeAt(0) - 0xD800) * 0x400 + (c.charCodeAt(1) - 0xDC00);
158+
return fromCharCode(0xf0 | cc >>> 18 & 0x07) + fromCharCode(0x80 | cc >>> 12 & 0x3f) + fromCharCode(0x80 | cc >>> 6 & 0x3f) + fromCharCode(0x80 | cc & 0x3f);
159+
}
160+
};
161+
162+
var re_utob = /[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g;
163+
164+
var utob = function utob(u) {
165+
return u.replace(re_utob, cb_utob);
166+
};
167+
168+
var cb_encode = function cb_encode(ccc) {
169+
var padlen = [0, 2, 1][ccc.length % 3],
170+
ord = ccc.charCodeAt(0) << 16 | (ccc.length > 1 ? ccc.charCodeAt(1) : 0) << 8 | (ccc.length > 2 ? ccc.charCodeAt(2) : 0),
171+
chars = [b64chars.charAt(ord >>> 18), b64chars.charAt(ord >>> 12 & 63), padlen >= 2 ? '=' : b64chars.charAt(ord >>> 6 & 63), padlen >= 1 ? '=' : b64chars.charAt(ord & 63)];
172+
return chars.join('');
173+
};
174+
175+
var btoa = global.btoa ? function (b) {
176+
return global.btoa(b);
177+
} : function (b) {
178+
return b.replace(/[\s\S]{1,3}/g, cb_encode);
179+
};
180+
181+
var _encode = buffer ? function (u) {
182+
return (u.constructor === buffer.constructor ? u : new buffer(u)).toString('base64');
183+
} : function (u) {
184+
return btoa(utob(u));
185+
};
186+
187+
var encode = function encode(u, urisafe) {
188+
return !urisafe ? _encode(String(u)) : _encode(String(u)).replace(/[+\/]/g, function (m0) {
189+
return m0 == '+' ? '-' : '_';
190+
}).replace(/=/g, '');
191+
};
192+
193+
var encodeURI = function encodeURI(u) {
194+
return encode(u, true);
195+
}; // decoder stuff
196+
197+
198+
var re_btou = new RegExp(['[\xC0-\xDF][\x80-\xBF]', '[\xE0-\xEF][\x80-\xBF]{2}', '[\xF0-\xF7][\x80-\xBF]{3}'].join('|'), 'g');
199+
200+
var cb_btou = function cb_btou(cccc) {
201+
switch (cccc.length) {
202+
case 4:
203+
var cp = (0x07 & cccc.charCodeAt(0)) << 18 | (0x3f & cccc.charCodeAt(1)) << 12 | (0x3f & cccc.charCodeAt(2)) << 6 | 0x3f & cccc.charCodeAt(3),
204+
offset = cp - 0x10000;
205+
return fromCharCode((offset >>> 10) + 0xD800) + fromCharCode((offset & 0x3FF) + 0xDC00);
206+
207+
case 3:
208+
return fromCharCode((0x0f & cccc.charCodeAt(0)) << 12 | (0x3f & cccc.charCodeAt(1)) << 6 | 0x3f & cccc.charCodeAt(2));
209+
210+
default:
211+
return fromCharCode((0x1f & cccc.charCodeAt(0)) << 6 | 0x3f & cccc.charCodeAt(1));
212+
}
213+
};
214+
215+
var btou = function btou(b) {
216+
return b.replace(re_btou, cb_btou);
217+
};
218+
219+
var cb_decode = function cb_decode(cccc) {
220+
var len = cccc.length,
221+
padlen = len % 4,
222+
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),
223+
chars = [fromCharCode(n >>> 16), fromCharCode(n >>> 8 & 0xff), fromCharCode(n & 0xff)];
224+
chars.length -= [0, 0, 2, 1][padlen];
225+
return chars.join('');
226+
};
227+
228+
var atob = global.atob ? function (a) {
229+
return global.atob(a);
230+
} : function (a) {
231+
return a.replace(/[\s\S]{1,4}/g, cb_decode);
232+
};
233+
234+
var _decode = buffer ? function (a) {
235+
return (a.constructor === buffer.constructor ? a : new buffer(a, 'base64')).toString();
236+
} : function (a) {
237+
return btou(atob(a));
238+
};
239+
240+
var decode = function decode(a) {
241+
return _decode(String(a).replace(/[-_]/g, function (m0) {
242+
return m0 == '-' ? '+' : '/';
243+
}).replace(/[^A-Za-z0-9\+\/]/g, ''));
244+
};
245+
246+
var noConflict = function noConflict() {
247+
var Base64 = global.Base64;
248+
global.Base64 = _Base64;
249+
return Base64;
250+
}; // export Base64
251+
252+
253+
var Base64 = {
254+
VERSION: version,
255+
atob: atob,
256+
btoa: btoa,
257+
fromBase64: decode,
258+
toBase64: encode,
259+
utob: utob,
260+
encode: encode,
261+
encodeURI: encodeURI,
262+
btou: btou,
263+
decode: decode,
264+
noConflict: noConflict
265+
};
266+
return Base64;
267+
}();
268+
269+
module.exports = Base64;
270+
271+
/***/ }),
272+
112273
/***/ "./lib/beacon.min.js":
113274
/*!***************************!*\
114275
!*** ./lib/beacon.min.js ***!
@@ -6948,7 +7109,7 @@ module.exports = function(module) {
69487109
/*! exports provided: name, version, description, main, types, scripts, repository, keywords, author, license, bugs, homepage, dependencies, devDependencies, default */
69497110
/***/ (function(module) {
69507111

6951-
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\"}}");
7112+
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\"}}");
69527113

69537114
/***/ }),
69547115

@@ -10061,15 +10222,15 @@ function submitBucketInventory(method, params, callback) {
1006110222
}
1006210223
/**
1006310224
* 创建一个清单任务
10064-
*/
10225+
*/
1006510226

1006610227

1006710228
function putBucketInventory(params, callback) {
1006810229
return submitBucketInventory.call(this, 'PUT', params, callback);
1006910230
}
1007010231
/**
1007110232
* 创建一个一次性清单任务 会立即执行
10072-
*/
10233+
*/
1007310234

1007410235

1007510236
function postBucketInventory(params, callback) {
@@ -12717,7 +12878,8 @@ advance.init(COS, task);
1271712878
COS.util = {
1271812879
md5: util.md5,
1271912880
xml2json: util.xml2json,
12720-
json2xml: util.json2xml
12881+
json2xml: util.json2xml,
12882+
encodeBase64: util.encodeBase64
1272112883
};
1272212884
COS.getAuthorization = util.getAuth;
1272312885
COS.version = pkg.version;
@@ -13682,6 +13844,8 @@ var xml2json = __webpack_require__(/*! ../lib/xml2json */ "./lib/xml2json.js");
1368213844

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

13847+
var base64 = __webpack_require__(/*! ../lib/base64 */ "./lib/base64.js");
13848+
1368513849
var Tracker = __webpack_require__(/*! ./tracker */ "./src/tracker.js");
1368613850

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

14679+
var encodeBase64 = function encodeBase64(str, safe) {
14680+
var base64Str = base64.encode(str); // 万象使用的安全base64格式需要特殊处理
14681+
14682+
if (safe) {
14683+
base64Str = base64Str.replaceAll('+', '-').replaceAll('/', '_').replaceAll('=', '');
14684+
}
14685+
14686+
return base64Str;
14687+
};
14688+
1451514689
var util = {
1451614690
noop: noop,
1451714691
formatParams: formatParams,
@@ -14546,7 +14720,8 @@ var util = {
1454614720
isBrowser: true,
1454714721
isNode: isNode,
1454814722
isCIHost: isCIHost,
14549-
isIOS_QQ: isIOS && isQQ
14723+
isIOS_QQ: isIOS && isQQ,
14724+
encodeBase64: encodeBase64
1455014725
};
1455114726
module.exports = util;
1455214727
/* 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: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ declare namespace COS {
6363
| 'public-read'
6464
| 'authenticated-read'
6565
| 'bucket-owner-read'
66-
| 'bucket-owner-full-contro';
66+
| 'bucket-owner-full-control';
6767
/** 二进制值的字符串,'true' | 'false' */
6868
type BooleanString = 'true' | 'false';
6969
/** 所有者的信息 */
@@ -207,6 +207,7 @@ declare namespace COS {
207207
md5: (str: String, encoding?: string) => string;
208208
xml2json: (bodyStr: string) => any;
209209
json2xml: (json: any) => string;
210+
encodeBase64: (str: string, safe?: boolean) => string;
210211
}
211212

212213
interface StaticGetAuthorizationOptions {
@@ -1506,7 +1507,13 @@ Bulk:批量模式,恢复时间为24 - 48小时。 */
15061507
'x-cos-meta-*'?: string;
15071508
}
15081509
/** putObjectCopy 接口返回值 */
1509-
interface PutObjectCopyResult extends GeneralResult {}
1510+
interface PutObjectCopyResult extends GeneralResult {
1511+
ETag: string;
1512+
CRC64: string;
1513+
LastModified: string;
1514+
VersionId: string;
1515+
Location: Location;
1516+
}
15101517

15111518
// putObjectTagging
15121519
/** putObjectTagging 接口参数 */

0 commit comments

Comments
 (0)