config.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. var __assign = (this && this.__assign) || function () {
  2. __assign = Object.assign || function(t) {
  3. for (var s, i = 1, n = arguments.length; i < n; i++) {
  4. s = arguments[i];
  5. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
  6. t[p] = s[p];
  7. }
  8. return t;
  9. };
  10. return __assign.apply(this, arguments);
  11. };
  12. var __rest = (this && this.__rest) || function (s, e) {
  13. var t = {};
  14. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
  15. t[p] = s[p];
  16. if (s != null && typeof Object.getOwnPropertySymbols === "function")
  17. for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
  18. if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
  19. t[p[i]] = s[p[i]];
  20. }
  21. return t;
  22. };
  23. var __read = (this && this.__read) || function (o, n) {
  24. var m = typeof Symbol === "function" && o[Symbol.iterator];
  25. if (!m) return o;
  26. var i = m.call(o), r, ar = [], e;
  27. try {
  28. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  29. }
  30. catch (error) { e = { error: error }; }
  31. finally {
  32. try {
  33. if (r && !r.done && (m = i["return"])) m.call(i);
  34. }
  35. finally { if (e) throw e.error; }
  36. }
  37. return ar;
  38. };
  39. var __spread = (this && this.__spread) || function () {
  40. for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
  41. return ar;
  42. };
  43. import { regionUphostMap } from '../config';
  44. import { DEFAULT_CHUNK_SIZE } from '../upload';
  45. export function normalizeUploadConfig(config, logger) {
  46. var _a = __assign({}, config), upprotocol = _a.upprotocol, uphost = _a.uphost, otherConfig = __rest(_a, ["upprotocol", "uphost"]);
  47. var normalizeConfig = __assign({ uphost: [], retryCount: 3, checkByMD5: false, forceDirect: false, useCdnDomain: true, checkByServer: false, concurrentRequestLimit: 3, chunkSize: DEFAULT_CHUNK_SIZE, upprotocol: 'https', debugLogLevel: 'OFF', disableStatisticsReport: false }, otherConfig);
  48. // 兼容原来的 http: https: 的写法
  49. if (upprotocol) {
  50. normalizeConfig.upprotocol = upprotocol
  51. .replace(/:$/, '');
  52. }
  53. var hostList = [];
  54. if (logger && (config === null || config === void 0 ? void 0 : config.uphost) != null && (config === null || config === void 0 ? void 0 : config.region) != null) {
  55. logger.warn('do not use both the uphost and region config.');
  56. }
  57. // 如果同时指定了 uphost 参数,添加到可用 host 列表
  58. if (uphost) {
  59. if (Array.isArray(uphost)) {
  60. hostList.push.apply(hostList, __spread(uphost));
  61. }
  62. else {
  63. hostList.push(uphost);
  64. }
  65. // 否则如果用户传了 region,添加指定 region 的 host 到可用 host 列表
  66. }
  67. else if (normalizeConfig === null || normalizeConfig === void 0 ? void 0 : normalizeConfig.region) {
  68. var hostMap = regionUphostMap[normalizeConfig === null || normalizeConfig === void 0 ? void 0 : normalizeConfig.region];
  69. if (normalizeConfig.useCdnDomain) {
  70. hostList.push.apply(hostList, __spread(hostMap.cdnUphost));
  71. }
  72. else {
  73. hostList.push.apply(hostList, __spread(hostMap.srcUphost));
  74. }
  75. }
  76. return __assign(__assign({}, normalizeConfig), { uphost: hostList.filter(Boolean) });
  77. }
  78. //# sourceMappingURL=config.js.map