cos-wx-sdk-v5 1.4.4 → 1.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,32 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
9
9
 
10
+ ## [v1.4.5](https://github.com/tencentyun/cos-wx-sdk-v5/compare/v1.4.4...v1.4.5) - 2022-10-22
11
+
12
+ fix
13
+ - getObjectUrl暂时只支持回调写法
14
+
15
+ ### Merged
16
+
17
+ - fix: getObjectUrl暂时只支持回调写法 [`#78`](https://github.com/tencentyun/cos-wx-sdk-v5/pull/78)
18
+
19
+ ### Commits
20
+
21
+ - Updated CHANGELOG.md [`8cc1986`](https://github.com/tencentyun/cos-wx-sdk-v5/commit/8cc19868dac5683cd807cfb8678c74c477b29ce5)
22
+
23
+ ## [v1.4.4](https://github.com/tencentyun/cos-wx-sdk-v5/compare/v1.4.3...v1.4.4) - 2022-10-20
24
+
25
+ - 分块复制支持续传
26
+ - 合法域名校验支持内网域名和.cn域名
27
+
28
+ ### Merged
29
+
30
+ - feat1.4.4 [`#77`](https://github.com/tencentyun/cos-wx-sdk-v5/pull/77)
31
+
32
+ ### Commits
33
+
34
+ - Updated CHANGELOG.md [`cdf8af6`](https://github.com/tencentyun/cos-wx-sdk-v5/commit/cdf8af65f6b44ae1ed8244655073b6e3003535a0)
35
+
10
36
  ## [v1.4.3](https://github.com/tencentyun/cos-wx-sdk-v5/compare/v1.4.2...v1.4.3) - 2022-09-22
11
37
 
12
38
  feat
@@ -6450,7 +6450,7 @@ module.exports = function(module) {
6450
6450
  /*! exports provided: name, version, description, main, scripts, repository, author, license, dependencies, devDependencies, default */
6451
6451
  /***/ (function(module) {
6452
6452
 
6453
- module.exports = JSON.parse("{\"name\":\"cos-wx-sdk-v5\",\"version\":\"1.4.4\",\"description\":\"小程序 SDK for [腾讯云对象存储服务](https://cloud.tencent.com/product/cos)\",\"main\":\"demo/lib/cos-wx-sdk-v5.min.js\",\"scripts\":{\"dev\":\"cross-env NODE_ENV=development node build.js --mode=development\",\"build\":\"cross-env NODE_ENV=production node build.js --mode=production\",\"sts.js\":\"node server/sts.js\"},\"repository\":{\"type\":\"git\",\"url\":\"http://github.com/tencentyun/cos-wx-sdk-v5.git\"},\"author\":\"carsonxu\",\"license\":\"ISC\",\"dependencies\":{\"mime\":\"^2.4.6\",\"@xmldom/xmldom\":\"^0.8.2\"},\"devDependencies\":{\"babel-core\":\"6.26.3\",\"babel-loader\":\"8.2.5\",\"@babel/preset-env\":\"7.16.11\",\"body-parser\":\"^1.18.3\",\"cross-env\":\"^7.0.3\",\"express\":\"^4.17.1\",\"qcloud-cos-sts\":\"^3.0.2\",\"terser-webpack-plugin\":\"4.2.3\",\"webpack\":\"4.46.0\",\"webpack-cli\":\"4.10.0\"}}");
6453
+ module.exports = JSON.parse("{\"name\":\"cos-wx-sdk-v5\",\"version\":\"1.4.6\",\"description\":\"小程序 SDK for [腾讯云对象存储服务](https://cloud.tencent.com/product/cos)\",\"main\":\"demo/lib/cos-wx-sdk-v5.min.js\",\"scripts\":{\"dev\":\"cross-env NODE_ENV=development node build.js --mode=development\",\"build\":\"cross-env NODE_ENV=production node build.js --mode=production\",\"sts.js\":\"node server/sts.js\"},\"repository\":{\"type\":\"git\",\"url\":\"http://github.com/tencentyun/cos-wx-sdk-v5.git\"},\"author\":\"carsonxu\",\"license\":\"ISC\",\"dependencies\":{\"mime\":\"^2.4.6\",\"@xmldom/xmldom\":\"^0.8.2\"},\"devDependencies\":{\"babel-core\":\"6.26.3\",\"babel-loader\":\"8.2.5\",\"@babel/preset-env\":\"7.16.11\",\"body-parser\":\"^1.18.3\",\"cross-env\":\"^7.0.3\",\"express\":\"^4.17.1\",\"qcloud-cos-sts\":\"^3.0.2\",\"terser-webpack-plugin\":\"4.2.3\",\"webpack\":\"4.46.0\",\"webpack-cli\":\"4.10.0\"}}");
6454
6454
 
6455
6455
  /***/ }),
6456
6456
 
@@ -7398,32 +7398,32 @@ function uploadFile(_x, _x2) {
7398
7398
 
7399
7399
 
7400
7400
  function _uploadFile() {
7401
- _uploadFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(params, callback) {
7401
+ _uploadFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(params, callback) {
7402
7402
  var self, SliceSize, taskList, FileSize, fileInfo, accelerate, _onTaskReady, _onFileFinish, onFileFinish, simpleUploadMethod, api;
7403
7403
 
7404
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
7404
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
7405
7405
  while (1) {
7406
- switch (_context2.prev = _context2.next) {
7406
+ switch (_context.prev = _context.next) {
7407
7407
  case 0:
7408
7408
  self = this; // 判断多大的文件使用分片上传
7409
7409
 
7410
7410
  SliceSize = params.SliceSize === undefined ? self.options.SliceSize : params.SliceSize;
7411
7411
  taskList = []; // var FileSize = params.FileSize;
7412
7412
 
7413
- _context2.prev = 3;
7414
- _context2.next = 6;
7413
+ _context.prev = 3;
7414
+ _context.next = 6;
7415
7415
  return util.getFileSizeByPath(params.FilePath);
7416
7416
 
7417
7417
  case 6:
7418
- FileSize = _context2.sent;
7419
- _context2.next = 12;
7418
+ FileSize = _context.sent;
7419
+ _context.next = 12;
7420
7420
  break;
7421
7421
 
7422
7422
  case 9:
7423
- _context2.prev = 9;
7424
- _context2.t0 = _context2["catch"](3);
7423
+ _context.prev = 9;
7424
+ _context.t0 = _context["catch"](3);
7425
7425
  callback({
7426
- error: _context2.t0
7426
+ error: _context.t0
7427
7427
  });
7428
7428
 
7429
7429
  case 12:
@@ -7483,154 +7483,183 @@ function _uploadFile() {
7483
7483
 
7484
7484
  case 23:
7485
7485
  case "end":
7486
- return _context2.stop();
7486
+ return _context.stop();
7487
7487
  }
7488
7488
  }
7489
- }, _callee2, this, [[3, 9]]);
7489
+ }, _callee, this, [[3, 9]]);
7490
7490
  }));
7491
7491
  return _uploadFile.apply(this, arguments);
7492
7492
  }
7493
7493
 
7494
- function uploadFiles(params, callback) {
7495
- var self = this; // 判断多大的文件使用分片上传
7496
-
7497
- var SliceSize = params.SliceSize === undefined ? self.options.SliceSize : params.SliceSize; // 汇总返回进度
7498
-
7499
- var TotalSize = 0;
7500
- var TotalFinish = 0;
7501
- var onTotalProgress = util.throttleOnProgress.call(self, TotalFinish, params.onProgress); // 汇总返回回调
7502
-
7503
- var unFinishCount = params.files.length;
7504
- var _onTotalFileFinish = params.onFileFinish;
7505
- var resultList = Array(unFinishCount);
7506
-
7507
- var onTotalFileFinish = function onTotalFileFinish(err, data, options) {
7508
- onTotalProgress(null, true);
7509
- _onTotalFileFinish && _onTotalFileFinish(err, data, options);
7510
- resultList[options.Index] = {
7511
- options: options,
7512
- error: err,
7513
- data: data
7514
- };
7515
-
7516
- if (--unFinishCount <= 0 && callback) {
7517
- callback(null, {
7518
- files: resultList
7519
- });
7520
- }
7521
- }; // 开始处理每个文件
7522
-
7523
-
7524
- var taskList = [];
7525
- util.each(params.files, /*#__PURE__*/function () {
7526
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(fileParams, index) {
7527
- var FileSize, fileInfo, accelerate, _onTaskReady, PreAddSize, _onProgress, _onFileFinish, onFileFinish, simpleUploadMethod, api;
7528
-
7529
- return _regeneratorRuntime().wrap(function _callee$(_context) {
7530
- while (1) {
7531
- switch (_context.prev = _context.next) {
7532
- case 0:
7533
- // var FileSize = fileParams.FileSize;
7534
- FileSize = 0;
7535
- _context.prev = 1;
7536
- _context.next = 4;
7537
- return util.getFileSizeByPath(fileParams.FilePath);
7538
-
7539
- case 4:
7540
- FileSize = _context.sent;
7541
- _context.next = 9;
7542
- break;
7494
+ function uploadFiles(_x3, _x4) {
7495
+ return _uploadFiles.apply(this, arguments);
7496
+ } // 分片复制文件
7543
7497
 
7544
- case 7:
7545
- _context.prev = 7;
7546
- _context.t0 = _context["catch"](1);
7547
-
7548
- case 9:
7549
- fileInfo = {
7550
- Index: index,
7551
- TaskId: ''
7552
- }; // 更新文件总大小
7553
-
7554
- TotalSize += FileSize; // 单个文件上传链路
7555
-
7556
- if (self.options.EnableTracker) {
7557
- accelerate = self.options.UseAccelerate || typeof self.options.Domain === 'string' && self.options.Domain.includes('accelerate.');
7558
- fileParams.tracker = new Tracker({
7559
- bucket: fileParams.Bucket,
7560
- region: fileParams.Region,
7561
- apiName: 'uploadFiles',
7562
- fileKey: fileParams.Key,
7563
- fileSize: FileSize,
7564
- accelerate: accelerate,
7565
- deepTracker: self.options.DeepTracker,
7566
- customId: self.options.CustomId,
7567
- delay: self.options.TrackerDelay
7568
- });
7569
- } // 整理 option,用于返回给回调
7570
7498
 
7499
+ function _uploadFiles() {
7500
+ _uploadFiles = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(params, callback) {
7501
+ var self, SliceSize, TotalSize, TotalFinish, onTotalProgress, unFinishCount, _onTotalFileFinish, resultList, onTotalFileFinish, taskList, getTaskList;
7571
7502
 
7572
- util.each(fileParams, function (v, k) {
7573
- if (_typeof(v) !== 'object' && typeof v !== 'function') {
7574
- fileInfo[k] = v;
7575
- }
7576
- }); // 处理单个文件 TaskReady
7503
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
7504
+ while (1) {
7505
+ switch (_context3.prev = _context3.next) {
7506
+ case 0:
7507
+ self = this; // 判断多大的文件使用分片上传
7577
7508
 
7578
- _onTaskReady = fileParams.onTaskReady;
7509
+ SliceSize = params.SliceSize === undefined ? self.options.SliceSize : params.SliceSize; // 汇总返回进度
7579
7510
 
7580
- fileParams.onTaskReady = function (tid) {
7581
- fileInfo.TaskId = tid;
7582
- _onTaskReady && _onTaskReady(tid);
7583
- }; // 处理单个文件进度
7511
+ TotalSize = 0;
7512
+ TotalFinish = 0;
7513
+ onTotalProgress = util.throttleOnProgress.call(self, TotalFinish, params.onProgress); // 汇总返回回调
7584
7514
 
7515
+ unFinishCount = params.files.length;
7516
+ _onTotalFileFinish = params.onFileFinish;
7517
+ resultList = Array(unFinishCount);
7585
7518
 
7586
- PreAddSize = 0;
7587
- _onProgress = fileParams.onProgress;
7519
+ onTotalFileFinish = function onTotalFileFinish(err, data, options) {
7520
+ onTotalProgress(null, true);
7521
+ _onTotalFileFinish && _onTotalFileFinish(err, data, options);
7522
+ resultList[options.Index] = {
7523
+ options: options,
7524
+ error: err,
7525
+ data: data
7526
+ };
7588
7527
 
7589
- fileParams.onProgress = function (info) {
7590
- TotalFinish = TotalFinish - PreAddSize + info.loaded;
7591
- PreAddSize = info.loaded;
7592
- _onProgress && _onProgress(info);
7593
- onTotalProgress({
7594
- loaded: TotalFinish,
7595
- total: TotalSize
7528
+ if (--unFinishCount <= 0 && callback) {
7529
+ callback(null, {
7530
+ files: resultList
7596
7531
  });
7597
- }; // 处理单个文件完成
7598
-
7599
-
7600
- _onFileFinish = fileParams.onFileFinish;
7601
-
7602
- onFileFinish = function onFileFinish(err, data) {
7603
- // 格式化上报参数并上报
7604
- fileParams.tracker && fileParams.tracker.formatResult(err, data);
7605
- _onFileFinish && _onFileFinish(err, data);
7606
- onTotalFileFinish && onTotalFileFinish(err, data, fileInfo);
7607
- }; // 添加上传任务
7608
-
7609
-
7610
- simpleUploadMethod = self.options.SimpleUploadMethod === 'postObject' ? 'postObject' : 'putObject';
7611
- api = FileSize > SliceSize ? 'sliceUploadFile' : simpleUploadMethod;
7612
- taskList.push({
7613
- api: api,
7614
- params: fileParams,
7615
- callback: onFileFinish
7532
+ }
7533
+ }; // 开始处理每个文件
7534
+
7535
+
7536
+ taskList = [];
7537
+
7538
+ getTaskList = function getTaskList() {
7539
+ return params.files.map(function (fileParams, index) {
7540
+ return new Promise( /*#__PURE__*/function () {
7541
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(resolve) {
7542
+ var FileSize, fileInfo, accelerate, _onTaskReady, PreAddSize, _onProgress, _onFileFinish, onFileFinish, simpleUploadMethod, api;
7543
+
7544
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
7545
+ while (1) {
7546
+ switch (_context2.prev = _context2.next) {
7547
+ case 0:
7548
+ FileSize = 0;
7549
+ _context2.prev = 1;
7550
+ _context2.next = 4;
7551
+ return util.getFileSizeByPath(fileParams.FilePath);
7552
+
7553
+ case 4:
7554
+ FileSize = _context2.sent;
7555
+ _context2.next = 9;
7556
+ break;
7557
+
7558
+ case 7:
7559
+ _context2.prev = 7;
7560
+ _context2.t0 = _context2["catch"](1);
7561
+
7562
+ case 9:
7563
+ fileInfo = {
7564
+ Index: index,
7565
+ TaskId: ''
7566
+ }; // 更新文件总大小
7567
+
7568
+ TotalSize += FileSize; // 单个文件上传链路
7569
+
7570
+ if (self.options.EnableTracker) {
7571
+ accelerate = self.options.UseAccelerate || typeof self.options.Domain === 'string' && self.options.Domain.includes('accelerate.');
7572
+ fileParams.tracker = new Tracker({
7573
+ bucket: fileParams.Bucket,
7574
+ region: fileParams.Region,
7575
+ apiName: 'uploadFiles',
7576
+ fileKey: fileParams.Key,
7577
+ fileSize: FileSize,
7578
+ accelerate: accelerate,
7579
+ deepTracker: self.options.DeepTracker,
7580
+ customId: self.options.CustomId,
7581
+ delay: self.options.TrackerDelay
7582
+ });
7583
+ } // 整理 option,用于返回给回调
7584
+
7585
+
7586
+ util.each(fileParams, function (v, k) {
7587
+ if (_typeof(v) !== 'object' && typeof v !== 'function') {
7588
+ fileInfo[k] = v;
7589
+ }
7590
+ }); // 处理单个文件 TaskReady
7591
+
7592
+ _onTaskReady = fileParams.onTaskReady;
7593
+
7594
+ fileParams.onTaskReady = function (tid) {
7595
+ fileInfo.TaskId = tid;
7596
+ _onTaskReady && _onTaskReady(tid);
7597
+ }; // 处理单个文件进度
7598
+
7599
+
7600
+ PreAddSize = 0;
7601
+ _onProgress = fileParams.onProgress;
7602
+
7603
+ fileParams.onProgress = function (info) {
7604
+ TotalFinish = TotalFinish - PreAddSize + info.loaded;
7605
+ PreAddSize = info.loaded;
7606
+ _onProgress && _onProgress(info);
7607
+ onTotalProgress({
7608
+ loaded: TotalFinish,
7609
+ total: TotalSize
7610
+ });
7611
+ }; // 处理单个文件完成
7612
+
7613
+
7614
+ _onFileFinish = fileParams.onFileFinish;
7615
+
7616
+ onFileFinish = function onFileFinish(err, data) {
7617
+ // 格式化上报参数并上报
7618
+ fileParams.tracker && fileParams.tracker.formatResult(err, data);
7619
+ _onFileFinish && _onFileFinish(err, data);
7620
+ onTotalFileFinish && onTotalFileFinish(err, data, fileInfo);
7621
+ }; // 添加上传任务
7622
+
7623
+
7624
+ simpleUploadMethod = self.options.SimpleUploadMethod === 'postObject' ? 'postObject' : 'putObject';
7625
+ api = FileSize > SliceSize ? 'sliceUploadFile' : simpleUploadMethod;
7626
+ taskList.push({
7627
+ api: api,
7628
+ params: fileParams,
7629
+ callback: onFileFinish
7630
+ });
7631
+ resolve(true);
7632
+
7633
+ case 24:
7634
+ case "end":
7635
+ return _context2.stop();
7636
+ }
7637
+ }
7638
+ }, _callee2, null, [[1, 7]]);
7639
+ }));
7640
+
7641
+ return function (_x5) {
7642
+ return _ref.apply(this, arguments);
7643
+ };
7644
+ }());
7616
7645
  });
7646
+ };
7617
7647
 
7618
- case 23:
7619
- case "end":
7620
- return _context.stop();
7621
- }
7622
- }
7623
- }, _callee, null, [[1, 7]]);
7624
- }));
7625
-
7626
- return function (_x3, _x4) {
7627
- return _ref.apply(this, arguments);
7628
- };
7629
- }());
7648
+ _context3.next = 13;
7649
+ return Promise.all(getTaskList());
7630
7650
 
7631
- self._addTasks(taskList);
7632
- } // 分片复制文件
7651
+ case 13:
7652
+ self._addTasks(taskList);
7633
7653
 
7654
+ case 14:
7655
+ case "end":
7656
+ return _context3.stop();
7657
+ }
7658
+ }
7659
+ }, _callee3, this);
7660
+ }));
7661
+ return _uploadFiles.apply(this, arguments);
7662
+ }
7634
7663
 
7635
7664
  function sliceCopyFile(params, callback) {
7636
7665
  var ep = new EventProxy();
@@ -13649,7 +13678,7 @@ var apiWrapper = function apiWrapper(apiName, apiFn) {
13649
13678
  };
13650
13679
 
13651
13680
  var errMsg = checkParams();
13652
- var isSync = apiName === 'getAuth';
13681
+ var isSync = ['getAuth', 'getObjectUrl'].includes(apiName);
13653
13682
  var Promise = global.Promise;
13654
13683
 
13655
13684
  if (!isSync && Promise && !callback) {