cos-wx-sdk-v5 1.4.1 → 1.4.3
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 +36 -0
- package/demo/lib/cos-wx-sdk-v5.js +239 -131
- package/demo/lib/cos-wx-sdk-v5.min.js +2 -2
- package/demo-album/lib/cos-wx-sdk-v5.js +239 -131
- package/demo-album/lib/cos-wx-sdk-v5.min.js +2 -2
- package/package.json +1 -1
- package/src/advance.js +20 -7
- package/src/tracker.js +31 -16
- package/src/util.js +19 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,42 @@ 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.2](https://github.com/tencentyun/cos-wx-sdk-v5/compare/v1.4.1...v1.4.2) - 2022-09-09
|
|
11
|
+
|
|
12
|
+
fix
|
|
13
|
+
- 修复已知问题
|
|
14
|
+
|
|
15
|
+
### Merged
|
|
16
|
+
|
|
17
|
+
- fix 1.4.2 [`#75`](https://github.com/tencentyun/cos-wx-sdk-v5/pull/75)
|
|
18
|
+
- fix:修复已知问题 [`#73`](https://github.com/tencentyun/cos-wx-sdk-v5/pull/73)
|
|
19
|
+
|
|
20
|
+
### Commits
|
|
21
|
+
|
|
22
|
+
- Updated CHANGELOG.md [`a4a3e55`](https://github.com/tencentyun/cos-wx-sdk-v5/commit/a4a3e55fbb8ae0b4739a7a9f5b85b031e726553c)
|
|
23
|
+
|
|
24
|
+
## [v1.4.1](https://github.com/tencentyun/cos-wx-sdk-v5/compare/v1.4.0...v1.4.1) - 2022-09-01
|
|
25
|
+
|
|
26
|
+
fix
|
|
27
|
+
- 修复已知问题
|
|
28
|
+
|
|
29
|
+
### Commits
|
|
30
|
+
|
|
31
|
+
- fix:修复已知问题 [`d1a433f`](https://github.com/tencentyun/cos-wx-sdk-v5/commit/d1a433fbd787ba134a672141ae8c7d750df50704)
|
|
32
|
+
|
|
33
|
+
## [v1.4.0](https://github.com/tencentyun/cos-wx-sdk-v5/compare/v1.3.0...v1.4.0) - 2022-08-17
|
|
34
|
+
|
|
35
|
+
feat
|
|
36
|
+
- 新增beacon上报
|
|
37
|
+
|
|
38
|
+
### Merged
|
|
39
|
+
|
|
40
|
+
- feat/1.4.0 [`#72`](https://github.com/tencentyun/cos-wx-sdk-v5/pull/72)
|
|
41
|
+
|
|
42
|
+
### Commits
|
|
43
|
+
|
|
44
|
+
- Updated CHANGELOG.md [`7d52326`](https://github.com/tencentyun/cos-wx-sdk-v5/commit/7d523262e886826755a1adf0aae207b04bee7391)
|
|
45
|
+
|
|
10
46
|
## [v1.3.0](https://github.com/tencentyun/cos-wx-sdk-v5/compare/v1.2.1...v1.3.0) - 2022-08-09
|
|
11
47
|
|
|
12
48
|
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.
|
|
6453
|
+
module.exports = JSON.parse("{\"name\":\"cos-wx-sdk-v5\",\"version\":\"1.4.3\",\"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
|
|
|
@@ -6461,8 +6461,14 @@ module.exports = JSON.parse("{\"name\":\"cos-wx-sdk-v5\",\"version\":\"1.4.1\",\
|
|
|
6461
6461
|
/*! no static exports found */
|
|
6462
6462
|
/***/ (function(module, exports, __webpack_require__) {
|
|
6463
6463
|
|
|
6464
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return generator._invoke = function (innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; }(innerFn, self, context), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; this._invoke = function (method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); }; } function maybeInvokeDelegate(delegate, context) { var method = delegate.iterator[context.method]; if (undefined === method) { if (context.delegate = null, "throw" === context.method) { if (delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel; context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method"); } return ContinueSentinel; } var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (object) { var keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
6465
|
+
|
|
6464
6466
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
6465
6467
|
|
|
6468
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
6469
|
+
|
|
6470
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
6471
|
+
|
|
6466
6472
|
var session = __webpack_require__(/*! ./session */ "./src/session.js");
|
|
6467
6473
|
|
|
6468
6474
|
var Async = __webpack_require__(/*! ./async */ "./src/async.js");
|
|
@@ -6604,8 +6610,10 @@ function sliceUploadFile(params, callback) {
|
|
|
6604
6610
|
SliceSize: ChunkSize,
|
|
6605
6611
|
onHashProgress: onHashProgress,
|
|
6606
6612
|
tracker: tracker
|
|
6607
|
-
}, params);
|
|
6613
|
+
}, params); // 这里用户传入的params.FileSize可能单位不统一,必须使用sdk内获取的大小
|
|
6614
|
+
|
|
6608
6615
|
|
|
6616
|
+
_params.FileSize = FileSize;
|
|
6609
6617
|
getUploadIdAndPartList.call(self, _params, function (err, UploadData) {
|
|
6610
6618
|
if (!self._isRunningTask(TaskId)) return;
|
|
6611
6619
|
if (err) return ep.emit('error', err);
|
|
@@ -7384,68 +7392,105 @@ function abortUploadTaskArray(params, callback) {
|
|
|
7384
7392
|
} // 高级上传
|
|
7385
7393
|
|
|
7386
7394
|
|
|
7387
|
-
function uploadFile(
|
|
7388
|
-
|
|
7395
|
+
function uploadFile(_x, _x2) {
|
|
7396
|
+
return _uploadFile.apply(this, arguments);
|
|
7397
|
+
} // 批量上传文件
|
|
7389
7398
|
|
|
7390
|
-
var SliceSize = params.SliceSize === undefined ? self.options.SliceSize : params.SliceSize;
|
|
7391
|
-
var taskList = [];
|
|
7392
|
-
var FileSize = params.FileSize;
|
|
7393
|
-
var fileInfo = {
|
|
7394
|
-
TaskId: ''
|
|
7395
|
-
}; // 上传链路
|
|
7396
7399
|
|
|
7397
|
-
|
|
7398
|
-
|
|
7399
|
-
|
|
7400
|
-
bucket: params.Bucket,
|
|
7401
|
-
region: params.Region,
|
|
7402
|
-
apiName: 'uploadFile',
|
|
7403
|
-
fileKey: params.Key,
|
|
7404
|
-
fileSize: FileSize,
|
|
7405
|
-
accelerate: accelerate,
|
|
7406
|
-
deepTracker: self.options.DeepTracker,
|
|
7407
|
-
customId: self.options.CustomId,
|
|
7408
|
-
delay: self.options.TrackerDelay
|
|
7409
|
-
});
|
|
7410
|
-
} // 整理 option,用于返回给回调
|
|
7400
|
+
function _uploadFile() {
|
|
7401
|
+
_uploadFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(params, callback) {
|
|
7402
|
+
var self, SliceSize, taskList, FileSize, fileInfo, accelerate, _onTaskReady, _onFileFinish, onFileFinish, simpleUploadMethod, api;
|
|
7411
7403
|
|
|
7404
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
7405
|
+
while (1) {
|
|
7406
|
+
switch (_context2.prev = _context2.next) {
|
|
7407
|
+
case 0:
|
|
7408
|
+
self = this; // 判断多大的文件使用分片上传
|
|
7412
7409
|
|
|
7413
|
-
|
|
7414
|
-
|
|
7415
|
-
fileInfo[k] = v;
|
|
7416
|
-
}
|
|
7417
|
-
}); // 处理文件 TaskReady
|
|
7410
|
+
SliceSize = params.SliceSize === undefined ? self.options.SliceSize : params.SliceSize;
|
|
7411
|
+
taskList = []; // var FileSize = params.FileSize;
|
|
7418
7412
|
|
|
7419
|
-
|
|
7413
|
+
_context2.prev = 3;
|
|
7414
|
+
_context2.next = 6;
|
|
7415
|
+
return util.getFileSizeByPath(params.FilePath);
|
|
7420
7416
|
|
|
7421
|
-
|
|
7422
|
-
|
|
7423
|
-
|
|
7424
|
-
|
|
7417
|
+
case 6:
|
|
7418
|
+
FileSize = _context2.sent;
|
|
7419
|
+
_context2.next = 12;
|
|
7420
|
+
break;
|
|
7425
7421
|
|
|
7422
|
+
case 9:
|
|
7423
|
+
_context2.prev = 9;
|
|
7424
|
+
_context2.t0 = _context2["catch"](3);
|
|
7425
|
+
callback({
|
|
7426
|
+
error: _context2.t0
|
|
7427
|
+
});
|
|
7426
7428
|
|
|
7427
|
-
|
|
7429
|
+
case 12:
|
|
7430
|
+
fileInfo = {
|
|
7431
|
+
TaskId: ''
|
|
7432
|
+
}; // 上传链路
|
|
7433
|
+
|
|
7434
|
+
if (self.options.EnableTracker) {
|
|
7435
|
+
accelerate = self.options.UseAccelerate || typeof self.options.Domain === 'string' && self.options.Domain.includes('accelerate.');
|
|
7436
|
+
params.tracker = new Tracker({
|
|
7437
|
+
bucket: params.Bucket,
|
|
7438
|
+
region: params.Region,
|
|
7439
|
+
apiName: 'uploadFile',
|
|
7440
|
+
fileKey: params.Key,
|
|
7441
|
+
fileSize: FileSize,
|
|
7442
|
+
accelerate: accelerate,
|
|
7443
|
+
deepTracker: self.options.DeepTracker,
|
|
7444
|
+
customId: self.options.CustomId,
|
|
7445
|
+
delay: self.options.TrackerDelay
|
|
7446
|
+
});
|
|
7447
|
+
} // 整理 option,用于返回给回调
|
|
7428
7448
|
|
|
7429
|
-
var onFileFinish = function onFileFinish(err, data) {
|
|
7430
|
-
// 格式化上报参数并上报
|
|
7431
|
-
params.tracker && params.tracker.formatResult(err, data);
|
|
7432
|
-
_onFileFinish && _onFileFinish(err, data, fileInfo);
|
|
7433
|
-
callback && callback(err, data);
|
|
7434
|
-
}; // 添加上传任务
|
|
7435
7449
|
|
|
7450
|
+
util.each(params, function (v, k) {
|
|
7451
|
+
if (_typeof(v) !== 'object' && typeof v !== 'function') {
|
|
7452
|
+
fileInfo[k] = v;
|
|
7453
|
+
}
|
|
7454
|
+
}); // 处理文件 TaskReady
|
|
7436
7455
|
|
|
7437
|
-
|
|
7438
|
-
var api = FileSize > SliceSize ? 'sliceUploadFile' : simpleUploadMethod;
|
|
7439
|
-
taskList.push({
|
|
7440
|
-
api: api,
|
|
7441
|
-
params: params,
|
|
7442
|
-
callback: onFileFinish
|
|
7443
|
-
});
|
|
7456
|
+
_onTaskReady = params.onTaskReady;
|
|
7444
7457
|
|
|
7445
|
-
|
|
7446
|
-
|
|
7458
|
+
params.onTaskReady = function (tid) {
|
|
7459
|
+
fileInfo.TaskId = tid;
|
|
7460
|
+
_onTaskReady && _onTaskReady(tid);
|
|
7461
|
+
}; // 处理文件完成
|
|
7462
|
+
|
|
7463
|
+
|
|
7464
|
+
_onFileFinish = params.onFileFinish;
|
|
7465
|
+
|
|
7466
|
+
onFileFinish = function onFileFinish(err, data) {
|
|
7467
|
+
// 格式化上报参数并上报
|
|
7468
|
+
params.tracker && params.tracker.formatResult(err, data);
|
|
7469
|
+
_onFileFinish && _onFileFinish(err, data, fileInfo);
|
|
7470
|
+
callback && callback(err, data);
|
|
7471
|
+
}; // 添加上传任务
|
|
7447
7472
|
|
|
7448
7473
|
|
|
7474
|
+
simpleUploadMethod = self.options.SimpleUploadMethod === 'postObject' ? 'postObject' : 'putObject';
|
|
7475
|
+
api = FileSize > SliceSize ? 'sliceUploadFile' : simpleUploadMethod;
|
|
7476
|
+
taskList.push({
|
|
7477
|
+
api: api,
|
|
7478
|
+
params: params,
|
|
7479
|
+
callback: onFileFinish
|
|
7480
|
+
});
|
|
7481
|
+
|
|
7482
|
+
self._addTasks(taskList);
|
|
7483
|
+
|
|
7484
|
+
case 23:
|
|
7485
|
+
case "end":
|
|
7486
|
+
return _context2.stop();
|
|
7487
|
+
}
|
|
7488
|
+
}
|
|
7489
|
+
}, _callee2, this, [[3, 9]]);
|
|
7490
|
+
}));
|
|
7491
|
+
return _uploadFile.apply(this, arguments);
|
|
7492
|
+
}
|
|
7493
|
+
|
|
7449
7494
|
function uploadFiles(params, callback) {
|
|
7450
7495
|
var self = this; // 判断多大的文件使用分片上传
|
|
7451
7496
|
|
|
@@ -7477,77 +7522,111 @@ function uploadFiles(params, callback) {
|
|
|
7477
7522
|
|
|
7478
7523
|
|
|
7479
7524
|
var taskList = [];
|
|
7480
|
-
util.each(params.files, function (
|
|
7481
|
-
var
|
|
7482
|
-
|
|
7483
|
-
|
|
7484
|
-
|
|
7485
|
-
|
|
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);
|
|
7486
7538
|
|
|
7487
|
-
|
|
7539
|
+
case 4:
|
|
7540
|
+
FileSize = _context.sent;
|
|
7541
|
+
_context.next = 9;
|
|
7542
|
+
break;
|
|
7488
7543
|
|
|
7489
|
-
|
|
7490
|
-
|
|
7491
|
-
|
|
7492
|
-
|
|
7493
|
-
|
|
7494
|
-
|
|
7495
|
-
|
|
7496
|
-
|
|
7497
|
-
|
|
7498
|
-
|
|
7499
|
-
|
|
7500
|
-
|
|
7501
|
-
|
|
7502
|
-
|
|
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,用于返回给回调
|
|
7503
7570
|
|
|
7504
7571
|
|
|
7505
|
-
|
|
7506
|
-
|
|
7507
|
-
|
|
7508
|
-
|
|
7509
|
-
|
|
7572
|
+
util.each(fileParams, function (v, k) {
|
|
7573
|
+
if (_typeof(v) !== 'object' && typeof v !== 'function') {
|
|
7574
|
+
fileInfo[k] = v;
|
|
7575
|
+
}
|
|
7576
|
+
}); // 处理单个文件 TaskReady
|
|
7510
7577
|
|
|
7511
|
-
|
|
7578
|
+
_onTaskReady = fileParams.onTaskReady;
|
|
7512
7579
|
|
|
7513
|
-
|
|
7514
|
-
|
|
7515
|
-
|
|
7516
|
-
|
|
7580
|
+
fileParams.onTaskReady = function (tid) {
|
|
7581
|
+
fileInfo.TaskId = tid;
|
|
7582
|
+
_onTaskReady && _onTaskReady(tid);
|
|
7583
|
+
}; // 处理单个文件进度
|
|
7517
7584
|
|
|
7518
7585
|
|
|
7519
|
-
|
|
7520
|
-
|
|
7586
|
+
PreAddSize = 0;
|
|
7587
|
+
_onProgress = fileParams.onProgress;
|
|
7521
7588
|
|
|
7522
|
-
|
|
7523
|
-
|
|
7524
|
-
|
|
7525
|
-
|
|
7526
|
-
|
|
7527
|
-
|
|
7528
|
-
|
|
7529
|
-
|
|
7530
|
-
|
|
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
|
|
7596
|
+
});
|
|
7597
|
+
}; // 处理单个文件完成
|
|
7531
7598
|
|
|
7532
7599
|
|
|
7533
|
-
|
|
7600
|
+
_onFileFinish = fileParams.onFileFinish;
|
|
7534
7601
|
|
|
7535
|
-
|
|
7536
|
-
|
|
7537
|
-
|
|
7538
|
-
|
|
7539
|
-
|
|
7540
|
-
|
|
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
|
+
}; // 添加上传任务
|
|
7541
7608
|
|
|
7542
7609
|
|
|
7543
|
-
|
|
7544
|
-
|
|
7545
|
-
|
|
7546
|
-
|
|
7547
|
-
|
|
7548
|
-
|
|
7549
|
-
|
|
7550
|
-
|
|
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
|
|
7616
|
+
});
|
|
7617
|
+
|
|
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
|
+
}());
|
|
7551
7630
|
|
|
7552
7631
|
self._addTasks(taskList);
|
|
7553
7632
|
} // 分片复制文件
|
|
@@ -12731,7 +12810,8 @@ var Tracker = /*#__PURE__*/function () {
|
|
|
12731
12810
|
deepTracker = opt.deepTracker;
|
|
12732
12811
|
var appid = bucket && bucket.substr(bucket.lastIndexOf('-') + 1) || '';
|
|
12733
12812
|
this.parent = parent;
|
|
12734
|
-
this.deepTracker = deepTracker;
|
|
12813
|
+
this.deepTracker = deepTracker;
|
|
12814
|
+
this.delay = delay; // 上报用到的字段
|
|
12735
12815
|
|
|
12736
12816
|
this.params = {
|
|
12737
12817
|
// 通用字段
|
|
@@ -12803,13 +12883,30 @@ var Tracker = /*#__PURE__*/function () {
|
|
|
12803
12883
|
key: "formatResult",
|
|
12804
12884
|
value: function () {
|
|
12805
12885
|
var _formatResult = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(err, data) {
|
|
12806
|
-
var _err$error, _err$error2, _err$error3;
|
|
12886
|
+
var _err$error, _err$error$error, _err$error2, _err$error2$error, _err$error3, _err$error4, _err$error5, _err$error5$error, _err$error6;
|
|
12807
12887
|
|
|
12808
12888
|
var now, tookTime, networkType, errorCode, errorMessage, errorStatusCode, errorServiceName, requestId, errorType, exec;
|
|
12809
12889
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
12810
12890
|
while (1) {
|
|
12811
12891
|
switch (_context.prev = _context.next) {
|
|
12812
12892
|
case 0:
|
|
12893
|
+
/**
|
|
12894
|
+
* 解析到err的格式为:
|
|
12895
|
+
* 1.服务端有返回时
|
|
12896
|
+
* {
|
|
12897
|
+
* err: 同下方error,
|
|
12898
|
+
* error: {
|
|
12899
|
+
* error: {
|
|
12900
|
+
* Code: '', Message: '', Resource: '', RequestId: '', TraceId: '',
|
|
12901
|
+
* },
|
|
12902
|
+
* statusCode: xxx,
|
|
12903
|
+
* headers: {},
|
|
12904
|
+
* RequestId: '',
|
|
12905
|
+
* },
|
|
12906
|
+
* }
|
|
12907
|
+
* 2.本地抛出或小程序直接报错
|
|
12908
|
+
* {error: 'message'}或{error: {error: 'message' }}
|
|
12909
|
+
*/
|
|
12813
12910
|
now = new Date().getTime();
|
|
12814
12911
|
tookTime = now - this.params.startTime;
|
|
12815
12912
|
_context.next = 4;
|
|
@@ -12817,11 +12914,11 @@ var Tracker = /*#__PURE__*/function () {
|
|
|
12817
12914
|
|
|
12818
12915
|
case 4:
|
|
12819
12916
|
networkType = _context.sent;
|
|
12820
|
-
errorCode = err ? err === null || err === void 0 ? void 0 : (_err$error = err.error) === null || _err$error === void 0 ? void 0 : _err$error.Code : '';
|
|
12821
|
-
errorMessage = err ? err === null || err === void 0 ? void 0 : (_err$error2 = err.error) === null || _err$error2 === void 0 ? void 0 : _err$error2.Message : '';
|
|
12822
|
-
errorStatusCode = err ? err === null || err === void 0 ? void 0 : err.statusCode : data.statusCode;
|
|
12823
|
-
errorServiceName = err ? err === null || err === void 0 ? void 0 : (_err$
|
|
12824
|
-
requestId = err ? (err === null || err === void 0 ? void 0 : err.
|
|
12917
|
+
errorCode = err ? (err === null || err === void 0 ? void 0 : (_err$error = err.error) === null || _err$error === void 0 ? void 0 : (_err$error$error = _err$error.error) === null || _err$error$error === void 0 ? void 0 : _err$error$error.Code) || 'Error' : '';
|
|
12918
|
+
errorMessage = err ? (err === null || err === void 0 ? void 0 : (_err$error2 = err.error) === null || _err$error2 === void 0 ? void 0 : (_err$error2$error = _err$error2.error) === null || _err$error2$error === void 0 ? void 0 : _err$error2$error.Message) || (err === null || err === void 0 ? void 0 : (_err$error3 = err.error) === null || _err$error3 === void 0 ? void 0 : _err$error3.error) || (err === null || err === void 0 ? void 0 : err.error) || '' : '';
|
|
12919
|
+
errorStatusCode = err ? err === null || err === void 0 ? void 0 : (_err$error4 = err.error) === null || _err$error4 === void 0 ? void 0 : _err$error4.statusCode : data.statusCode;
|
|
12920
|
+
errorServiceName = err ? err === null || err === void 0 ? void 0 : (_err$error5 = err.error) === null || _err$error5 === void 0 ? void 0 : (_err$error5$error = _err$error5.error) === null || _err$error5$error === void 0 ? void 0 : _err$error5$error.Resource : '';
|
|
12921
|
+
requestId = err ? (err === null || err === void 0 ? void 0 : (_err$error6 = err.error) === null || _err$error6 === void 0 ? void 0 : _err$error6.RequestId) || '' : (data === null || data === void 0 ? void 0 : data.RequestId) || '';
|
|
12825
12922
|
errorType = err ? requestId ? 'Server' : 'Client' : '';
|
|
12826
12923
|
Object.assign(this.params, {
|
|
12827
12924
|
tookTime: tookTime,
|
|
@@ -12888,19 +12985,19 @@ var Tracker = /*#__PURE__*/function () {
|
|
|
12888
12985
|
}
|
|
12889
12986
|
|
|
12890
12987
|
var eventCode = getEventCode(this.params.name);
|
|
12891
|
-
var formattedParams = formatParams(this.params);
|
|
12892
|
-
|
|
12988
|
+
var formattedParams = formatParams(this.params); // 兜底处理
|
|
12989
|
+
|
|
12990
|
+
if (!this.beacon) {
|
|
12991
|
+
this.beacon = getBeacon(this.delay || 5000);
|
|
12992
|
+
}
|
|
12893
12993
|
|
|
12894
12994
|
if (this.params.delay === 0) {
|
|
12895
12995
|
// 实时上报
|
|
12896
|
-
this.beacon.onDirectUserAction(eventCode, formattedParams);
|
|
12996
|
+
this.beacon && this.beacon.onDirectUserAction(eventCode, formattedParams);
|
|
12897
12997
|
} else {
|
|
12898
12998
|
// 周期性上报
|
|
12899
|
-
this.beacon.onUserAction(eventCode, formattedParams);
|
|
12900
|
-
}
|
|
12901
|
-
|
|
12902
|
-
|
|
12903
|
-
this.destroy();
|
|
12999
|
+
this.beacon && this.beacon.onUserAction(eventCode, formattedParams);
|
|
13000
|
+
}
|
|
12904
13001
|
} // 生成子实例,与父所属一个链路,可用于分块上传内部流程上报单个分块操作
|
|
12905
13002
|
|
|
12906
13003
|
}, {
|
|
@@ -12917,13 +13014,6 @@ var Tracker = /*#__PURE__*/function () {
|
|
|
12917
13014
|
delay: this.params.delay
|
|
12918
13015
|
});
|
|
12919
13016
|
return new Tracker(subParams);
|
|
12920
|
-
} // 链路结束后销毁实例
|
|
12921
|
-
|
|
12922
|
-
}, {
|
|
12923
|
-
key: "destroy",
|
|
12924
|
-
value: function destroy() {
|
|
12925
|
-
this.beacon = null;
|
|
12926
|
-
this.params = {};
|
|
12927
13017
|
}
|
|
12928
13018
|
}]);
|
|
12929
13019
|
|
|
@@ -13439,7 +13529,7 @@ var apiWrapper = function apiWrapper(apiName, apiFn) {
|
|
|
13439
13529
|
};
|
|
13440
13530
|
|
|
13441
13531
|
var errMsg = checkParams();
|
|
13442
|
-
var isSync = apiName === 'getAuth'
|
|
13532
|
+
var isSync = apiName === 'getAuth';
|
|
13443
13533
|
var Promise = global.Promise;
|
|
13444
13534
|
|
|
13445
13535
|
if (!isSync && Promise && !callback) {
|
|
@@ -13620,7 +13710,24 @@ var getFileSize = /*#__PURE__*/function () {
|
|
|
13620
13710
|
return function getFileSize(_x, _x2, _x3) {
|
|
13621
13711
|
return _ref.apply(this, arguments);
|
|
13622
13712
|
};
|
|
13623
|
-
}();
|
|
13713
|
+
}(); // 通过FilePath获取上传文件的大小
|
|
13714
|
+
|
|
13715
|
+
|
|
13716
|
+
var getFileSizeByPath = function getFileSizeByPath(filePath) {
|
|
13717
|
+
return new Promise(function (resolve, reject) {
|
|
13718
|
+
wxfs.stat({
|
|
13719
|
+
path: filePath,
|
|
13720
|
+
success: function success(res) {
|
|
13721
|
+
var stats = res.stats;
|
|
13722
|
+
var size = stats.isDirectory() ? 0 : stats.size;
|
|
13723
|
+
resolve(size);
|
|
13724
|
+
},
|
|
13725
|
+
fail: function fail(res) {
|
|
13726
|
+
reject((res === null || res === void 0 ? void 0 : res.errMsg) || '');
|
|
13727
|
+
}
|
|
13728
|
+
});
|
|
13729
|
+
});
|
|
13730
|
+
};
|
|
13624
13731
|
|
|
13625
13732
|
var getSkewTime = function getSkewTime(offset) {
|
|
13626
13733
|
return Date.now() + (offset || 0);
|
|
@@ -13724,6 +13831,7 @@ var util = {
|
|
|
13724
13831
|
camSafeUrlEncode: camSafeUrlEncode,
|
|
13725
13832
|
throttleOnProgress: throttleOnProgress,
|
|
13726
13833
|
getFileSize: getFileSize,
|
|
13834
|
+
getFileSizeByPath: getFileSizeByPath,
|
|
13727
13835
|
getSkewTime: getSkewTime,
|
|
13728
13836
|
obj2str: obj2str,
|
|
13729
13837
|
getAuth: getAuth,
|