tim-upload-plugin.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. import {
  2. __commonJS
  3. } from "./chunk-Y2F7D3TJ.js";
  4. // E:/Project/2023/问诊平台/his_user_app/node_modules/tim-upload-plugin/index.js
  5. var require_tim_upload_plugin = __commonJS({
  6. "E:/Project/2023/问诊平台/his_user_app/node_modules/tim-upload-plugin/index.js"(exports, module) {
  7. var global;
  8. var factory;
  9. global = exports, factory = function() {
  10. function e(e2, t2) {
  11. var n2 = Object.keys(e2);
  12. if (Object.getOwnPropertySymbols) {
  13. var o2 = Object.getOwnPropertySymbols(e2);
  14. t2 && (o2 = o2.filter(function(t3) {
  15. return Object.getOwnPropertyDescriptor(e2, t3).enumerable;
  16. })), n2.push.apply(n2, o2);
  17. }
  18. return n2;
  19. }
  20. function t(t2) {
  21. for (var n2 = 1; n2 < arguments.length; n2++) {
  22. var o2 = null != arguments[n2] ? arguments[n2] : {};
  23. n2 % 2 ? e(Object(o2), true).forEach(function(e2) {
  24. s(t2, e2, o2[e2]);
  25. }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(t2, Object.getOwnPropertyDescriptors(o2)) : e(Object(o2)).forEach(function(e2) {
  26. Object.defineProperty(t2, e2, Object.getOwnPropertyDescriptor(o2, e2));
  27. });
  28. }
  29. return t2;
  30. }
  31. function n(e2) {
  32. return (n = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(e3) {
  33. return typeof e3;
  34. } : function(e3) {
  35. return e3 && "function" == typeof Symbol && e3.constructor === Symbol && e3 !== Symbol.prototype ? "symbol" : typeof e3;
  36. })(e2);
  37. }
  38. function o(e2, t2) {
  39. if (!(e2 instanceof t2))
  40. throw new TypeError("Cannot call a class as a function");
  41. }
  42. function r(e2, t2) {
  43. for (var n2 = 0; n2 < t2.length; n2++) {
  44. var o2 = t2[n2];
  45. o2.enumerable = o2.enumerable || false, o2.configurable = true, "value" in o2 && (o2.writable = true), Object.defineProperty(e2, o2.key, o2);
  46. }
  47. }
  48. function a(e2, t2, n2) {
  49. return t2 && r(e2.prototype, t2), n2 && r(e2, n2), Object.defineProperty(e2, "prototype", { writable: false }), e2;
  50. }
  51. function s(e2, t2, n2) {
  52. return t2 in e2 ? Object.defineProperty(e2, t2, { value: n2, enumerable: true, configurable: true, writable: true }) : e2[t2] = n2, e2;
  53. }
  54. function i(e2, t2) {
  55. if (null == e2)
  56. return {};
  57. var n2, o2, r2 = function(e3, t3) {
  58. if (null == e3)
  59. return {};
  60. var n3, o3, r3 = {}, a3 = Object.keys(e3);
  61. for (o3 = 0; o3 < a3.length; o3++)
  62. n3 = a3[o3], t3.indexOf(n3) >= 0 || (r3[n3] = e3[n3]);
  63. return r3;
  64. }(e2, t2);
  65. if (Object.getOwnPropertySymbols) {
  66. var a2 = Object.getOwnPropertySymbols(e2);
  67. for (o2 = 0; o2 < a2.length; o2++)
  68. n2 = a2[o2], t2.indexOf(n2) >= 0 || Object.prototype.propertyIsEnumerable.call(e2, n2) && (r2[n2] = e2[n2]);
  69. }
  70. return r2;
  71. }
  72. var f = "undefined" != typeof wx && "function" == typeof wx.getSystemInfoSync && Boolean(wx.getSystemInfoSync().fontSizeSetting), u = "undefined" != typeof qq && "function" == typeof qq.getSystemInfoSync && Boolean(qq.getSystemInfoSync().fontSizeSetting), l = "undefined" != typeof tt && "function" == typeof tt.getSystemInfoSync && Boolean(tt.getSystemInfoSync().fontSizeSetting), c = "undefined" != typeof swan && "function" == typeof swan.getSystemInfoSync && Boolean(swan.getSystemInfoSync().fontSizeSetting), y = "undefined" != typeof my && "function" == typeof my.getSystemInfoSync && Boolean(my.getSystemInfoSync().fontSizeSetting), d = "undefined" != typeof uni && "undefined" == typeof window && "function" == typeof uni.requireNativePlugin, p = d && "ios" === uni.getDeviceInfo().platform.toLocaleLowerCase(), g = (d && uni.getDeviceInfo().platform.toLocaleLowerCase(), f || u || l || c || y || d), m = u ? qq : l ? tt : c ? swan : y ? my : f ? wx : d ? uni : {}, h = function(e2) {
  73. if ("object" !== n(e2) || null === e2)
  74. return false;
  75. var t2 = Object.getPrototypeOf(e2);
  76. if (null === t2)
  77. return true;
  78. for (var o2 = t2; null !== Object.getPrototypeOf(o2); )
  79. o2 = Object.getPrototypeOf(o2);
  80. return t2 === o2;
  81. };
  82. function v(e2) {
  83. if (null == e2)
  84. return true;
  85. if ("boolean" == typeof e2)
  86. return false;
  87. if ("number" == typeof e2)
  88. return 0 === e2;
  89. if ("string" == typeof e2)
  90. return 0 === e2.length;
  91. if ("function" == typeof e2)
  92. return 0 === e2.length;
  93. if (Array.isArray(e2))
  94. return 0 === e2.length;
  95. if (e2 instanceof Error)
  96. return "" === e2.message;
  97. if (h(e2)) {
  98. for (var t2 in e2)
  99. if (Object.prototype.hasOwnProperty.call(e2, t2))
  100. return false;
  101. return true;
  102. }
  103. return false;
  104. }
  105. var b = function() {
  106. function e2() {
  107. o(this, e2);
  108. }
  109. return a(e2, [{ key: "request", value: function(e3, t2) {
  110. var n2 = this, o2 = e3.downloadUrl || "", r2 = (e3.method || "PUT").toUpperCase(), a2 = e3.url;
  111. if (e3.qs) {
  112. var s2 = function(e4) {
  113. var t3 = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : "&", n3 = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : "=";
  114. return v(e4) ? "" : h(e4) ? Object.keys(e4).map(function(o3) {
  115. var r3 = encodeURIComponent(o3) + n3;
  116. return Array.isArray(e4[o3]) ? e4[o3].map(function(e5) {
  117. return r3 + encodeURIComponent(e5);
  118. }).join(t3) : r3 + encodeURIComponent(e4[o3]);
  119. }).filter(Boolean).join(t3) : void 0;
  120. }(e3.qs);
  121. s2 && (a2 += "".concat(-1 === a2.indexOf("?") ? "?" : "&").concat(s2));
  122. }
  123. var i2 = new XMLHttpRequest();
  124. i2.open(r2, a2, true), i2.responseType = e3.dataType || "text";
  125. var f2 = e3.headers || {};
  126. if (!v(f2))
  127. for (var u2 in f2)
  128. f2.hasOwnProperty(u2) && "content-length" !== u2.toLowerCase() && "user-agent" !== u2.toLowerCase() && "origin" !== u2.toLowerCase() && "host" !== u2.toLowerCase() && i2.setRequestHeader(u2, f2[u2]);
  129. return i2.onload = function() {
  130. if (200 === i2.status)
  131. t2(null, n2._xhrRes(i2, n2._xhrBody(i2, o2)));
  132. else {
  133. var e4 = { code: i2.status, message: JSON.stringify(i2.responseText) };
  134. t2(e4, n2._xhrRes(i2, n2._xhrBody(i2)));
  135. }
  136. }, i2.onerror = function(e4) {
  137. var o3 = n2._xhrBody(i2), r3 = { code: i2.status, message: JSON.stringify(i2.responseText) };
  138. o3 || i2.statusText || 0 !== i2.status || (e4.message = "CORS blocked or network error"), t2(r3, n2._xhrRes(i2, o3)), r3 = null;
  139. }, e3.onProgress && i2.upload && (i2.upload.onprogress = function(t3) {
  140. var n3 = t3.total, o3 = t3.loaded, r3 = Math.floor(100 * o3 / n3);
  141. e3.onProgress({ total: n3, loaded: o3, percent: (r3 >= 100 ? 100 : r3) / 100 });
  142. }), i2.send(e3.resources), i2;
  143. } }, { key: "_xhrRes", value: function(e3, t2) {
  144. var n2 = {};
  145. return e3.getAllResponseHeaders().trim().split("\n").forEach(function(e4) {
  146. if (e4) {
  147. var t3 = e4.indexOf(":"), o2 = e4.substr(0, t3).trim().toLowerCase(), r2 = e4.substr(t3 + 1).trim();
  148. n2[o2] = r2;
  149. }
  150. }), { statusCode: e3.status, statusMessage: e3.statusText, headers: n2, data: t2 };
  151. } }, { key: "_xhrBody", value: function(e3, t2) {
  152. return 200 === e3.status && t2 ? { location: t2 } : { response: e3.responseText };
  153. } }]), e2;
  154. }(), O = ["unknown", "image", "video", "audio", "log"], w = ["name"], S = function() {
  155. function e2() {
  156. o(this, e2);
  157. }
  158. return a(e2, [{ key: "request", value: function(e3, n2) {
  159. var o2 = this, r2 = e3.resources, a2 = void 0 === r2 ? "" : r2, s2 = e3.headers, f2 = void 0 === s2 ? {} : s2, u2 = e3.url, l2 = e3.downloadUrl, c2 = void 0 === l2 ? "" : l2, d2 = u2, g2 = null, h2 = c2.match(/^(https?:\/\/[^/]+\/)([^/]*\/?)(.*)$/), v2 = decodeURIComponent(h2[3]), b2 = { key: v2.indexOf("?") > -1 ? v2.split("?")[0] : v2, success_action_status: 200, "Content-Type": "" }, S2 = {};
  160. if (p) {
  161. var C = u2.split("?sign=");
  162. if (C.length > 1) {
  163. var P = C[1];
  164. d2 = "".concat(C[0], "?sign=").concat(encodeURIComponent("".concat(P))), S2.sign = decodeURIComponent(P), S2.signature = decodeURIComponent(P);
  165. }
  166. }
  167. var j = { url: d2, header: f2, name: "file", filePath: a2, formData: t(t({}, b2), S2), timeout: e3.timeout || 3e5 };
  168. if (y) {
  169. var x = j;
  170. x.name, j = t(t({}, i(x, w)), {}, { fileName: "file", fileType: O[e3.fileType] });
  171. }
  172. return (g2 = m.uploadFile(t(t({}, j), {}, { success: function(e4) {
  173. o2._handleResponse({ response: e4, downloadUrl: c2, callback: n2 });
  174. }, fail: function(e4) {
  175. o2._handleResponse({ response: e4, downloadUrl: c2, callback: n2 });
  176. } }))).onProgressUpdate && g2.onProgressUpdate(function(t2) {
  177. e3.onProgress && e3.onProgress({ total: t2.totalBytesExpectedToSend, loaded: t2.totalBytesSent, percent: Math.floor(t2.progress) / 100 });
  178. }), g2;
  179. } }, { key: "_handleResponse", value: function(e3) {
  180. var n2 = e3.downloadUrl, o2 = e3.response, r2 = e3.callback, a2 = o2.header, s2 = {};
  181. if (a2)
  182. for (var i2 in a2)
  183. a2.hasOwnProperty(i2) && (s2[i2.toLowerCase()] = a2[i2]);
  184. var f2 = +o2.statusCode;
  185. 200 === f2 ? r2(null, { statusCode: f2, headers: s2, data: t(t({}, o2.data), {}, { location: n2 }) }) : r2({ code: f2, message: JSON.stringify(o2.data) }, { statusCode: f2, headers: s2, data: void 0 });
  186. } }]), e2;
  187. }();
  188. return function() {
  189. function e2() {
  190. o(this, e2), console.log("TIMUploadPlugin.VERSION: ".concat("1.2.0")), this.retry = 1, this.tryCount = 0, this.systemClockOffset = 0, this.httpRequest = g ? new S() : new b();
  191. }
  192. return a(e2, [{ key: "uploadFile", value: function(e3, t2) {
  193. var n2 = this;
  194. return this.httpRequest.request(e3, function(o2, r2) {
  195. o2 && n2.tryCount < n2.retry && n2.allowRetry(o2) ? (n2.tryCount++, n2.uploadFile(e3, t2)) : (n2.tryCount = 0, t2(o2, r2));
  196. });
  197. } }, { key: "allowRetry", value: function(e3) {
  198. var t2 = false, n2 = false;
  199. if (e3) {
  200. var o2 = e3.headers && (e3.headers.date || e3.headers.Date) || e3.error && e3.error.ServerTime;
  201. try {
  202. var r2 = e3.error && e3.error.Code, a2 = e3.error && e3.error.Message;
  203. ("RequestTimeTooSkewed" === r2 || "AccessDenied" === r2 && "Request has expired" === a2) && (n2 = true);
  204. } catch (f2) {
  205. }
  206. if (n2 && o2) {
  207. var s2 = Date.now(), i2 = Date.parse(o2);
  208. Math.abs(s2 + this.systemClockOffset - i2) >= 3e4 && (this.systemClockOffset = i2 - s2, t2 = true);
  209. } else
  210. 5 === Math.floor(e3.statusCode / 100) && (t2 = true);
  211. }
  212. return t2;
  213. } }]), e2;
  214. }();
  215. }, "object" == typeof exports && "undefined" != typeof module ? module.exports = factory() : "function" == typeof define && define.amd ? define(factory) : (global = global || self).TIMUploadPlugin = factory();
  216. }
  217. });
  218. export default require_tim_upload_plugin();
  219. //# sourceMappingURL=tim-upload-plugin.js.map