Files
ruo-shan-cloud-pharmacy/miniprogram/package-live/volc-mini-sdk/lib/tt-uploader-miniprogram.js
T
陈誉午 994b267f5c feat: 电子药箱小程序 - 4Tab药品管理
- 电子药箱: 药品库存管理 + 手动录入 + 今日用药打卡
- 药品百科: 搜索 + 分类筛选 + 20种药品静态数据
- 惠教中心: 4条药品使用指南课程
- 我的: 家庭成员信息管理
- 自定义TabBar + navigation-bar组件
- SVG药品分类插图
2026-07-29 11:20:52 +08:00

1 line
84 KiB
JavaScript

"use strict";function _typeof(e){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_typeof(e)}!function(e,t){"object"==("undefined"==typeof exports?"undefined":_typeof(exports))&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TTUploader={})}(void 0,function(e){function t(e,t){(null==t||t>e.length)&&(t=e.length);for(var i=0,s=Array(t);i<t;i++)s[i]=e[i];return s}function i(e,t,i){return t=c(t),function(e,t){if(t&&("object"==_typeof(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,l()?Reflect.construct(t,i||[],c(e).constructor):t.apply(e,i))}function s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t){for(var i=0;i<t.length;i++){var s=t[i];s.enumerable=s.enumerable||!1,s.configurable=!0,"value"in s&&(s.writable=!0),Object.defineProperty(e,y(s.key),s)}}function r(e,t,i){return t&&n(e.prototype,t),i&&n(e,i),Object.defineProperty(e,"prototype",{writable:!1}),e}function o(e,t,i){return(t=y(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}function a(){return a="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(e,t,i){var s=function(e,t){for(;!{}.hasOwnProperty.call(e,t)&&null!==(e=c(e)););return e}(e,t);if(s){var n=Object.getOwnPropertyDescriptor(s,t);return n.get?n.get.call(arguments.length<3?e:i):n.value}},a.apply(null,arguments)}function c(e){return c=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},c(e)}function u(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&f(e,t)}function l(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(l=function(){return!!e})()}function h(e,t){var i=Object.keys(e);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);t&&(s=s.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),i.push.apply(i,s)}return i}function d(e){for(var t=1;t<arguments.length;t++){var i=null!=arguments[t]?arguments[t]:{};t%2?h(Object(i),!0).forEach(function(t){o(e,t,i[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):h(Object(i)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))})}return e}function f(e,t){return f=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},f(e,t)}function p(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var i=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=i){var s,n,r,o,a=[],c=!0,u=!1;try{if(r=(i=i.call(e)).next,0===t){if(Object(i)!==i)return;c=!1}else for(;!(c=(s=r.call(i)).done)&&(a.push(s.value),a.length!==t);c=!0);}catch(e){u=!0,n=e}finally{try{if(!c&&null!=i.return&&(o=i.return(),Object(o)!==o))return}finally{if(u)throw n}}return a}}(e,t)||m(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function g(e,t,i,s){var n=a(c(1&s?e.prototype:e),t,i);return 2&s&&"function"==typeof n?function(e){return n.apply(i,e)}:n}function v(e){return function(e){if(Array.isArray(e))return t(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||m(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function y(e){var t=function(e){if("object"!=_typeof(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var i=t.call(e,"string");if("object"!=_typeof(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==_typeof(t)?t:t+""}function m(e,i){if(e){if("string"==typeof e)return t(e,i);var s={}.toString.call(e).slice(8,-1);return"Object"===s&&e.constructor&&(s=e.constructor.name),"Map"===s||"Set"===s?Array.from(e):"Arguments"===s||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(s)?t(e,i):void 0}}var k="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function _(e){var t={exports:{}};return e(t,t.exports),t.exports}var b=_(function(e){var t=Object.prototype.hasOwnProperty,i="~";function s(){}function n(e,t,i){this.fn=e,this.context=t,this.once=i||!1}function r(e,t,s,r,o){if("function"!=typeof s)throw new TypeError("The listener must be a function");var a=new n(s,r||e,o),c=i?i+t:t;return e._events[c]?e._events[c].fn?e._events[c]=[e._events[c],a]:e._events[c].push(a):(e._events[c]=a,e._eventsCount++),e}function o(e,t){0==--e._eventsCount?e._events=new s:delete e._events[t]}function a(){this._events=new s,this._eventsCount=0}Object.create&&(s.prototype=Object.create(null),(new s).__proto__||(i=!1)),a.prototype.eventNames=function(){var e,s,n=[];if(0===this._eventsCount)return n;for(s in e=this._events)t.call(e,s)&&n.push(i?s.slice(1):s);return Object.getOwnPropertySymbols?n.concat(Object.getOwnPropertySymbols(e)):n},a.prototype.listeners=function(e){var t=i?i+e:e,s=this._events[t];if(!s)return[];if(s.fn)return[s.fn];for(var n=0,r=s.length,o=new Array(r);n<r;n++)o[n]=s[n].fn;return o},a.prototype.listenerCount=function(e){var t=i?i+e:e,s=this._events[t];return s?s.fn?1:s.length:0},a.prototype.emit=function(e,t,s,n,r,o){var a=i?i+e:e;if(!this._events[a])return!1;var c,u,l=this._events[a],h=arguments.length;if(l.fn){switch(l.once&&this.removeListener(e,l.fn,void 0,!0),h){case 1:return l.fn.call(l.context),!0;case 2:return l.fn.call(l.context,t),!0;case 3:return l.fn.call(l.context,t,s),!0;case 4:return l.fn.call(l.context,t,s,n),!0;case 5:return l.fn.call(l.context,t,s,n,r),!0;case 6:return l.fn.call(l.context,t,s,n,r,o),!0}for(u=1,c=new Array(h-1);u<h;u++)c[u-1]=arguments[u];l.fn.apply(l.context,c)}else{var d,f=l.length;for(u=0;u<f;u++)switch(l[u].once&&this.removeListener(e,l[u].fn,void 0,!0),h){case 1:l[u].fn.call(l[u].context);break;case 2:l[u].fn.call(l[u].context,t);break;case 3:l[u].fn.call(l[u].context,t,s);break;case 4:l[u].fn.call(l[u].context,t,s,n);break;default:if(!c)for(d=1,c=new Array(h-1);d<h;d++)c[d-1]=arguments[d];l[u].fn.apply(l[u].context,c)}}return!0},a.prototype.on=function(e,t,i){return r(this,e,t,i,!1)},a.prototype.once=function(e,t,i){return r(this,e,t,i,!0)},a.prototype.removeListener=function(e,t,s,n){var r=i?i+e:e;if(!this._events[r])return this;if(!t)return o(this,r),this;var a=this._events[r];if(a.fn)a.fn!==t||n&&!a.once||s&&a.context!==s||o(this,r);else{for(var c=0,u=[],l=a.length;c<l;c++)(a[c].fn!==t||n&&!a[c].once||s&&a[c].context!==s)&&u.push(a[c]);u.length?this._events[r]=1===u.length?u[0]:u:o(this,r)}return this},a.prototype.removeAllListeners=function(e){var t;return e?(t=i?i+e:e,this._events[t]&&o(this,t)):(this._events=new s,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=i,a.EventEmitter=a,e.exports=a}),w={ERROR:"error",PROGRESS:"progress",1e3:"crc32",1001:"apply",1002:"init",1003:"process",1004:"merge",1005:"complete"},x="vod",S="imagex",C="https://vod.volcengineapi.com",I="https://imagex.volcengineapi.com",O={TRANS:[1002,1003,1004]},A={sdkVersion:"2.3.3",region:"cn-north-1",sliceSize:5242880,uploadSliceCount:3,gatewayTimeout:3e5,uploadTimeout:18e5,noLog:!1,uploadHost:null};function P(e){return e.length<8?P(e="0".concat(e)):e}function U(e){if(void 0!==e)return P(Number(e).toString(16))}function j(e,t){var i=[0,1996959894,3993919788,2567524794,124634137,1886057615,3915621685,2657392035,249268274,2044508324,3772115230,2547177864,162941995,2125561021,3887607047,2428444049,498536548,1789927666,4089016648,2227061214,450548861,1843258603,4107580753,2211677639,325883990,1684777152,4251122042,2321926636,335633487,1661365465,4195302755,2366115317,997073096,1281953886,3579855332,2724688242,1006888145,1258607687,3524101629,2768942443,901097722,1119000684,3686517206,2898065728,853044451,1172266101,3705015759,2882616665,651767980,1373503546,3369554304,3218104598,565507253,1454621731,3485111705,3099436303,671266974,1594198024,3322730930,2970347812,795835527,1483230225,3244367275,3060149565,1994146192,31158534,2563907772,4023717930,1907459465,112637215,2680153253,3904427059,2013776290,251722036,2517215374,3775830040,2137656763,141376813,2439277719,3865271297,1802195444,476864866,2238001368,4066508878,1812370925,453092731,2181625025,4111451223,1706088902,314042704,2344532202,4240017532,1658658271,366619977,2362670323,4224994405,1303535960,984961486,2747007092,3569037538,1256170817,1037604311,2765210733,3554079995,1131014506,879679996,2909243462,3663771856,1141124467,855842277,2852801631,3708648649,1342533948,654459306,3188396048,3373015174,1466479909,544179635,3110523913,3462522015,1591671054,702138776,2966460450,3352799412,1504918807,783551873,3082640443,3233442989,3988292384,2596254646,62317068,1957810842,3939845945,2647816111,81470997,1943803523,3814918930,2489596804,225274430,2053790376,3826175755,2466906013,167816743,2097651377,4027552580,2265490386,503444072,1762050814,4150417245,2154129355,426522225,1852507879,4275313526,2312317920,282753626,1742555852,4189708143,2394877945,397917763,1622183637,3604390888,2714866558,953729732,1340076626,3518719985,2797360999,1068828381,1219638859,3624741850,2936675148,906185462,1090812512,3747672003,2825379669,829329135,1181335161,3412177804,3160834842,628085408,1382605366,3423369109,3138078467,570562233,1426400815,3317316542,2998733608,733239954,1555261956,3268935591,3050360625,752459403,1541320221,2607071920,3965973030,1969922972,40735498,2617837225,3943577151,1913087877,83908371,2512341634,3803740692,2075208622,213261112,2463272603,3855990285,2094854071,198958881,2262029012,4057260610,1759359992,534414190,2176718541,4139329115,1873836001,414664567,2282248934,4279200368,1711684554,285281116,2405801727,4167216745,1634467795,376229701,2685067896,3608007406,1308918612,956543938,2808555105,3495958263,1231636301,1047427035,2932959818,3654703836,1088359270,936918e3,2847714899,3736837829,1202900863,817233897,3183342108,3401237130,1404277552,615818150,3134207493,3453421203,1423857449,601450431,3009837614,3294710456,1567103746,711928724,3020668471,3272380065,1510334235,755167117];"undefined"!=typeof Int32Array&&(i=new Int32Array(i));for(var s=~t,n=(e=new Uint8Array(e)).length,r=0;r<n;r++)s=i[255&(s^e[r])]^s>>>8;return U(~s>>>0)}var T=1000002,D=1001e3,q=1003e3,H=1005e3,R=r(function e(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};s(this,e),this.path=t.path,this.size=t.size,this.uploaderCtx=t.context,this.key=t.key,this.isDirect=t.isDirect,this.isImageBatchUpload=t.isImageBatchUpload,this.config=i},[{key:"start",value:function(e,t,i){if(this.successProcess=t,this.failProcess=i,this.sliceSize=this.size,this._st=Date.now(),this.uploaderCtx.priorInfo._supportCrc32)this.crc32();else{var s=this.uploaderCtx.tasks[this.key];this.successProcess(Object.assign(s,{crc32Array:[0],sliceSize:this.sliceSize,extra:{message:"Skip crc32 stage."},stage:1e3,type:"success",duration:Date.now()-this._st,totalDuration:Date.now()-this._st,isDirect:this.isDirect,isImageBatchUpload:this.isImageBatchUpload}))}}},{key:"crc32",value:function(){var e=this;this.isImageBatchUpload||(this.isDirect?this.getContentCrc32(this.path,0,this.size,function(t){e.success([t])},function(t){e.fail(t)}):(this.sliceSize=this.config.sliceSize,this.sliceFile(this.path,this.sliceSize)))}},{key:"sliceFile",value:function(e,t){for(var i=[],s=this.size,n=0,r=0;r<s;)r=Math.min(n+t,s),s>419430400&&s-r<=5242880&&(r=s),i.push({start:n,end:r,crc32:0}),n=r;this.success(i)}},{key:"getContentCrc32",value:function(e,t,i,s,n){wx.getFileSystemManager().readFile({filePath:e,position:t,length:i-t,success:function(e){var t=0;try{t=j(e.data,0)}catch(e){return n({code:1000003,error:e.toString(),message:"Compute Crc32 value failed."})}s(t)},fail:function(e){n({code:1000001,error:e.errMsg||"",message:"Read file faild."})}})}},{key:"getCrc32Key",value:function(e,t){var i;return(i="[object Array]"===Object.prototype.toString.call(t)?v(t):[t]).push(e[0].crc32,e[e.length-1].crc32),i.join("_")}},{key:"success",value:function(e){var t=this.uploaderCtx,i=this.key,s=t.tasks[i],n=[],r=[];if(this.isImageBatchUpload)for(var o=0;o<this.file.length;o++)n.push(this.file[o].size),r.push(this.file[o].name);else n=this.size;var a=Object.assign(s,{key:i,crc32Array:e,sliceSize:this.sliceSize,extra:{message:"crc32 success"},stage:1e3,type:"success",fileSize:n,duration:Date.now()-this._st,totalDuration:Date.now()-this._st,isDirect:this.isDirect,isImageBatchUpload:this.isImageBatchUpload});this.successProcess(a)}},{key:"fail",value:function(e){var t=d({stage:1e3,type:"error",key:this.key},e);this.failProcess(t)}}]),z=function(e){if(e.__esModule)return e;var t=Object.defineProperty({},"__esModule",{value:!0});return Object.keys(e).forEach(function(i){var s=Object.getOwnPropertyDescriptor(e,i);Object.defineProperty(t,i,s.get?s:{enumerable:!0,get:function(){return e[i]}})}),t}(Object.freeze({__proto__:null,default:{}})),E=_(function(e,t){var i;e.exports=(i=i||function(e){var t;if("undefined"!=typeof window&&window.crypto&&(t=window.crypto),"undefined"!=typeof self&&self.crypto&&(t=self.crypto),"undefined"!=typeof globalThis&&globalThis.crypto&&(t=globalThis.crypto),!t&&"undefined"!=typeof window&&window.msCrypto&&(t=window.msCrypto),!t&&void 0!==k&&k.crypto&&(t=k.crypto),!t)try{t=z}catch(e){}var i=function(){if(t){if("function"==typeof t.getRandomValues)try{return t.getRandomValues(new Uint32Array(1))[0]}catch(e){}if("function"==typeof t.randomBytes)try{return t.randomBytes(4).readInt32LE()}catch(e){}}throw new Error("Native crypto module could not be used to get secure random number.")},s=Object.create||function(){function e(){}return function(t){var i;return e.prototype=t,i=new e,e.prototype=null,i}}(),n={},r=n.lib={},o=r.Base={extend:function(e){var t=s(this);return e&&t.mixIn(e),t.hasOwnProperty("init")&&this.init!==t.init||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},a=r.WordArray=o.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||u).stringify(this)},concat:function(e){var t=this.words,i=e.words,s=this.sigBytes,n=e.sigBytes;if(this.clamp(),s%4)for(var r=0;r<n;r++){var o=i[r>>>2]>>>24-r%4*8&255;t[s+r>>>2]|=o<<24-(s+r)%4*8}else for(var a=0;a<n;a+=4)t[s+a>>>2]=i[a>>>2];return this.sigBytes+=n,this},clamp:function(){var t=this.words,i=this.sigBytes;t[i>>>2]&=4294967295<<32-i%4*8,t.length=e.ceil(i/4)},clone:function(){var e=o.clone.call(this);return e.words=this.words.slice(0),e},random:function(e){for(var t=[],s=0;s<e;s+=4)t.push(i());return new a.init(t,e)}}),c=n.enc={},u=c.Hex={stringify:function(e){for(var t=e.words,i=e.sigBytes,s=[],n=0;n<i;n++){var r=t[n>>>2]>>>24-n%4*8&255;s.push((r>>>4).toString(16)),s.push((15&r).toString(16))}return s.join("")},parse:function(e){for(var t=e.length,i=[],s=0;s<t;s+=2)i[s>>>3]|=parseInt(e.substr(s,2),16)<<24-s%8*4;return new a.init(i,t/2)}},l=c.Latin1={stringify:function(e){for(var t=e.words,i=e.sigBytes,s=[],n=0;n<i;n++){var r=t[n>>>2]>>>24-n%4*8&255;s.push(String.fromCharCode(r))}return s.join("")},parse:function(e){for(var t=e.length,i=[],s=0;s<t;s++)i[s>>>2]|=(255&e.charCodeAt(s))<<24-s%4*8;return new a.init(i,t)}},h=c.Utf8={stringify:function(e){try{return decodeURIComponent(escape(l.stringify(e)))}catch(e){throw new Error("Malformed UTF-8 data")}},parse:function(e){return l.parse(unescape(encodeURIComponent(e)))}},d=r.BufferedBlockAlgorithm=o.extend({reset:function(){this._data=new a.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=h.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var i,s=this._data,n=s.words,r=s.sigBytes,o=this.blockSize,c=r/(4*o),u=(c=t?e.ceil(c):e.max((0|c)-this._minBufferSize,0))*o,l=e.min(4*u,r);if(u){for(var h=0;h<u;h+=o)this._doProcessBlock(n,h);i=n.splice(0,u),s.sigBytes-=l}return new a.init(i,l)},clone:function(){var e=o.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0});r.Hasher=d.extend({cfg:o.extend(),init:function(e){this.cfg=this.cfg.extend(e),this.reset()},reset:function(){d.reset.call(this),this._doReset()},update:function(e){return this._append(e),this._process(),this},finalize:function(e){return e&&this._append(e),this._doFinalize()},blockSize:16,_createHelper:function(e){return function(t,i){return new e.init(i).finalize(t)}},_createHmacHelper:function(e){return function(t,i){return new f.HMAC.init(e,i).finalize(t)}}});var f=n.algo={};return n}(Math),i)}),F=_(function(e,t){var i;e.exports=(i=E,function(e){var t=i,s=t.lib,n=s.WordArray,r=s.Hasher,o=t.algo,a=[],c=[];!function(){function t(t){for(var i=e.sqrt(t),s=2;s<=i;s++)if(!(t%s))return!1;return!0}function i(e){return 4294967296*(e-(0|e))|0}for(var s=2,n=0;n<64;)t(s)&&(n<8&&(a[n]=i(e.pow(s,.5))),c[n]=i(e.pow(s,1/3)),n++),s++}();var u=[],l=o.SHA256=r.extend({_doReset:function(){this._hash=new n.init(a.slice(0))},_doProcessBlock:function(e,t){for(var i=this._hash.words,s=i[0],n=i[1],r=i[2],o=i[3],a=i[4],l=i[5],h=i[6],d=i[7],f=0;f<64;f++){if(f<16)u[f]=0|e[t+f];else{var p=u[f-15],g=(p<<25|p>>>7)^(p<<14|p>>>18)^p>>>3,v=u[f-2],y=(v<<15|v>>>17)^(v<<13|v>>>19)^v>>>10;u[f]=g+u[f-7]+y+u[f-16]}var m=s&n^s&r^n&r,k=(s<<30|s>>>2)^(s<<19|s>>>13)^(s<<10|s>>>22),_=d+((a<<26|a>>>6)^(a<<21|a>>>11)^(a<<7|a>>>25))+(a&l^~a&h)+c[f]+u[f];d=h,h=l,l=a,a=o+_|0,o=r,r=n,n=s,s=_+(k+m)|0}i[0]=i[0]+s|0,i[1]=i[1]+n|0,i[2]=i[2]+r|0,i[3]=i[3]+o|0,i[4]=i[4]+a|0,i[5]=i[5]+l|0,i[6]=i[6]+h|0,i[7]=i[7]+d|0},_doFinalize:function(){var t=this._data,i=t.words,s=8*this._nDataBytes,n=8*t.sigBytes;return i[n>>>5]|=128<<24-n%32,i[14+(n+64>>>9<<4)]=e.floor(s/4294967296),i[15+(n+64>>>9<<4)]=s,t.sigBytes=4*i.length,this._process(),this._hash},clone:function(){var e=r.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=r._createHelper(l),t.HmacSHA256=r._createHmacHelper(l)}(Math),i.SHA256)}),N=(_(function(e,t){var i;e.exports=(i=E,void function(){var e=i,t=e.lib.Base,s=e.enc.Utf8;e.algo.HMAC=t.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=s.parse(t));var i=e.blockSize,n=4*i;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),o=this._iKey=t.clone(),a=r.words,c=o.words,u=0;u<i;u++)a[u]^=1549556828,c[u]^=909522486;r.sigBytes=o.sigBytes=n,this.reset()},reset:function(){var e=this._hasher;e.reset(),e.update(this._iKey)},update:function(e){return this._hasher.update(e),this},finalize:function(e){var t=this._hasher,i=t.finalize(e);return t.reset(),t.finalize(this._oKey.clone().concat(i))}})}())}),_(function(e,t){e.exports=E.HmacSHA256})),M={getUnique:function(e){return"".concat(e,"_").concat(Date.now(),"_").concat(parseInt(1e6*Math.random()))},resolveUri:function(e){if(!e)return"";if(Array.isArray(e))return e.map(function(e){try{return e.split("/")[0]+"/"+encodeURIComponent(e.split("/").slice(1).join("/"))}catch(t){return e}});try{return e.split("/")[0]+"/"+encodeURIComponent(e.split("/").slice(1).join("/"))}catch(t){return e}},decodeUri:function(e){if(!e)return"";if(Array.isArray(e))return e.map(function(e){try{return e.split("/")[0]+"/"+decodeURIComponent(e.split("/").slice(1).join("/"))}catch(t){return e}});try{return e.split("/")[0]+"/"+decodeURIComponent(e.split("/").slice(1).join("/"))}catch(t){return e}},crypto:{hmac:function(e,t){return N(t,e)},sha256:function(e){return F(e)}},toQueryString:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return Object.keys(e).map(function(t){return"".concat(t,"=").concat(encodeURIComponent(e[t]))}).join("&")},date:{iso8601:function(e){return void 0===e&&(e=M.date.getDate()),e.toISOString().replace(/\.\d{3}Z$/,"Z")}},getFileSuffix:function(e){if(e&&"[object String]"===Object.prototype.toString.call(e)){var t=e.lastIndexOf(".");if(t>0){var i="."+e.substring(t+1);if(i.length<=8)return i}}},formatUploadHeader:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1]?{"X-Upload-Storage-Mode":"gateway"}:{};return"[object Array]"===Object.prototype.toString.call(e)?e.forEach(function(e){e.Key&&e.Value&&(t[e.Key.toLowerCase()]=e.Value)}):"[object Object]"===Object.prototype.toString.call(e)&&Object.assign(t,e),"gateway"!==t["X-Storage-Mode"]&&"gateway"!==t["x-storage-mode"]||(t["X-Upload-Storage-Mode"]="gateway"),t},urlTemplate:function(e,t){var i;return t=t||{},Object.keys(t).forEach(function(s){i=new RegExp("{".concat(s,"}"),"g"),e=e.replace(i,t[s])}),e}},B=function(){try{var e;return!!(null===(e=wx)||void 0===e?void 0:e.getFileSystemManager()).readFile}catch(e){return!1}},$=["authorization","content-type","content-length","user-agent","presigned-expires","expect","x-amzn-trace-id"],K=function(e){try{return encodeURIComponent(e).replace(/[^A-Za-z0-9_.~\-%]+/g,escape).replace(/[*]/g,function(e){return"%".concat(e.charCodeAt(0).toString(16).toUpperCase())})}catch(e){return""}},L=function(e){return Object.keys(e).sort().map(function(t){var i=e[t];if(null!=i){var s=K(t);if(s)return Array.isArray(i)?"".concat(s,"=").concat(i.map(K).sort().join("&".concat(s,"="))):"".concat(s,"=").concat(K(i))}}).filter(function(e){return e}).join("&")},V=r(function e(t,i,n){s(this,e),this.request=t,this.request.headers=t.headers||{},this.serviceName=i,n=n||{},this.signatureCache="boolean"!=typeof n.signatureCache||n.signatureCache,this.operation=n.operation,this.signatureVersion=n.signatureVersion,this.constant=n.isVolcengine?{algorithm:"HMAC-SHA256",v4Identifier:"request",dateHeader:"X-Date",tokenHeader:"x-security-token",contentSha256Header:"X-Content-Sha256",kDatePrefix:""}:{algorithm:"AWS4-HMAC-SHA256",v4Identifier:"aws4_request",dateHeader:"X-Amz-Date",tokenHeader:"x-amz-security-token",contentSha256Header:"X-Amz-Content-Sha256",kDatePrefix:"AWS4"},this.bodySha256=n.bodySha256},[{key:"addAuthorization",value:function(e,t){var i=this.iso8601(t).replace(/[:\-]|\.\d{3}/g,"");this.addHeaders(e,i),this.request.headers.Authorization=this.authorization(e,i)}},{key:"addHeaders",value:function(e,t){if(this.request.headers[this.constant.dateHeader]=t,e.sessionToken&&(this.request.headers[this.constant.tokenHeader]=e.sessionToken),this.request.body){var i=this.request.body;"string"!=typeof i&&(i=i instanceof URLSearchParams?i.toString():JSON.stringify(i)),this.request.headers[this.constant.contentSha256Header]=this.bodySha256||M.crypto.sha256(i).toString()}}},{key:"authorization",value:function(e,t){var i=[],s=this.credentialString(t);return i.push("".concat(this.constant.algorithm," Credential=").concat(e.accessKeyId,"/").concat(s)),i.push("SignedHeaders=".concat(this.signedHeaders())),i.push("Signature=".concat(this.signature(e,t))),i.join(", ")}},{key:"signature",value:function(e,t){var i=this.getSigningKey(e,t.substr(0,8),this.request.region,this.serviceName,this.signatureCache);return M.crypto.hmac(i,this.stringToSign(t),"hex")}},{key:"stringToSign",value:function(e){var t=[];return t.push(this.constant.algorithm),t.push(e),t.push(this.credentialString(e)),t.push(this.hexEncodedHash(this.canonicalString())),t.join("\n")}},{key:"canonicalString",value:function(){var e=[],t=this.request.pathname||"/";return e.push(this.request.method.toUpperCase()),e.push(t),e.push(L(this.request.params)||""),e.push("".concat(this.canonicalHeaders(),"\n")),e.push(this.signedHeaders()),e.push(this.hexEncodedBodyHash()),e.join("\n")}},{key:"canonicalHeaders",value:function(){var e=this,t=[];Object.keys(this.request.headers).forEach(function(i){t.push([i,e.request.headers[i]])}),t.sort(function(e,t){return e[0].toLowerCase()<t[0].toLowerCase()?-1:1});var i=[];return t.forEach(function(t){var s=t[0].toLowerCase();if(e.isSignableHeader(s)){var n=t[1];if(null==n||"function"!=typeof n.toString)throw new Error("Header ".concat(s," contains invalid value"));i.push("".concat(s,":").concat(e.canonicalHeaderValues(n.toString())))}}),i.join("\n")}},{key:"canonicalHeaderValues",value:function(e){return e.replace(/\s+/g," ").replace(/^\s+|\s+$/g,"")}},{key:"signedHeaders",value:function(){var e=this,t=[];return Object.keys(this.request.headers).forEach(function(i){i=i.toLowerCase(),e.isSignableHeader(i)&&t.push(i)}),t.sort().join(";")}},{key:"credentialString",value:function(e){return this.createScope(e.substr(0,8),this.request.region,this.serviceName)}},{key:"hexEncodedHash",value:function(e){return M.crypto.sha256(e)}},{key:"hexEncodedBodyHash",value:function(){return this.request.headers[this.constant.contentSha256Header]?this.request.headers[this.constant.contentSha256Header]:this.request.body?this.hexEncodedHash(L(this.request.body)):this.hexEncodedHash("")}},{key:"isSignableHeader",value:function(e){return 0===e.toLowerCase().indexOf("x-amz-")||$.indexOf(e)<0}},{key:"iso8601",value:function(e){return void 0===e&&(e=new Date),e.toISOString().replace(/\.\d{3}Z$/,"Z")}},{key:"getSigningKey",value:function(e,t,i,s){var n=M.crypto.hmac("".concat(this.constant.kDatePrefix).concat(e.secretAccessKey),t),r=M.crypto.hmac(n,i),o=M.crypto.hmac(r,s);return M.crypto.hmac(o,this.constant.v4Identifier)}},{key:"createScope",value:function(e,t,i){return[e.substr(0,8),t,i,this.constant.v4Identifier].join("/")}}]),J=r(function e(t,i){s(this,e),this.options=t,this.config=i,this.uploaderCtx=t.context,this.currFileCtx=t.context.tasks[t.key],this.isImageBatchUpload=!!this.options.isImageBatchUpload,this.serviceName=t.serviceName||x},[{key:"start",value:function(e,t,i){this.successProcess=t,this.failProcess=i,this._st=Date.now(),this.startPreUpload()}},{key:"startPreUpload",value:function(){var e,t=this,i=this.config.region,s=this.serviceName,n="",r={};if(s===S?(n=this.config.imageHost||I,r={Action:"ApplyImageUpload",Version:"2018-08-01",ServiceId:this.options.serviceId||this.config.imageConfig.serviceId},this.options.storeKey&&(r.StoreKeys=[this.options.storeKey]),this.options.prefix&&(r.Prefix=this.options.prefix),this.options.overwrite&&(r.Overwrite=!0)):(n=this.config.videoHost||C,r={Action:"ApplyUploadInfo",Version:"2022-01-01",SpaceName:null===(e=this.config)||void 0===e||null===(e=e.videoConfig)||void 0===e?void 0:e.spaceName,FileSize:this.currFileCtx.fileSize,FileType:this.options.type,NeedFallback:!0},this.options.fileName&&(r.FileName=this.options.fileName),this.options.storageClass&&(r.StorageClass=this.options.storageClass)),this.config.useFileExtension&&this.currFileCtx.filePath){var o=this.currFileCtx.filePath,a=M.getFileSuffix(o);a&&(r.FileExtension=a)}this.options.fileExtension&&(r.FileExtension=this.options.fileExtension),this.config.accountId&&(r["X-Account-Id"]=this.config.accountId),r.s=Math.random().toString(36).substr(2),r.UseAppletsHosts=!0;var c=this.currFileCtx.proxyStsToken||this.config.stsToken,u=M.toQueryString(r),l=c.AccessKeyID,h=c.AccessKeyId,d=c.SecretAccessKey,f=c.SessionToken,p={method:"GET",url:"".concat(n,"?").concat(u),timeout:this.config.gatewayTimeout,region:i,params:r};new V(p,s,{isVolcengine:!0}).addAuthorization({accessKeyId:h||l,secretAccessKey:d,sessionToken:f},new Date),wx.request({method:"GET",url:p.url,header:p.headers,success:function(e){var i,s,n,r,o,a,c=e.data,u=e.statusCode;200!==u||null!==(i=c.ResponseMetadata)&&void 0!==i&&i.Error?t.fail({statusCode:u,error:"".concat(null===(s=c.ResponseMetadata)||void 0===s||null===(s=s.Error)||void 0===s?void 0:s.Code,", RequestId:").concat(null===(n=c.ResponseMetadata)||void 0===n?void 0:n.RequestId,"."),message:"".concat(null===(r=c.ResponseMetadata)||void 0===r||null===(r=r.Error)||void 0===r?void 0:r.Message," RequestId:").concat(null===(o=c.ResponseMetadata)||void 0===o?void 0:o.RequestId,"."),code:(null===(a=c.ResponseMetadata)||void 0===a||null===(a=a.Error)||void 0===a?void 0:a.CodeN)||D}):t.success(c.Result,c)},fail:function(e){t.fail({error:"Unknown network error when applyupload",code:e.errno||D,message:e.errMsg||"Unknown network error when applyupload"})}})}},{key:"success",value:function(e,t){var i,s,n,r,o,a=this.serviceName===S?e.UploadAddress:null!==(n=null===(r=e.Data)||void 0===r||null===(r=r.CandidateUploadAddresses)||void 0===r||null===(r=r.MainUploadAddresses)||void 0===r?void 0:r[0])&&void 0!==n?n:null===(o=e.Data)||void 0===o?void 0:o.UploadAddress;a.Cloud;var c,u,l=a.StoreInfos,h=a.UploadHosts,d=a.SessionKey,f=a.UploadHeader;if(this.serviceName===x){var p,g=(null===(p=e.Data)||void 0===p?void 0:p.CandidateUploadAddresses)||{},v=g.BackupUploadAddresses,y=void 0===v?[]:v,m=g.FallbackUploadAddresses,k=void 0===m?[]:m,_=y.concat(k);_.length&&_.length>0&&(c=_.map(function(e){var t=e.Cloud,i=e.SessionKey,s=e.StoreInfos,n=e.UploadHeader,r=e.UploadHosts;return{Cloud:t,SessionKey:i,UploadHeader:n,StoreInfo:s[0],UploadHost:r[0]}}))}u=this.config.uploadHost?"https://".concat(this.config.uploadHost):"https://".concat(h[0]);var b=Object.assign(this.currFileCtx,{signature:null===(i=l[0])||void 0===i?void 0:i.Auth,type:"success",extra:{message:"prepare upload success"},stage:1001,oid:M.resolveUri(null===(s=l[0])||void 0===s?void 0:s.StoreUri),tosDomain:u,uploadHeader:M.formatUploadHeader(f,this.currFileCtx.gatewayUpload),sessionKey:d,res:t,duration:Date.now()-this._st,totalDuration:Date.now()-this._st+this.currFileCtx.totalDuration,fallbackStoreInfoList:c});return this.successProcess(b)}},{key:"fail",value:function(e){var t=d({type:"error",key:this.options.key,stage:1001},e);this.failProcess(t)}}]),X=r(function e(t,i){s(this,e),this.uploaderCtx=t.context,this.key=t.key,this.currFileCtx=this.uploaderCtx.tasks[this.key],this.config=i},[{key:"start",value:function(e,t,i){this.successProcess=t,this.failProcess=i,this._st=Date.now(),this.initUpload()}},{key:"initUpload",value:function(){var e=this,t=this.currFileCtx,i={oid:t.oid,tosDomain:t.tosDomain},s=M.urlTemplate("{tosDomain}/upload/v1/{oid}?uploadmode=part&phase=init",i),n=this.config.userId,r=t.uploadHeader;wx.request({method:"POST",url:s,timeout:this.config.uplaodTimeout,header:d({authorization:t.signature,"x-storage-u":n},r),success:function(t){var i,s=t.statusCode,n=t.data;2e3===(null==n?void 0:n.code)&&null!=n&&null!==(i=n.data)&&void 0!==i&&i.uploadid?e.success(n.data.uploadid):e.fail({statusCode:s,error:"Init phase failed.",message:n.message,code:n.code})},fail:function(t){e.fail({error:"Unknown network error when init",code:t.errno||1002e3,message:t.errMsg||"Unknown network error when init"})}})}},{key:"success",value:function(e){var t=this.currFileCtx,i=Object.assign(t,{uploadId:e,percent:0,type:"success",extra:{message:"Init upload success."},stage:1002,duration:Date.now()-this._st,totalDuration:Date.now()-this._st+t.totalDuration});this.successProcess(i)}},{key:"fail",value:function(e){var t=d({type:"error",key:this.key,stage:1002},e);this.failProcess(t)}}]),W=function(e){function t(e){var n;return s(this,t),(n=i(this,t)).crc32=e.crc32,n.url=e.url,n.uploadHeader=e.uploadHeader||{},n.oid=e.oid,n.signature=e.signature,n.timeout=e.timeout,n.uploadTask=null,n}return u(t,e),r(t,[{key:"upload",value:function(e){var t=this,i={url:this.url,filePath:e,name:decodeURIComponent(this.oid.split("/")[1]),header:d({Authorization:this.signature,"Content-CRC32":0===this.crc32?"Ignore":this.crc32},this.uploadHeader),timeout:this.timeout,success:function(e){var i=e.statusCode,s=e.data,n=e.header;try{s=JSON.parse(s)}catch(e){console.warn(e)}200===i&&2e3===s.code?t.success(s):t.fail({statusCode:i,error:"Upload failed, oid:".concat(t.oid),code:s.code,message:"".concat(s.message,".request log id:").concat(n["X-Tt-Logid"]||n["X-Upload-Request-Id"]),direct:!0})},fail:function(e){t.fail({error:"Upload failed, oid:".concat(t.oid),code:e.errno||q,message:e.errMsg,direct:!0})},complete:function(){t.uploadTask=null}};this.uploadTask=wx.uploadFile(i),this.uploadTask.onProgressUpdate(function(e){t.progress(e)})}},{key:"uploadSlice",value:function(e,t,i){var s=this,n={url:this.url,data:e,header:d({authorization:this.signature,"content-crc32":this.crc32,"content-type":"application/octet-stream"},this.uploadHeader),timeout:this.timeout,method:"POST",success:function(e){var n=e.statusCode,r=e.data,o=e.header;if(200===n&&2e3===r.code)s.success(t);else{var a=null;try{a=JSON.stringify(r.data)}catch(e){console.warn(e)}s.fail({statusCode:n,code:r.code||q,error:"".concat(a||"upload slice failed",", uploadId:").concat(i),message:"".concat(r.message,".request log id:").concat(o["X-Tt-Logid"]||o["X-Upload-Request-Id"]||o["x-tt-logid"]||o["x-upload-request-id"])})}},fail:function(e){s.fail({error:"upload slice failed, uploadId:".concat(i),code:e.errno||q,message:e.errMsg})},complete:function(){s.uploadTask.offProgressUpdate(),s.uploadTask=null}};this.uploadTask=wx.request(n)}},{key:"success",value:function(e){this.emit("success",e)}},{key:"fail",value:function(e){this.emit("error",e)}},{key:"progress",value:function(e){this.emit("progress",e)}},{key:"abort",value:function(){this.uploadTask&&this.uploadTask.abort()}}])}(b),G=r(function e(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};s(this,e),this.path=t.path,this.size=t.size,this.uploaderCtx=t.context,this.key=t.key,this.config=i,this.currFileCtx=this.uploaderCtx.tasks[this.key],this.finishSize=0,this.finishArr=[],this.uploadSliceCount=Number(i.uploadSliceCount)||3,this.percent=0},[{key:"start",value:function(e,t,i){this.failProcess=i,this.successProcess=t,this.crc32Array=this.currFileCtx.crc32Array,this.uploadSliceCount=this.uploadSliceCount>this.crc32Array.length?this.crc32Array.length:this.uploadSliceCount,this.lastIndex=0,this.uploading=[],this.uploadHandlers={},this.currFileCtx.useFallback&&(this.crc32Array.forEach(function(e){e.finished=!1,e.loaded=0,e.speed=0}),this.finishArr=[],this.finishSize=0),this._st=Date.now(),this.threadUpload()}},{key:"threadUpload",value:function(){if(!(this.uploading.length>=this.uploadSliceCount)){var e=this.lastIndex,t=this.crc32Array[e];if(t){if(t.finished){if(-1===this.finishArr.indexOf(t.start)&&(this.finishArr.push(t.start),this.finishArr.length===this.crc32Array.length))return this.stop(),void this.success()}else this.uploading.push(e),this.read(t,e);this.lastIndex++,this.threadUpload()}}}},{key:"read",value:function(e,t){var i=this;wx.getFileSystemManager().readFile({filePath:this.path,position:e.start,length:e.end-e.start,success:function(s){var n=0;try{n=j(s.data,0),e.crc32=n}catch(e){return i.fail(e)}i.upload(e,s.data,t)},fail:function(e){i.fail(e)}})}},{key:"upload",value:function(e,t,i){var s=this,n=e.crc32,r=this.currFileCtx,o=r.uploadId,a=r.oid,c=r.tosDomain,u=r.signature,l={part_number:i+1,uploadId:o,oid:a,tosDomain:c},h=M.urlTemplate("{tosDomain}/upload/v1/{oid}?uploadid={uploadId}&part_number={part_number}&phase=transfer",l),d=M.formatUploadHeader(r.uploadHeader,r.gatewayUpload),f=new W({crc32:n,url:h,uploadHeader:d,oid:a,signature:u,timeout:this.config.uploadTimeout});f.on("success",function(e){e.sliceIndex=i,s.fileSliceSuccess(e)}),f.on("error",function(e){1===s.currFileCtx.status&&(s.currFileCtx.userCanceled&&/abort/g.test(e.message)||s.fail(Object.assign(e,{sliceIndex:i})))}),f.uploadSlice(t,e,o),this.uploadHandlers["".concat(n,"_").concat(i)]=f}},{key:"fileSliceSuccess",value:function(e){var t=e.sliceIndex;if(-1===this.finishArr.indexOf(e.start)&&(this.finishArr.push(e.start),this.finishSize+=e.end-e.start),this.crc32Array[t].finished=!0,this.uploading.splice(this.uploading.indexOf(t),1),this.uploadHandlers[t]&&delete this.uploadHandlers[t],this.uploaderCtx.logger.send({key:this.key,stage:1003,type:"success",slice_index:t,extra:{message:"slice upload success"}},!0),1===this.currFileCtx.status){var i=Math.round(this.finishSize/this.size*100);if(this.percent=Math.max(this.percent,i),this.uploaderCtx._broadcast(w.PROGRESS,{percent:Math.min(this.percent,99),totalSize:this.size,sentSize:this.finishSize,key:this.key,oid:this.currFileCtx.oid,uploadId:this.currFileCtx.uploadId,sliceIndex:t+1}),this.finishArr.length>=this.crc32Array.length)return this.stop(),void this.success(e);this.threadUpload()}}},{key:"success",value:function(e){var t=Date.now()-this._st,i=Math.round(this.size/t),s=this.currFileCtx,n=Object.assign(s,{type:"success",stage:1003,percent:99,extra:{message:"upload all slice success."},speed:i,duration:t,totalDuration:Date.now()-this._st+s.totalDuration,isAllFinish:!0});this.successProcess(n)}},{key:"fail",value:function(e){this.stop();var t=d({type:"error",key:this.key,uploadId:this.currFileCtx.uploadId,oid:this.currFileCtx.oid,stage:1003},e);this.failProcess(t)}},{key:"stop",value:function(){Object.values(this.uploadHandlers).forEach(function(e){e&&e.abort&&e.abort()})}}]),Z=r(function e(t,i){s(this,e),this.uploaderCtx=t.context,this.key=t.key,this.currFileCtx=this.uploaderCtx.tasks[this.key],this.config=i},[{key:"start",value:function(e,t,i){this.successProcess=t,this.failProcess=i,this._st=Date.now(),this.mergeFile()}},{key:"mergeFile",value:function(){for(var e=this,t=this.currFileCtx,i={oid:t.oid,uploadId:t.uploadId,tosDomain:t.tosDomain},s=t.crc32Array,n="",r=0;r<s.length;r++)n=n?"".concat(n,",").concat(r+1,":").concat(s[r].crc32):"".concat(r+1,":").concat(s[r].crc32);var o=M.urlTemplate("{tosDomain}/upload/v1/{oid}?uploadmode=part&phase=finish&uploadid={uploadId}",i),a=this.config.userId,c=M.formatUploadHeader(t.uploadHeader,t.gatewayUpload),u=d({Authorization:t.signature,"X-Storage-U":encodeURIComponent(a)},c);wx.request({url:o,data:n,header:u,timeout:this.config.uploadTimeout,method:"POST",success:function(i){var s=i.data,n=i.statusCode,r=i.header;2e3===(null==s?void 0:s.code)?e.success():e.fail({statusCode:n,code:s.code,message:"".concat(s.message,".request log id:").concat(r["X-Tt-Logid"]||r["X-Upload-Request-Id"]),error:"Merge file failed, uploadId:".concat(t.uploadId)})},fail:function(t){e.fail({error:"Unknown network error when merge",code:t.errno||1004e3,message:t.errMsg||"Unknown network error when merge"})}})}},{key:"success",value:function(){var e=this.currFileCtx,t=Date.now()-this._st+e.totalDuration,i=Object.assign(e,{stage:1004,type:"success",hasMerge:!0,extra:{message:"Merge file success."},duration:Date.now()-this._st,totalDuration:t,speed:Math.round(e.fileSize/t)});this.successProcess(i)}},{key:"fail",value:function(e){var t=d(d({type:"error",key:this.key,stage:1004,oid:this.currFileCtx.oid,uploadId:this.currFileCtx.uploadId},e),{},{duration:Date.now()-this._st});this.failProcess(t)}}]),Q=r(function e(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};s(this,e),this.path=t.path,this.size=t.size,this.uploaderCtx=t.context,this.key=t.key,this.currentCtx=this.uploaderCtx.tasks[this.key],this.isImageBatchUpload=t.isImageBatchUpload,this.config=i,this.percent=0,this.totalBytesSent=0},[{key:"start",value:function(e,t,i){this.successProcess=t,this.failProcess=i,this.crc32Array=this.currentCtx.crc32Array,this.uploadHandlers={},this._st=Date.now(),this.upload()}},{key:"upload",value:function(){for(var e=this,t=this.crc32Array.length,i=0,s=0,n=this.currentCtx,r=0;r<t;r++){var o=this.crc32Array[r],a=this.currentCtx.oid,c=this.currentCtx.signature,u={oid:"[object Array]"===Object.prototype.toString.call(a)?a[r]:a,tosDomain:this.currentCtx.tosDomain},l=M.urlTemplate("{tosDomain}/upload/v1/{oid}",u),h=new W({crc32:o,url:l,oid:a,uploadHeader:this.currentCtx.uploadHeader||{},signature:"[object Array]"===Object.prototype.toString.call(c)?c[r]:c,timeout:this.config.uploadTimeout});this.uploadHandlers["".concat(o,"_").concat(r)]=h,h.on("success",function(n){i++,s+i===t&&e.success(n)}),h.on("error",function(i){n.userCanceled&&/abort/g.test(i.message)||++s===t&&e.fail(i)}),h.on("progress",function(t){e.progress(t)}),h.upload(this.path)}}},{key:"progress",value:function(e){this.percent=Math.max(e.progress,this.percent),this.totalBytesSent=Math.max(e.totalBytesSent,this.totalBytesSent),this.uploaderCtx._broadcast(w.PROGRESS,{percent:Math.min(this.percent,99),totalSize:e.totalBytesExpectedToSend||this.size,sentSize:this.totalBytesSent,key:this.key,oid:this.currentCtx.oid})}},{key:"success",value:function(e){var t=Date.now()-this._st+this.currentCtx.totalDuration,i=Object.assign(this.currentCtx,{type:"success",stage:1003,percent:99,extra:{message:"direct upload success"},duration:Date.now()-this._st,totalDuration:t,speed:Math.round(this.currentCtx.fileSize/t)});this.uploadHandlers={},this.successProcess(i)}},{key:"fail",value:function(e){var t=d(d({type:"error",key:this.key,stage:1003,oid:this.currentCtx.oid},e),{},{duration:Date.now()-this._st});this.failProcess(t)}},{key:"stop",value:function(){Object.values(this.uploadHandlers).forEach(function(e){e&&e.abort()})}}]),Y=r(function e(t,i){s(this,e),this.uploaderCtx=t.context,this.currFileCtx=t.context.tasks[t.key],this.isImageBatchUpload=!!t.isImageBatchUpload,this.processAction=t.processAction,this.skipCommit=t.skipCommit,this.serviceName=t.serviceName||x,this.options=t,this.config=i},[{key:"start",value:function(e,t,i){if(this.successProcess=t,this.failProcess=i,this._st=Date.now(),this.skipCommit&&this.serviceName===S){var s=Date.now()-this._st+this.currFileCtx.totalDuration;return this.successProcess(Object.assign(this.currFileCtx,{stage:1005,type:"success",percent:100,extra:{message:"upload successful, skip commit"},duration:Date.now()-this._st,totalDuration:s,speed:Math.round(this.currFileCtx.fileSize/s),skipCommit:this.skipCommit}))}this.commitUpload()}},{key:"commitUpload",value:function(){var e,t=this,i=this.config.region,s="",n={},r=this.serviceName;if(r===S)s=this.config.imageHost||I,n={Action:"CommitImageUpload",Version:"2018-08-01",ServiceId:this.options.serviceId||this.config.imageConfig.serviceId},this.options.skipMeta&&(n.SkipMeta=this.options.skipMeta),e={SessionKey:this.currFileCtx.sessionKey,SuccessOids:M.decodeUri(Array.isArray(this.currFileCtx.oid)?this.currFileCtx.oid:[this.currFileCtx.oid])};else{var o=this.config.videoConfig&&this.config.videoConfig.spaceName;s=this.config.videoHost||C,n={Action:"CommitUploadInfo",Version:"2022-01-01",SpaceName:o},e={SessionKey:this.currFileCtx.sessionKey};var a=this.processAction;Array.isArray(a)&&a.length>0&&(e.Functions=a),this.options.callbackArgs&&(e.CallbackArgs=this.options.callbackArgs)}this.config.accountId&&(n["X-Account-Id"]=this.config.accountId);var c=M.toQueryString(n),u=this.currFileCtx.proxyStsToken,l=u.AccessKeyID,h=u.AccessKeyId,d=u.SecretAccessKey,f=u.SessionToken,p={method:"POST",url:"".concat(s,"?").concat(c),timeout:this.config.gatewayTimeout,region:i,params:n,headers:{}};if(r===x){var g=Object.keys(e).map(function(t){return"[object Array]"===Object.prototype.toString.call(e[t])||"[object Object]"===Object.prototype.toString.call(e[t])?"".concat(t,"=").concat(encodeURIComponent(JSON.stringify(e[t]))):"".concat(t,"=").concat(encodeURIComponent(e[t]))}).join("&");p.headers["Content-Type"]="application/x-www-form-urlencoded",p.body=g}else p.headers["Content-Type"]="application/json",p.body=JSON.stringify(e);new V(p,r,{isVolcengine:!0}).addAuthorization({accessKeyId:h||l,secretAccessKey:d,sessionToken:f},new Date),wx.request({method:"POST",url:p.url,header:p.headers,data:p.body,success:function(e){var i,s,n,r,o,a=e.data,c=e.statusCode;200!==c||null!==(i=a.ResponseMetadata)&&void 0!==i&&i.Error?t.fail({statusCode:c,error:null===(s=a.ResponseMetadata)||void 0===s||null===(s=s.Error)||void 0===s?void 0:s.Code,message:"".concat(null===(n=a.ResponseMetadata)||void 0===n||null===(n=n.Error)||void 0===n?void 0:n.Message,",RequestId:").concat(null===(r=a.ResponseMetadata)||void 0===r?void 0:r.RequestId,"."),code:(null===(o=a.ResponseMetadata)||void 0===o||null===(o=o.Error)||void 0===o?void 0:o.CodeN)||H}):t.success(a.Result)},fail:function(e){t.fail({error:"Unknown network error when commit",code:e.errno||H,message:e.errMsg||"Unknown network error when commit"})}})}},{key:"success",value:function(e){var t;if(this.serviceName===S){var i=e.PluginResult,s=void 0===i?[]:i,n=e.Results,r=void 0===n?[]:n;try{t=r.map(function(e,t){return d(d({},e),s[t])})}catch(e){console.warn("[1005 error]:",e.toString())}}else t=e.Data;var o=Date.now()-this._st+this.currFileCtx.totalDuration,a=Object.assign(this.currFileCtx,{stage:1005,type:"success",percent:100,extra:{message:"upload successful"},uploadResult:t,duration:Date.now()-this._st,totalDuration:o,speed:Math.round(this.currFileCtx.fileSize/o)});this.successProcess(a)}},{key:"fail",value:function(e){var t=d({type:"error",key:this.options.key,stage:1005},e);this.failProcess(t)}}]),ee=function(e){function t(e){var n,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=arguments.length>2?arguments[2]:void 0,a=arguments.length>3?arguments[3]:void 0;return s(this,t),(n=i(this,t,[e])).tasks=e,n.config=r,n.uploaderCtx=o,n.key=a,n.currFileCtx=n.uploaderCtx.tasks[n.key],n.current=0,n.taskError={},n.retryTaskTime=r.retryTaskTime||3,n}return u(t,e),r(t,[{key:"addTask",value:function(e){this.tasks.push(e)}},{key:"start",value:function(){var e=this.tasks.shift();e&&(this.current=e.index,this.execTask(e))}},{key:"execTask",value:function(e){var t=this,i=e.key,s=this.uploaderCtx,n=s.tasks[i];if(n){var r=n.cacheTask;!n.useFallback&&r&&e.index>0&&e.index<r?this.start():(n.currentTask=e.index,n.stage=e.stage,1===n.status&&e&&e.func.call(e.context,e.arg,function(e){t.success(e),t.tasks.length>0?t.start():s._queueSuccess(i)},function(e){var s;if(n.useFallback=!1,O.TRANS.includes(n.stage)&&(null==n||null===(s=n.fallbackStoreInfoList)||void 0===s?void 0:s.length)>0){var r=n.fallbackStoreInfoList.shift();n.tosDomain="https://".concat(r.UploadHost),n.uploadHeader=M.formatUploadHeader(r.UploadHeader),n.oid=M.resolveUri(r.StoreInfo.StoreUri),n.signature=r.StoreInfo.Auth,n.SessionKey=r.SessionKey,n.UploadID=r.StoreInfo.UploadID,n.useFallback=!0;var o=t.uploaderCtx.taskList[i].findIndex(function(e){return 1001===e.stage});t.tasks=t.uploaderCtx.taskList[i].slice(o+1),t.uploaderCtx.logger.send(n,{type:"retryUseFallback",ex:"retry start from fallbackNodes."}),t.start()}else n.key=i,n.status=5,t.fail(e)}))}}},{key:"success",value:function(e){this.uploaderCtx._broadcast(e.stage,e),this.uploaderCtx.logger.send(e)}},{key:"fail",value:function(e){this.uploaderCtx._broadcast(w.ERROR,e),this.uploaderCtx.logger.send(e)}},{key:"cancel",value:function(e){var t=this.key,i=this.uploaderCtx.tasks[t].currentTask,s=this.uploaderCtx.tasks[t].isDirect?this.uploaderCtx.taskList[t][i-1]:this.uploaderCtx.taskList[t][i];e||(this.tasks=[]),s&&3===s.index&&s.context.stop()}},{key:"restart",value:function(){this.uploadList.forEach(function(e){e.cancel=!1}),this.start()}}])}(b);function te(e,t){var i={};for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.indexOf(s)<0&&(i[s]=e[s]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(s=Object.getOwnPropertySymbols(e);n<s.length;n++)t.indexOf(s[n])<0&&Object.prototype.propertyIsEnumerable.call(e,s[n])&&(i[s[n]]=e[s[n]])}return i}var ie,se=void 0;ie={cn:"https://mcs.zijieapi.com",va:"https://maliva-mcs.byteoversea.com",sg:"https://sgali-mcs.byteoversea.com"};var ne,re={appOnShow:"app_launch",appOnHide:"app_terminate",appOnError:"on_error",pageOnShow:"predefine_pageview",pageOnHide:"predefine_pageview_hide",pageOnShareAppMessage:"on_share"},oe=["utm_source","utm_medium","utm_campaign","utm_term","utm_content"],ae=["__profile_set","__profile_set_once","__profile_increment","__profile_unset","__profile_append"],ce=function(e){return null!=e&&"[object Object]"==Object.prototype.toString.call(e)},ue=function(e){return"function"==typeof e},le=function(e){return"number"==typeof e&&!isNaN(e)},he=function(){return+new Date},de=r(function e(t){s(this,e),this.sdk=t,this.env=this.init()},[{key:"init",value:function(){return{user:{web_id:se,user_unique_id:se,user_id:se,user_type:se,user_is_auth:se,user_is_login:se,ip_addr_id:se,device_id:se},header:{app_id:se,app_name:se,app_install_id:se,install_id:se,app_package:se,app_channel:se,app_version:se,os_name:se,os_version:se,device_model:se,device_brand:se,traffic_type:se,client_ip:se,os_api:se,access:se,language:se,app_language:se,creative_id:se,ad_id:se,campaign_id:se,ab_client:se,ab_version:se,platform:se,sdk_version:se,sdk_lib:se,app_region:se,region:se,province:se,city:se,timezone:se,tz_offset:se,tz_name:se,sim_region:se,carrier:se,resolution:se,screen_width:se,screen_height:se,browser:se,browser_version:se,referrer:se,referrer_host:se,utm_source:se,utm_medium:se,utm_campaign:se,utm_term:se,utm_content:se,custom:{},ab_sdk_version:se,_sdk_version:se,_sdk_name:se}}}},{key:"set",value:function(e){var t=this;this.sdk.emit(this.sdk.types.EnvTransform,e),Object.keys(e).forEach(function(i){if("evtParams"===i)t.evtParams=Object.assign(Object.assign({},t.evtParams||{}),e.evtParams||{});else if("_staging_flag"===i)t.evtParams=Object.assign(Object.assign({},t.evtParams||{}),{_staging_flag:e._staging_flag});else{var s,n=i,r=e[i];if(null===r)return!1;var o="";n.indexOf(".")>-1&&(o=(s=p(n.split("."),2))[0],n=s[1]),"os_version"!==n&&"mp_platform"!==n||(r="".concat(r)),o?("headers"===o&&(o="header"),"user"===o||"header"===o?t.env[o][n]=r:t.env.header.custom[n]=r):t.env.user.hasOwnProperty(n)?["user_type","ip_addr_id"].indexOf(n)>-1?t.env.user[n]=Number(r):["user_id","web_id","user_unique_id"].indexOf(n)>-1?t.env.user[n]=String(r):["user_is_auth","user_is_login"].indexOf(n)>-1?t.env.user[n]=Boolean(r):["device_id"].indexOf(n)>-1&&(t.env.user[n]=r):t.env.header.hasOwnProperty(n)?t.env.header[n]=r:t.env.header.custom[n]=r}})}},{key:"get",value:function(e){return e&&"env"!==e?"evtParams"===e?Object.assign({},this[e]):this.env.hasOwnProperty(e)?this.clone(this.env[e]):this.env.user.hasOwnProperty(e)?this.clone(this.env.user[e]):this.env.header.hasOwnProperty(e)?this.clone(this.env.header[e]):this.env.header.custom.hasOwnProperty(e)?this.clone(this.env.header.custom[e]):void 0:this.clone(this.env)}},{key:"compose",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],i=this.env,s=i.user,n=i.header,r=this.evtParams,o=e.map(function(e){return e.event&&!t.includes(e.event)&&r&&Object.keys(r).forEach(function(t){void 0===e.params[t]&&(e.params[t]=r[t])}),e.params=JSON.stringify(e.params),e});return this.clone({events:o,user:s,header:n})}},{key:"merge",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],i=this.compose(e,t);return i.local_time=Math.floor(he()/1e3),[i]}},{key:"clone",value:function(e){return ce(e)?JSON.parse(JSON.stringify(e)):e}}]),fe=r(function e(){s(this,e),this.domains=ie,this.init()},[{key:"init",value:function(){this.option={caller:"",log:!1,channel:"cn",report_channel:"cn",channel_domain:"",report_url:"",auto_report:!1,auto_profile:!1,profile_channel:"cn",enable_profile:!1,enable_ab_test:!1,ab_channel_domain:"",clear_ab_cache_on_user_change:!0,enable_et_test:!1,event_verify_url:"",enable_buffer:!1,buffer_interval:5e3,buffer_number:5,enable_storage_only:!1,enable_filter_list:!1,enable_third:!1,enable_filter_crawler:!1,request_timeout:0,enable_initiative_launch:!1,enable_custom_webid:!1,disable_sdk_monitor:!1},this.cloneOption=Object.assign({},this.option),this.initDomain()}},{key:"initDomain",value:function(){if(this.option.channel_domain)this.domain=this.option.channel_domain;else{var e=this.option.report_channel;Object.keys(this.domains).includes(e)||(e="cn"),this.domain=this.domains[e]}}},{key:"set",value:function(e){var t=this;ce(e)&&Object.keys(e).forEach(function(i){t.option.hasOwnProperty(i)&&("channel"===i||"report_channel"===i?(t.option.report_channel=t.option.channel=e[i]?e[i]:t.cloneOption[i],t.initDomain()):(t.option[i]=void 0===e[i]?t.cloneOption[i]:e[i],"channel_domain"===i&&t.initDomain()))})}},{key:"get",value:function(e){return e?this.hasOwnProperty(e)?this[e]:this.option.hasOwnProperty(e)?this.option[e]:void 0:Object.assign({},this.option)}}]),pe=r(function e(){s(this,e),this.hooks={}},[{key:"on",value:function(e,t){e&&t&&"function"==typeof t&&(this.hooks[e]||(this.hooks[e]=[]),this.hooks[e].push(t))}},{key:"once",value:function(e,t){var i=this;e&&t&&"function"==typeof t&&this.on(e,function s(n){t(n),i.off(e,s)})}},{key:"off",value:function(e,t){if(e&&this.hooks[e]&&this.hooks[e].length)if(t){var i=this.hooks[e].indexOf(t);-1!==i&&this.hooks[e].splice(i,1)}else this.hooks[e]=[]}},{key:"emit",value:function(e,t){e&&this.hooks[e]&&this.hooks[e].length&&v(this.hooks[e]).forEach(function(e){try{e(t)}catch(e){}})}}]),ge=r(function e(t){s(this,e),this.ready=!1,this.sdk=t},[{key:"setLog",value:function(e){e&&ue(e.log)&&(this._log=e)}},{key:"setRequest",value:function(e){if(ue(e)){var t=e(this.sdk);ue(t)&&(this._request=t)}}},{key:"setStorage",value:function(e){ce(e)&&ue(e.get)&&ue(e.set)&&ue(e.remove)&&(this._storage=e)}},{key:"check",value:function(){this._request&&this._storage&&(this.ready=!0)}},{key:"log",value:function(){if(this._log)try{var e;this.sdk.option.get("log")&&(e=this._log).log.apply(e,arguments)}catch(e){}}},{key:"request",value:function(e){var t;if(!this.ready)return Promise.reject();try{return null===(t=this._request)||void 0===t?void 0:t.call(this,e)}catch(e){}}},{key:"get",value:function(e){return this.ready?this._storage.get(e):Promise.reject(null)}},{key:"set",value:function(e,t){return this.ready?this._storage.set(e,t):Promise.reject(!1)}},{key:"remove",value:function(e){return this.ready?this._storage.remove(e):Promise.reject(!1)}}]);!function(e){e.Init="$init",e.Config="$config",e.Send="$send",e.Ready="$ready",e.TokenComplete="$token-complete",e.TokenStorage="$token-storage",e.TokenFetch="$token-fetch",e.TokenGet="$token-get",e.LaunchComplete="$launch-complete",e.ConfigUuid="$config-uuid",e.ConfigWebId="$config-webid",e.ConfigTransform="$config-transform",e.UuidChangeBefore="$uuid-change-before",e.UuidChangeAfter="$uuid-change-after",e.EnvTransform="$env-transform",e.Event="$event",e.Report="$report",e.AppOpen="$app-open",e.AppClose="$app-close",e.AppShowStart="$app-show-start",e.AppShow="$app-show",e.AppHide="$app-hide",e.AppError="$app-error",e.AppShare="$app-share",e.AppOnShare="$app-on-share",e.PageShow="$page-show",e.PageHide="$page-hide",e.PageShare="$page-share",e.SubmitBefore="$submit-before",e.SubmitAfter="$submit-after",e.SubmitError="$submit-error",e.FilterCrawler="$filter-crawler",e.LaunchInfo="$launch-info",e.AbVar="$ab-var",e.AbAllVars="$ab-all-vars",e.AbExternalVersion="$ab-external-version",e.AbVersionChangeOn="$ab-version-change-on",e.AbVersionChangeOff="$ab-version-change-off",e.AbRefresh="$ab-refresh",e.AbFetchAfter="$ab-fetch-After",e.ProfileSet="$profile-set",e.ProfileSetOnce="$profile-set-once",e.ProfileUnset="$profile-unset",e.ProfileIncrement="$profile-increment",e.ProfileAppend="$profile-append",e.ProfileClear="$profile-clear",e.ProfileSubmitAfter="$profile-submit-after",e.ProfileSubmitError="$profile-submit-error",e.TransformInfo="$transform-info"}(ne||(ne={}));var ve=ne,ye=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})},me=function(){function e(){s(this,e),this.types=ve,this.EventType=re,this.ProfileType=ae,this.UtmType=oe,this.SdkHook=ve,this.inited=!1,this.sended=!1,this.pluginInstances=[],this.data=new Map,this.ready=!1,this.sessionId="",this.env=new de(this),this.option=new fe,this.hook=new pe,e.instances.push(this);try{this.adapter=new ge(this),this.adapter.setLog(e._log),this.adapter.setRequest(e._request),this.adapter.setStorage(e._storage),this.adapter.check(),e.plugins.reduce(function(e,t){var i=t.plugin;return e.push(new i),e},this.pluginInstances)}catch(e){}}return r(e,[{key:"on",value:function(e,t){var i;null===(i=this.hook)||void 0===i||i.on(e,t)}},{key:"once",value:function(e,t){var i;null===(i=this.hook)||void 0===i||i.once(e,t)}},{key:"off",value:function(e,t){var i;!t&&this.types[e]||null===(i=this.hook)||void 0===i||i.off(e,t)}},{key:"emit",value:function(e,t){var i;this.adapter.log("emit ".concat(e),t||""),null===(i=this.hook)||void 0===i||i.emit(e,t)}},{key:"appId",get:function(){return this._appId}},{key:"checkUsePlugin",value:function(t){return!!e.plugins.find(function(e){return e.name===t})}},{key:"init",value:function(e){var t=this;if(!this.inited&&ce(e)){var i=e.app_id,s=e.log,n=te(e,["app_id","log"]);if(void 0!==s&&this.option.set({log:s}),le(i)&&i>0){this._appId=i,this.option.set(n),this.env.set({app_id:i}),Promise.all([new Promise(function(e){t.once(ve.TokenComplete,function(){e(!0)})}),new Promise(function(e){t.checkUsePlugin("official:auto")?t.on(ve.LaunchComplete,function(){e(!0)}):e(!0)}),new Promise(function(e){t.sended?e(!0):t.once(ve.Send,function(){e(!0)})})]).then(function(){t.ready=!0,t.emit(ve.Ready)});var r=this.option.get();this.pluginInstances.forEach(function(e){e.apply(t,r)}),this.get("is-crawler")||(this.inited=!0,this.emit(ve.Init),this.sessionId=ye(),this.on(ve.AppShowStart,function(){t.sessionId=ye()}))}else this.adapter.log("app_id invalid")}}},{key:"config",value:function(e){if(this.inited&&ce(e)){this.emit(ve.Config,e);var t=e.web_id,i=e.user_unique_id,s=te(e,["web_id","user_unique_id"]);void 0!==t&&this.emit(ve.ConfigWebId,t),void 0!==i&&this.emit(ve.ConfigUuid,i),this.env.set(s)}}},{key:"send",value:function(){this.inited&&!this.sended&&(this.sended=!0,this.emit(ve.Send))}},{key:"event",value:function(e,t){var i=this;if(!this.get("is-crawler"))if(Array.isArray(e)){var s=he(),n=[];e.forEach(function(e){var t,r,o,a;Array.isArray(e)?(r=(t=p(e,3))[0],o=t[1],a=t[2]):ce(e)&&(r=e.event,o=e.params,a=e.local_time_ms),r&&((!le(a)||a<0||a>s)&&(a=s),n.push(i.createEvent({event:r,params:o,time:a})))}),n.length>0&&this.emit(ve.Event,n)}else this.emit(ve.Event,this.createEvent({event:e,params:t}))}},{key:"createEvent",value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],i=Object.assign({event:e.event,params:e.params||{},local_time_ms:e.time||he()},this.sessionId?{session_id:this.sessionId}:{});if(!t)return i;var s="",n=this.get("ab_sdk_version");n&&(s+=n);var r=this.get("ab_sdk_version_external");return r&&(s?s+=","+r:s=r),Object.assign(Object.assign({},i),s?{ab_sdk_version:s}:{})}},{key:"set",value:function(e,t){this.data.set(e,t)}},{key:"get",value:function(e){return this.data.get(e)}},{key:"getKey",value:function(e){var t=this.appId;if("ab_version"===e||"ab_version_external"===e)return"__tea_sdk_".concat(e,"_").concat(t);var i={token:"tokens",report:"reports",event:"events",utm:"utm",first:"first",compensate:"compensate"};return i[e]?"__tea_cache_".concat(i[e],"_").concat(t):void 0}},{key:"getUrl",value:function(e){var t=this.option,i=this.env,s=i.get("_sdk_version"),n=(i.get("_sdk_name")||"").replace(/@.+\//,""),r="".concat(t.get("domain")).concat(e,"?sdk_version=").concat(s,"&sdk_name=").concat(n),o=t.get("caller");return o?"".concat(r,"&app_id=").concat(this.appId,"&caller=").concat(o):r}},{key:"getToken",value:function(e){var t=this;if(!e)return new Promise(function(e){t.emit(ve.TokenGet,{callback:function(t){e(t)}})});this.emit(ve.TokenGet,{callback:e})}},{key:"getConfig",value:function(e){return this.env.get(e||"header")}},{key:"stash",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i="stash";this.set(i,[].concat(v(this.get(i)||[]),[this.createEvent({event:e,params:t})]))}},{key:"commit",value:function(){var e="stash",t=this.get(e)||[];t.length>0&&(this.event(t),this.set(e,[]))}},{key:"getVar",value:function(e,t,i){var s=this;if(!i)return new Promise(function(i){s.emit(ve.AbVar,{name:e,defaultValue:t,callback:function(e){i(e)}})});this.emit(ve.AbVar,{name:e,defaultValue:t,callback:i})}},{key:"getAllVars",value:function(e){var t=this;if(!e)return new Promise(function(e){t.emit(ve.AbAllVars,function(t){e(t)})});this.emit(ve.AbAllVars,e)}},{key:"getAbSdkVersion",value:function(){var e=this.get("ab_versions")||[];return e.length>0?e[e.length-1].ab:""}},{key:"onAbSdkVersionChange",value:function(e){var t=this;return this.emit(ve.AbVersionChangeOn,e),function(){t.emit(ve.AbVersionChangeOff,e)}}},{key:"offAbSdkVersionChange",value:function(e){this.emit(ve.AbVersionChangeOff,e)}},{key:"setExternalAbVersion",value:function(e){this.emit(ve.AbExternalVersion,"string"==typeof e&&e?"".concat(e).trim():null)}},{key:"getAbConfig",value:function(e,t){var i=this;if(!t)return new Promise(function(t){i.emit(ve.AbRefresh,{params:e,callback:function(e){t(e)}})});this.emit(ve.AbRefresh,{params:e,callback:t})}},{key:"profileSet",value:function(e){this.emit(ve.ProfileSet,e)}},{key:"profileSetOnce",value:function(e){this.emit(ve.ProfileSetOnce,e)}},{key:"profileUnset",value:function(e){this.emit(ve.ProfileUnset,e)}},{key:"profileIncrement",value:function(e){this.emit(ve.ProfileIncrement,e)}},{key:"profileAppend",value:function(e){this.emit(ve.ProfileAppend,e)}},{key:"autoInitializationRangers",value:function(e){var t=e.onTokenReady,i=te(e,["onTokenReady"]);return this.init(Object.assign(Object.assign({},i),{log:!1,enable_third:!0})),this.send(),this.getToken().then(function(e){var i=e.web_id;try{if("function"==typeof t)return void t("".concat(i))}catch(e){}return"".concat(i)})}}],[{key:"useAdapterLog",value:function(t){e._log=t}},{key:"useAdapterRequest",value:function(t){e._request=t}},{key:"useAdapterStorage",value:function(t){e._storage=t}},{key:"usePlugin",value:function(t,i){var s=i||t.pluginName;if(s){for(var n=!1,r=0,o=e.plugins.length;r<o;r++)if(e.plugins[r].name===s){e.plugins[r].plugin=t,n=!0;break}n||e.plugins.push({name:s,plugin:t})}else e.plugins.push({plugin:t});if("function"==typeof t.init)try{t.init(e)}catch(t){}}}])}();me.plugins=[],me.instances=[];var ke,_e=r(function e(){s(this,e)},[{key:"apply",value:function(e,t){e.env.set({sdk_version:"3.0.0",_sdk_version:"3.0.0",_sdk_name:"@dp/tea-sdk-common"})}}]);_e.pluginName="official:info",function(e){e.Default="default",e.Custom="custom"}(ke||(ke={}));var be=r(function e(t,i){s(this,e),this.wrap=t,this.sdk=i,this.url="/webid/"},[{key:"storageNoData",value:function(){this.fetch()}},{key:"storageHasData",value:function(e){return this.wrap.dataComplete(e)}},{key:"fetch",value:function(){var e=this,t=this.sdk,i=t.adapter,s=t.appId;i.request({url:this.sdk.getUrl("".concat(this.url)),method:"POST",data:{app_id:s,url:"-",user_agent:"-",referer:"-",user_unique_id:""}}).then(function(t){try{var s=t.data,n=void 0===s?{}:s,r=n.e,o=void 0===r?-1e4:r,a=n.web_id,c=void 0===a?"":a;if(0===o)return void e.fetchComplete(c);i.log("parse web_id error",o)}catch(t){i.log("parse web_id error",t)}e.fetchComplete()}).catch(function(t){e.fetchComplete(),i.log("fetch web_id error",t)})}},{key:"fetchComplete",value:function(e){e&&this.wrap.webIdComplete(e)}},{key:"storageComplete",value:function(e){if(e)try{if(e[this.wrap.typeKey]===ke.Default){var t=this.storageHasData(e);this.wrap.complete(t)}else this.storageNoData()}catch(e){}else this.storageNoData()}}]),we=r(function e(t,i){var n=this;s(this,e),this.wrap=t,this.sdk=i,this.sdk.on(this.sdk.types.ConfigWebId,function(e){e="".concat(e),n.wrap.tokenComplete?n.waitComplete(e):n.waitResolve?n.waitResolve(e):n.tmpWebId=e})},[{key:"storageNoData",value:function(){this.wait()}},{key:"storageHasData",value:function(e){return this.wrap.dataComplete(e,this.tmpWebId)}},{key:"wait",value:function(){var e=this;new Promise(function(t){void 0!==e.tmpWebId?(t(e.tmpWebId),e.tmpWebId=void 0):e.waitResolve=t}).then(function(t){e.waitComplete(t)})}},{key:"waitComplete",value:function(e){this.wrap.webIdComplete(e)}},{key:"storageComplete",value:function(e){if(e)try{if(e[this.wrap.typeKey]===ke.Custom){var t=this.storageHasData(e);this.wrap.complete(t)}else this.storageNoData()}catch(e){}else this.storageNoData()}}]),xe=r(function e(){s(this,e),this.tokenComplete=!1,this.tobid="",this.tobidUrl="/tobid/",this.tobidKey="",this.isCustom=!1,this.typeKey="_type_"},[{key:"apply",value:function(e,t){var i=this;this.sdk=e,this.options=t,this.key=this.sdk.getKey("token"),this.tobidKey="diss".split("").reverse().join(""),this.options.enable_custom_webid?(this.isCustom=!0,this.token=new we(this,this.sdk)):(this.isCustom=!1,this.token=new be(this,this.sdk));var s=this.sdk.types;this.sdk.on(s.ConfigUuid,function(e){i.setUserUniqueId(e)}),this.sdk.on(s.TokenGet,function(e){var t=e.callback,n=function(){i.fetchTobid().then(function(){var e=i.sdk.env.get("user"),s=Object.assign(Object.assign({},e),{web_id:i.webId,user_unique_id:i.userUniqueId});s[i.tobidKey]=i.tobid,"function"==typeof t&&t(s)})};i.sdk.ready?n():i.sdk.once(s.Ready,function(){n()})}),this.storage()}},{key:"storage",value:function(){var e=this,t=this.sdk.adapter;t.get(this.key).then(function(i){ce(i)&&i.web_id?(i[e.typeKey]&&!i[e.tobidKey]&&i.user_unique_id||(i={web_id:i.web_id,user_unique_id:i.user_unique_id||i.web_id},t.set(e.key,i)),e.storageComplete(i)):e.storageComplete(null)}).catch(function(i){e.storageComplete(null),t.log("get token error",i)})}},{key:"storageComplete",value:function(e){this.token.storageComplete(e)}},{key:"dataComplete",value:function(e,t){var i=e.web_id;void 0!==t&&t!==i&&(i=t),this.webId=i;var s=e.web_id===e.user_unique_id?i:e.user_unique_id;return void 0!==this.tmpUserUniqueId&&this.tmpUserUniqueId!==s&&(s=this.tmpUserUniqueId?this.tmpUserUniqueId:i,this.tmpUserUniqueId=void 0),this.userUniqueId=s,i!==e.web_id||s!==e.user_unique_id}},{key:"webIdComplete",value:function(e){this.webId=e,this.tmpUserUniqueId?(this.userUniqueId=this.tmpUserUniqueId,this.tmpUserUniqueId=void 0):this.userUniqueId=e,this.complete(!0)}},{key:"complete",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0],t=this.sdk.types,i=o({web_id:this.webId,user_unique_id:this.userUniqueId},this.typeKey,this.isCustom?ke.Custom:ke.Default);this.sdk.env.set(i),e&&this.sdk.adapter.set(this.key,i),this.tokenComplete=!0,this.sdk.emit(t.TokenComplete)}},{key:"setUserUniqueId",value:function(e){var t=this.sdk,i=t.adapter,s=t.env,n=t.types;if(this.tokenComplete){if(this.userUniqueId===e)return;this.sdk.emit(n.UuidChangeBefore),this.userUniqueId=e||this.webId,s.set({user_unique_id:this.userUniqueId});var r=o({web_id:this.webId,user_unique_id:this.userUniqueId},this.typeKey,this.isCustom?ke.Custom:ke.Default);i.set(this.key,r),this.sdk.emit(n.UuidChangeAfter)}else this.tmpUserUniqueId=e}},{key:"fetchTobid",value:function(){var e=this,t=this.sdk,i=t.adapter,s=t.appId;return i.request({url:this.sdk.getUrl("".concat(this.tobidUrl)),method:"POST",data:{app_id:s,web_id:this.webId,user_unique_id:this.userUniqueId}}).then(function(t){try{var i=t.data,s=void 0===i?{}:i,n=s.e,r=void 0===n?-1e4:n,o=s.tobid,a=void 0===o?"":o;if(0===r)return void(e.tobid=a)}catch(t){}}).catch(function(e){i.log("fetch tobid error",e)})}}]);xe.pluginName="official:token";var Se=r(function e(){s(this,e),this.url="/list/",this.cache=[]},[{key:"apply",value:function(e,t){var i=this;this.sdk=e,this.options=t,this.key=this.sdk.getKey("report"),this.reportUrl=this.sdk.getUrl("".concat(this.url)),this.sdk.set("report_url",this.reportUrl);var s=this.sdk.types;this.sdk.on(s.Report,function(e){Array.isArray(e)||(e=[e]),i.sdk.ready?i.report(e):e.forEach(function(e){return i.cache.push(e)})}),this.sdk.on(s.Ready,function(){i.cache.length>0&&(i.report(v(i.cache)),i.cache.length=0)});var n=this.sdk.adapter;this.sdk.on(s.AppOpen,function(){n.get(i.key).then(function(){})}),this.sdk.on(s.AppClose,function(){i.cache.length>0&&(n.set(i.key,v(i.cache)),i.cache.length=0)})}},{key:"report",value:function(e){this.submit(e)}},{key:"submit",value:function(e){var t=this,i=this.sdk.types;this.sdk.emit(i.SubmitBefore,e),this.sdk.adapter.request({url:this.reportUrl,method:"POST",data:e}).then(function(s){t.sdk.emit(i.SubmitAfter,{isError:!1,response:s,event:e})}).catch(function(s){t.sdk.emit(i.SubmitAfter,{isError:!0,error:s,event:e}),t.sdk.emit(i.SubmitError,{event:e})})}}]);Se.pluginName="official:report";var Ce=r(function e(){s(this,e),this.buffer=[],this.timer=0,this.unReadyCache=[]},[{key:"apply",value:function(e,t){var i,s,n=this;this.sdk=e,this.options=t,this.enable=!!this.options.enable_buffer;var r=!0===this.options.enable_storage||!1===this.options.disable_storage;if(r&&(this.enable=!0),this.enable){this.interval=this.options.buffer_interval,this.number=this.options.buffer_number,r&&((null===(i=this.options)||void 0===i?void 0:i.report_interval)>0&&(this.interval=this.options.report_interval),(null===(s=this.options)||void 0===s?void 0:s.max_batch_event)>0&&(this.number=this.options.max_batch_event));try{this.interval=Number(this.interval),this.number=Number(this.number)}catch(e){}}this.sdk.set("enable_storage",this.enable);var o=this.sdk.types;this.sdk.on(o.Event,function(e){n.sdk.ready?n.process(Array.isArray(e)?e:[e]):n.unReadyCache=[].concat(v(n.unReadyCache),v(Array.isArray(e)?e:[e]))}),this.sdk.on(o.Ready,function(){n.unReadyCache.length>0&&(n.process(n.unReadyCache),n.unReadyCache=[])}),this.sdk.on(o.AppClose,function(){n.buffer.length>0&&(n.report(n.buffer),n.buffer.length=0)})}},{key:"process",value:function(e){var t=this.sdk.env.compose(e);this.enable?(this.buffer=[].concat(v(this.buffer),[t]),this.refresh()):this.report(t)}},{key:"refresh",value:function(){var e=this;this.timer&&clearTimeout(this.timer),this.buffer.length>=this.number?(this.report(v(this.buffer)),this.buffer.length=0):this.timer=setTimeout(function(){e.report(v(e.buffer)),e.buffer.length=0},this.interval)}},{key:"report",value:function(e){this.sdk.emit(this.sdk.types.Report,e)}}]);Ce.pluginName="official:buffer";var Ie=r(function e(){s(this,e)},[{key:"apply",value:function(e,t){var i=this;this.sdk=e,this.options=t;var s=this.sdk,n=s.types,r=s.env,o=function(){try{var e=(new Date).getTimezoneOffset();return{timezone:Math.floor(Math.abs(e)/60),offset:60*e}}catch(e){return{timezone:8,offset:-28800}}}();r.set({timezone:o.timezone,tz_offset:o.offset}),this.sdk.on(n.ConfigTransform,function(e){if(void 0!==e.gender&&([1,2,"1","2"].includes(e.gender)?e.gender=e.gender<2?"male":"female":delete e.gender),i.options.enable_profile){var t={};["nick_name","gender","avatar_url"].forEach(function(i){void 0!==e[i]&&(t[i]=e[i],delete e[i])}),i.sdk.emit(n.ProfileSet,t)}}),this.sdk.on(n.EnvTransform,function(e){if(i.options.enable_profile){var t={};["$mp_from_uuid"].forEach(function(i){void 0!==e[i]&&(t[i]=e[i],delete e[i])}),Object.keys(t).length>0&&i.sdk.emit(n.ProfileSetOnce,t)}})}}]);Ie.pluginName="official:transform",me.usePlugin(_e),me.usePlugin(xe),me.usePlugin(Se),me.usePlugin(Ce),me.usePlugin(Ie);var Oe=console,Ae="undefined",Pe=function(){return"undefined"!==Ae||(Ae="undefined"!=typeof tt?{target:tt,config:"undefined"!=typeof __ttConfig?__ttConfig:null,customPlatform:"ttMiniProduct",mpPlatform:2,is:"tt"}:"undefined"!=typeof my?{target:my,config:null,customPlatform:"aliMiniProduct",mpPlatform:1,is:"my"}:"undefined"!=typeof swan?{target:swan,config:null,customPlatform:"swanMiniProduct",mpPlatform:5,is:"swan"}:"undefined"!=typeof qq?{target:qq,config:"undefined"!=typeof __qqConfig?__qqConfig:null,customPlatform:"qqMiniProduct",mpPlatform:6,is:"qq"}:"undefined"!=typeof wx?{target:wx,config:"undefined"!=typeof __wxConfig?__wxConfig:null,customPlatform:"miniProduct",mpPlatform:0,is:"wx"}:"undefined"!=typeof uni?{target:uni,config:null,customPlatform:"uniMiniProduct",mpPlatform:7,is:"uni"}:{target:{},config:null,customPlatform:"",mpPlatform:-1,is:""}),Ae},Ue=Pe(),je="my"===Ue.is?function(e){return function(t){var i=t.timeout||e.option.get("request_timeout"),s="number"==typeof i&&i>0;return new Promise(function(e,n){var r=my[my.request?"request":"httpRequest"](Object.assign(Object.assign({},t),{dataType:t.dataType||"json",success:function(t){e(t)},fail:function(e){n(e)}}));s&&setTimeout(function(){try{r&&r.abort()}catch(e){}},i)})}}:Ue.target?function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return function(i){return function(s){var n=s.timeout||i.option.get("request_timeout"),r="number"==typeof n&&n>0;return new Promise(function(i,o){var a=e.request(Object.assign(Object.assign(Object.assign({},s),r&&!t?{timeout:n}:{}),{dataType:s.dataType||"json",success:function(e){i(e)},fail:function(e){o(e)}}));r&&t&&setTimeout(function(){try{a&&a.abort()}catch(e){}},n)})}}}(Ue.target,"swan"===Ue.is):function(e){return function(e){return Promise.reject("request adapter error")}},Te=Pe(),De="my"===Te.is?new(r(function e(){s(this,e)},[{key:"get",value:function(e){return new Promise(function(t,i){try{t(my.getStorageSync({key:e}).data)}catch(e){i(e)}})}},{key:"set",value:function(e,t){return new Promise(function(i,s){try{my.setStorageSync({key:e,data:t}),i(!0)}catch(e){s(!1)}})}},{key:"remove",value:function(e){return new Promise(function(t,i){try{my.removeStorageSync({key:e}),t(!0)}catch(e){i(!1)}})}}])):Te.target?new(r(function e(t){s(this,e),this.target=t},[{key:"get",value:function(e){var t=this;return new Promise(function(i,s){try{i(t.target.getStorageSync(e))}catch(e){s(e)}})}},{key:"set",value:function(e,t){var i=this;return new Promise(function(s,n){try{i.target.setStorageSync(e,t),s(!0)}catch(e){n(!1)}})}},{key:"remove",value:function(e){var t=this;return new Promise(function(i,s){try{t.target.removeStorageSync(e),i(!0)}catch(e){s(!1)}})}}]))(Te.target):function(){var e="storage adapter error";return{get:function(t){return Promise.reject(e)},set:function(t,i){return Promise.reject(e)},remove:function(t){return Promise.reject(e)}}}(),qe=r(function e(){s(this,e)},[{key:"apply",value:function(e,t){var i=this;this.sdk=e,this.options=t,this.boost();var s=this.sdk.types;this.getInfo(),this.sdk.on(s.AppOpen,function(){i.getInfo()})}},{key:"boost",value:function(){}},{key:"getInfo",value:function(){var e=this,t=this.sdk,i=t.target,s=t.env;i&&(i.getSystemInfo&&i.getSystemInfo({success:function(t){var i=Math.ceil(t.screenWidth),n=Math.ceil(t.screenHeight),r={device_brand:t.brand,device_model:t.model,os_version:t.system,os_name:t.platform,platform:t.platform,resolution:"".concat(i,"x").concat(n),screen_width:i,screen_height:n};e.overlap(t,r),s.set(r)}}),i.getNetworkType&&i.getNetworkType({success:function(e){var t={access:e.networkType};s.set(t)}}))}},{key:"overlap",value:function(e,t){t.language=e.language,t.mp_platform_app_version=e.version,t.mp_platform_basic_version=e.SDKVersion}}]);qe.pluginName="official:device",me.useAdapterLog(Oe),me.useAdapterRequest(je),me.useAdapterStorage(De),me.usePlugin(function(e){function t(){return s(this,t),i(this,t,arguments)}return u(t,e),r(t,[{key:"boost",value:function(){g(t,"boost",this,3)([]),this.which=Pe(),this.sdk.target=this.which.target,this.sdk.targetEnvConfig=this.which.config,this.sdk.env.set({sdk_lib:"mp_common",custom_platform:this.which.customPlatform,mp_platform:this.which.mpPlatform})}},{key:"overlap",value:function(e,i){g(t,"overlap",this,3)([e,i])}}],[{key:"init",value:function(e){var t=Pe();e.platform=t.is?t.target:null,e.platformIs=t.is}}])}(qe));var He=r(function e(t,i){s(this,e),this.config=t,this.uploaderCtx=i,this.teaLog=new me,this.teaLog.init({app_id:2562,channel:"cn",log:!1}),this.teaLog.config({evtParams:{sdk_version:this.config.sdkVersion,line_app_id:this.config.appId,toB:!0,user_unique_id:this.config.userId,imp:!0},user_unique_id:this.config.userId}),this.teaLog.send()},[{key:"send",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],i=this.uploaderCtx,s=e.key,n=e.stage,r=e.type,o=i.tasks[s];if(o){var a=o.serviceType,c=o.fileSize,u=o.duration,l=o.totalDuration,h=a===x?"video":"image",f={type:r,stage:n,fk:s,fs:c,ts:Math.round(Date.now()/1e3),idu:Number(o.isDirect),cuh:o.customUploadHost};if("error"!==r){var p="".concat(h,"_").concat(n),g=d({dur:u,tdur:l,durs:u/1e3,tdurs:l/1e3,oid:e.oid,upload_host:e.tosDomain},f);switch(n){case 1e3:this.teaLog.event(p,Object.assign({},g,{ex:JSON.stringify({msg:e.extra&&e.extra.message,crc32Array:[e.crc32Array[0],e.crc32Array[e.crc32Array.length-1]],isDirect:e.isDirect})}));break;case 1001:this.teaLog.event(p,Object.assign({},g,{ex:JSON.stringify({msg:e.extra&&e.extra.message}),res:e.res}));break;case 1002:this.teaLog.event(p,Object.assign({},g,{uploadId:e.uploadId,ex:JSON.stringify({msg:e.extra&&e.extra.message,upid:e.uploadId}),uh:e.uploadHeader&&JSON.stringify(e.uploadHeader)}));break;case 1003:t?this.teaLog.event(p,Object.assign({},f,{ex:JSON.stringify({msg:e.extra&&e.extra.message,si:e.slice_index,af:e.isAllFinish}),uh:o.uploadHeader&&JSON.stringify(o.uploadHeader),si:e.slice_index,oid:o.oid,upload_host:o.tosDomain,uploadId:o.uploadId,ss:o.sliceSize&&o.sliceSize/1024/1024})):this.teaLog.event(p,Object.assign({},g,{ex:JSON.stringify({msg:e.extra&&e.extra.message,af:e.isAllFinish}),uploadId:o.uploadId,uh:e.uploadHeader&&JSON.stringify(e.uploadHeader),af:!0,speed:e.speed}));break;case 1004:this.teaLog.event(p,Object.assign({},g,{ex:JSON.stringify({msg:e.extra&&e.extra.message,upid:e.uploadId}),uh:e.uploadHeader&&JSON.stringify(e.uploadHeader),uploadId:e.uploadId,speed:e.speed}));break;case 1005:this.teaLog.event(p,Object.assign({},g,{ex:JSON.stringify({msg:e.extra&&e.extra.message,vid:e.uploadResult&&e.uploadResult.Vid}),vid:e.uploadResult&&e.uploadResult.Vid,speed:e.speed}))}}else{var v=d({ex:JSON.stringify({errc:e.code,msg:e.message,err:e.error}),errc:e.code,errmsg:e.message,err:e.error},f);this.teaLog.event("".concat(h,"_error"),Object.assign({},v))}}}}]),Re=function(e){function t(){var e,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return s(this,t),(e=i(this,t,[n])).config=Object.assign({},A,n),e.tasks={},e.taskList={},e.priorInfo={_supportCrc32:B()},e.logger=e.config.noLog?{send:function(){}}:new He(e.config,e),e}return u(t,e),r(t,[{key:"_addTask",value:function(e,t){var i=this.tasks,s=this.taskList;i[e]&&i[e].task?(s[e].push(t),i[e].task.addTask(t)):(s[e]=[],s[e].push(t),i[e]=i[e]||{},i[e].task=new ee([],this.config,this,e),i[e].task.addTask(t))}},{key:"_broadcast",value:function(e,t){var i=this.tasks[t.key];if(i){if(5===i.status&&e===w.ERROR)return this.emit(e,t);if(1===i.status){if(e===w.PROGRESS||e===w.ERROR)return this.emit(e,t);t.status;var s=t.stage,n=Object.keys(t).reduce(function(e,i){return"task"!==i&&"sessionKey"!==i&&"signature"!==i&&"uploadHeader"!==i&&"tosDomain"!==i&&"crc32Array"!==i&&"res"!==i&&(e[i]=t[i]),e},{});1005===s&&(n.status=4),this.emit(w[s],n)}}}},{key:"_addAllUploadProcess",value:function(e,t,i){var s="image"===e.type&&"[object Array]"===Object.prototype.toString.call(e.file);try{var n=function(e){if(e.size)return e.size;try{var t;return(null===(t=wx)||void 0===t?void 0:t.getFileSystemManager()).statSync(e.path).size}catch(e){throw console.error(e),e}}(e);e.size=n}catch(e){return void this.emit(w.ERROR,{code:1000004,message:"get file size error",error:"get file size error"})}this.tasks[t]=this.tasks[t]||{};var r=this.tasks[t]={key:t,fileSize:e.size,proxyStsToken:e.stsToken,serviceType:i,filePath:e.path,customUploadHost:this.config.uploadHost,gatewayUpload:!!this.config.uploadHost};r.status=0,i===x&&(r.fileType=e.type||"media");var o=e.size<10485760||s;this._addCrc32ProcessTask(e,t,{isDirect:o,isImageBatchUpload:s}),this._addPreUploadTask(e,t,{isImageBatchUpload:s,serviceId:i===S?e.serviceId:null,serviceName:i}),o||!this.priorInfo._supportCrc32?this._addDirectUploadTask(e,t,{isImageBatchUpload:s}):(this._addInitUploadIDTask(e,t),this._addUploadProcessTask(e,t),this._mergeFileTask(e,t));var a=i===S&&e.skipCommit;this._getMetaInfoTask(e,t,{isImageBatchUpload:s,serviceId:i===S?e.serviceId:null,skipCommit:a,serviceName:i})}},{key:"_addCrc32ProcessTask",value:function(e,t,i){var s=i.isDirect,n=i.isImageBatchUpload,r=new R({path:e.path,size:e.size,context:this,key:t,isDirect:s,isImageBatchUpload:n},this.config),o={context:r,func:r.start,arg:{},key:t,index:0,stage:1e3};this._addTask(t,o)}},{key:"_addPreUploadTask",value:function(e,t,i){var s=i.isImageBatchUpload,n=i.serviceId,r=i.serviceName,o={file:e.file,stsToken:e.stsToken,context:this,type:e.type||"video",key:t,isImageBatchUpload:s,fileExtension:e.fileExtension||null,fileName:e.fileName||null,storageClass:e.storageClass||null,serviceId:n,prefix:e.prefix,storeKey:e.storeKey,serviceName:r,overwrite:e.overwrite},a=new J(o,this.config),c={context:a,func:a.start,arg:{},key:t,index:1,stage:1001};this._addTask(t,c)}},{key:"_addInitUploadIDTask",value:function(e,t){var i=new X({context:this,key:t},this.config),s={context:i,func:i.start,arg:{},key:t,index:2,stage:1002};this._addTask(t,s)}},{key:"_addDirectUploadTask",value:function(e,t,i){var s=i.isImageBatchUpload,n=new Q({path:e.path,size:e.size,context:this,key:t,isImageBatchUpload:s},this.config),r={context:n,func:n.start,arg:{},key:t,index:3,stage:1003};this._addTask(t,r)}},{key:"_addUploadProcessTask",value:function(e,t){var i=new G({path:e.path,size:e.size,context:this,key:t},this.config),s={context:i,func:i.start,arg:{},key:t,index:3,stage:1003};this._addTask(t,s)}},{key:"_mergeFileTask",value:function(e,t){var i=new Z({context:this,key:t},this.config),s={context:i,func:i.start,arg:{},key:t,index:4,stage:1004};this._addTask(t,s)}},{key:"_getMetaInfoTask",value:function(e,t,i){var s=i.isImageBatchUpload,n=void 0!==s&&s,r=i.serviceId,o=i.skipCommit,a=i.serviceName,c={context:this,key:t,isImageBatchUpload:n,serviceId:r,processAction:e.processAction,callbackArgs:e.callbackArgs,skipCommit:o,skipMeta:e.skipMeta,serviceName:a},u=new Y(c,this.config),l={context:u,func:u.start,arg:{},key:t,index:5,stage:1005};this._addTask(t,l)}},{key:"_run",value:function(e){var t=this.tasks;t[e]?1!==t[e]?3===t[e].status?this._restart(e):t[e].task&&1!==t[e].status&&t[e].task.tasks.length&&(t[e].startTime=Date.now(),t[e].status=1,t[e].task.start()):console.wran("".concat(e," is running now...")):console.warn("".concat(e," is not exit in object tasks, stop running..."))}},{key:"_pause",value:function(e){var t=this.tasks;t[e]?5!==t[e].currentTask&&1===t[e].status&&(t[e].userCanceled=!0,t[e].status=3,t[e].task.cancel(!0)):console.warn("".concat(e," is not exit in object tasks"))}},{key:"_cancel",value:function(e){var t=this.tasks;t[e]?5!==t[e].currentTask&&(1===t[e].status&&(t[e].userCanceled=!0,t[e].task.cancel(!1),t[e].status=2),this._removeFile(e)):console.warn("".concat(e," is not exit in object tasks"))}},{key:"_restart",value:function(e){var t=this,i=this.tasks;if(i[e]){if(3===i[e].status){var s=i[e].task,n=i[e].currentTask||0;this.taskList[e].forEach(function(i,r){i.index===n&&(s.tasks=t.taskList[e].slice(r))}),!s.tasks.length>0?console.warn("".concat(e," has already completed.")):(i[e].status=1,s.start())}}else console.warn("".concat(e," is not exit in object tasks."))}},{key:"_queueSuccess",value:function(e){var t=this.tasks;t[e]?(t[e].endTime=Date.now(),t[e].time=t[e].endTime-t[e].startTime,t[e].status=4):console.warn("".concat(e," is not exit in object tasks"))}},{key:"_removeFile",value:function(e){this.tasks[e]&&(delete this.tasks[e],delete this.taskList[e])}},{key:"_batchAction",value:function(e){var t=this.tasks;Object.keys(t).forEach(function(t){e&&e(t)})}},{key:"_setServiceId",value:function(e){!this.config.imageConfig&&e?this.config.imageConfig={serviceId:e}:this.config.imageConfig.serviceId=e}},{key:"_getServiceId",value:function(){var e;return null===(e=this.config.imageConfig)||void 0===e?void 0:e.serviceId}},{key:"_getOption",value:function(e){var t=Object.assign({},this.config);return e?t[e]:t}}])}(b),ze=function(e){return!!e&&e.SessionToken&&e.SecretAccessKey&&(e.AccessKeyId||e.AccessKeyID)},Ee=function(e){function t(){return s(this,t),i(this,t,arguments)}return u(t,e),r(t,[{key:"start",value:function(e){this.abort=!1,e?this._run(e):this._batchAction(this._run.bind(this))}},{key:"pause",value:function(e){e?this._pause(e):this._batchAction(this._pause.bind(this))}},{key:"restart",value:function(e){e?this._restart(e):this._batchAction(this._restart.bind(this))}},{key:"cancel",value:function(e){e?this._cancel(e):this._batchAction(this._cancel.bind(this))}},{key:"addFile",value:function(e){if(!e||!ze(e.stsToken))return this.emit(w.ERROR,{code:T,message:"sts token format invalid.",error:"sts token format invalid."}),null;if(e.path){var t=M.getUnique("file");return this._addAllUploadProcess(e,t,x),t}return null}},{key:"addImageFile",value:function(e){if(!e||!ze(e.stsToken))return this.emit(w.ERROR,{code:T,message:"sts token format invalid.",error:"sts token format invalid."}),null;if(e.path){var t=M.getUnique("file");return this._addAllUploadProcess(e,t,S),t}return null}},{key:"addImageXFile",value:function(e){return this.addImageFile(e)}},{key:"setServiceId",value:function(e){this._setServiceId(e)}},{key:"getServiceId",value:function(){return this._getServiceId()}}])}(Re);e.default=Ee,Object.defineProperty(e,"__esModule",{value:!0})});