import{g as ve,a1 as me,a2 as be,a3 as we,a4 as _e}from"./index.Dzkftxcu.js";import"./vue.Bi2Y_N79.js";var ce=function(){var o=function(t,e){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,i){n.__proto__=i}||function(n,i){for(var r in i)i.hasOwnProperty(r)&&(n[r]=i[r])},o(t,e)};return function(t,e){o(t,e);function n(){this.constructor=t}t.prototype=e===null?Object.create(e):(n.prototype=e.prototype,new n)}}(),b;(function(o){o.InvalidFile="InvalidFile",o.InvalidToken="InvalidToken",o.InvalidMetadata="InvalidMetadata",o.InvalidChunkSize="InvalidChunkSize",o.InvalidCustomVars="InvalidCustomVars",o.NotAvailableUploadHost="NotAvailableUploadHost",o.ReadCacheFailed="ReadCacheFailed",o.InvalidCacheData="InvalidCacheData",o.WriteCacheFailed="WriteCacheFailed",o.RemoveCacheFailed="RemoveCacheFailed",o.GetCanvasContextFailed="GetCanvasContextFailed",o.UnsupportedFileType="UnsupportedFileType",o.FileReaderReadFailed="FileReaderReadFailed",o.NotAvailableXMLHttpRequest="NotAvailableXMLHttpRequest",o.InvalidProgressEventTarget="InvalidProgressEventTarget",o.RequestError="RequestError"})(b||(b={}));var _=function(){function o(t,e){this.name=t,this.message=e,this.stack=new Error().stack}return o}(),q=function(o){ce(t,o);function t(e,n,i,r){var c=o.call(this,b.RequestError,i)||this;return c.code=e,c.reqId=n,c.isRequestError=!0,c.data=r,c}return t}(_),xe=function(o){ce(t,o);function t(e,n){return n===void 0&&(n=""),o.call(this,0,n,e)||this}return t}(q),Ce=function(){function o(t,e){this.runTask=t,this.limit=e,this.aborted=!1,this.queue=[],this.processing=[]}return o.prototype.enqueue=function(t){var e=this;return new Promise(function(n,i){e.queue.push({task:t,resolve:n,reject:i}),e.check()})},o.prototype.run=function(t){var e=this;this.queue=this.queue.filter(function(n){return n!==t}),this.processing.push(t),this.runTask(t.task).then(function(){e.processing=e.processing.filter(function(n){return n!==t}),t.resolve(),e.check()},function(n){return t.reject(n)})},o.prototype.check=function(){var t=this;if(!this.aborted){var e=this.processing.length,n=this.limit-e;this.queue.slice(0,n).forEach(function(i){t.run(i)})}},o.prototype.abort=function(){this.queue=[],this.aborted=!0},o}(),Se=function(){var o=function(t,e){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,i){n.__proto__=i}||function(n,i){for(var r in i)i.hasOwnProperty(r)&&(n[r]=i[r])},o(t,e)};return function(t,e){o(t,e);function n(){this.constructor=t}t.prototype=e===null?Object.create(e):(n.prototype=e.prototype,new n)}}(),T=function(){return T=Object.assign||function(o){for(var t,e=1,n=arguments.length;e"u")return"";var t=o+"",e="",n,i,r=0;n=i=0,r=t.length;for(var c=0;c127&&h<2048)g=String.fromCharCode(h>>6|192,h&63|128);else if((h&63488^55296)>0)g=String.fromCharCode(h>>12|224,h>>6&63|128,h&63|128);else{if((h&64512^55296)>0)throw new RangeError("Unmatched trail surrogate at "+c);var a=t.charCodeAt(++c);if((a&64512^56320)>0)throw new RangeError("Unmatched lead surrogate at "+(c-1));h=((h&1023)<<10)+(a&1023)+65536,g=String.fromCharCode(h>>18|240,h>>12&63|128,h>>6&63|128,h&63|128)}g!==null&&(i>n&&(e+=t.slice(n,i)),e+=g,n=i=c+1)}return i>n&&(e+=t.slice(n,r)),e}function Fe(o){var t=[],e=0,n=0,i=0;for(o+="";e>10&1023)),t.push(String.fromCharCode(56320|n&1023))):t.push(String.fromCharCode(n)),e+=i}return t.join("")}function Oe(o){var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",e,n,i,r,c,h,g,a,d=0,v=0,w="",x=[];if(!o)return o;o=Ue(o+"");do e=o.charCodeAt(d++),n=o.charCodeAt(d++),i=o.charCodeAt(d++),a=e<<16|n<<8|i,r=a>>18&63,c=a>>12&63,h=a>>6&63,g=a&63,x[v++]=t.charAt(r)+t.charAt(c)+t.charAt(h)+t.charAt(g);while(d>16&255,n=a>>8&255,i=a&255,h===64?x[v++]=String.fromCharCode(e):g===64?x[v++]=String.fromCharCode(e,n):x[v++]=String.fromCharCode(e,n,i);while(d>>25)+s|0,f+=(u&s|~u&l)+p[1]-389564586|0,f=(f<<12|f>>>20)+u|0,l+=(f&u|~f&s)+p[2]+606105819|0,l=(l<<17|l>>>15)+f|0,s+=(l&f|~l&u)+p[3]-1044525330|0,s=(s<<22|s>>>10)+l|0,u+=(s&l|~s&f)+p[4]-176418897|0,u=(u<<7|u>>>25)+s|0,f+=(u&s|~u&l)+p[5]+1200080426|0,f=(f<<12|f>>>20)+u|0,l+=(f&u|~f&s)+p[6]-1473231341|0,l=(l<<17|l>>>15)+f|0,s+=(l&f|~l&u)+p[7]-45705983|0,s=(s<<22|s>>>10)+l|0,u+=(s&l|~s&f)+p[8]+1770035416|0,u=(u<<7|u>>>25)+s|0,f+=(u&s|~u&l)+p[9]-1958414417|0,f=(f<<12|f>>>20)+u|0,l+=(f&u|~f&s)+p[10]-42063|0,l=(l<<17|l>>>15)+f|0,s+=(l&f|~l&u)+p[11]-1990404162|0,s=(s<<22|s>>>10)+l|0,u+=(s&l|~s&f)+p[12]+1804603682|0,u=(u<<7|u>>>25)+s|0,f+=(u&s|~u&l)+p[13]-40341101|0,f=(f<<12|f>>>20)+u|0,l+=(f&u|~f&s)+p[14]-1502002290|0,l=(l<<17|l>>>15)+f|0,s+=(l&f|~l&u)+p[15]+1236535329|0,s=(s<<22|s>>>10)+l|0,u+=(s&f|l&~f)+p[1]-165796510|0,u=(u<<5|u>>>27)+s|0,f+=(u&l|s&~l)+p[6]-1069501632|0,f=(f<<9|f>>>23)+u|0,l+=(f&s|u&~s)+p[11]+643717713|0,l=(l<<14|l>>>18)+f|0,s+=(l&u|f&~u)+p[0]-373897302|0,s=(s<<20|s>>>12)+l|0,u+=(s&f|l&~f)+p[5]-701558691|0,u=(u<<5|u>>>27)+s|0,f+=(u&l|s&~l)+p[10]+38016083|0,f=(f<<9|f>>>23)+u|0,l+=(f&s|u&~s)+p[15]-660478335|0,l=(l<<14|l>>>18)+f|0,s+=(l&u|f&~u)+p[4]-405537848|0,s=(s<<20|s>>>12)+l|0,u+=(s&f|l&~f)+p[9]+568446438|0,u=(u<<5|u>>>27)+s|0,f+=(u&l|s&~l)+p[14]-1019803690|0,f=(f<<9|f>>>23)+u|0,l+=(f&s|u&~s)+p[3]-187363961|0,l=(l<<14|l>>>18)+f|0,s+=(l&u|f&~u)+p[8]+1163531501|0,s=(s<<20|s>>>12)+l|0,u+=(s&f|l&~f)+p[13]-1444681467|0,u=(u<<5|u>>>27)+s|0,f+=(u&l|s&~l)+p[2]-51403784|0,f=(f<<9|f>>>23)+u|0,l+=(f&s|u&~s)+p[7]+1735328473|0,l=(l<<14|l>>>18)+f|0,s+=(l&u|f&~u)+p[12]-1926607734|0,s=(s<<20|s>>>12)+l|0,u+=(s^l^f)+p[5]-378558|0,u=(u<<4|u>>>28)+s|0,f+=(u^s^l)+p[8]-2022574463|0,f=(f<<11|f>>>21)+u|0,l+=(f^u^s)+p[11]+1839030562|0,l=(l<<16|l>>>16)+f|0,s+=(l^f^u)+p[14]-35309556|0,s=(s<<23|s>>>9)+l|0,u+=(s^l^f)+p[1]-1530992060|0,u=(u<<4|u>>>28)+s|0,f+=(u^s^l)+p[4]+1272893353|0,f=(f<<11|f>>>21)+u|0,l+=(f^u^s)+p[7]-155497632|0,l=(l<<16|l>>>16)+f|0,s+=(l^f^u)+p[10]-1094730640|0,s=(s<<23|s>>>9)+l|0,u+=(s^l^f)+p[13]+681279174|0,u=(u<<4|u>>>28)+s|0,f+=(u^s^l)+p[0]-358537222|0,f=(f<<11|f>>>21)+u|0,l+=(f^u^s)+p[3]-722521979|0,l=(l<<16|l>>>16)+f|0,s+=(l^f^u)+p[6]+76029189|0,s=(s<<23|s>>>9)+l|0,u+=(s^l^f)+p[9]-640364487|0,u=(u<<4|u>>>28)+s|0,f+=(u^s^l)+p[12]-421815835|0,f=(f<<11|f>>>21)+u|0,l+=(f^u^s)+p[15]+530742520|0,l=(l<<16|l>>>16)+f|0,s+=(l^f^u)+p[2]-995338651|0,s=(s<<23|s>>>9)+l|0,u+=(l^(s|~f))+p[0]-198630844|0,u=(u<<6|u>>>26)+s|0,f+=(s^(u|~l))+p[7]+1126891415|0,f=(f<<10|f>>>22)+u|0,l+=(u^(f|~s))+p[14]-1416354905|0,l=(l<<15|l>>>17)+f|0,s+=(f^(l|~u))+p[5]-57434055|0,s=(s<<21|s>>>11)+l|0,u+=(l^(s|~f))+p[12]+1700485571|0,u=(u<<6|u>>>26)+s|0,f+=(s^(u|~l))+p[3]-1894986606|0,f=(f<<10|f>>>22)+u|0,l+=(u^(f|~s))+p[10]-1051523|0,l=(l<<15|l>>>17)+f|0,s+=(f^(l|~u))+p[1]-2054922799|0,s=(s<<21|s>>>11)+l|0,u+=(l^(s|~f))+p[8]+1873313359|0,u=(u<<6|u>>>26)+s|0,f+=(s^(u|~l))+p[15]-30611744|0,f=(f<<10|f>>>22)+u|0,l+=(u^(f|~s))+p[6]-1560198380|0,l=(l<<15|l>>>17)+f|0,s+=(f^(l|~u))+p[13]+1309151649|0,s=(s<<21|s>>>11)+l|0,u+=(l^(s|~f))+p[4]-145523070|0,u=(u<<6|u>>>26)+s|0,f+=(s^(u|~l))+p[11]-1120210379|0,f=(f<<10|f>>>22)+u|0,l+=(u^(f|~s))+p[2]+718787259|0,l=(l<<15|l>>>17)+f|0,s+=(f^(l|~u))+p[9]-343485551|0,s=(s<<21|s>>>11)+l|0,y[0]=u+y[0]|0,y[1]=s+y[1]|0,y[2]=l+y[2]|0,y[3]=f+y[3]|0}function r(y){var p=[],u;for(u=0;u<64;u+=4)p[u>>2]=y.charCodeAt(u)+(y.charCodeAt(u+1)<<8)+(y.charCodeAt(u+2)<<16)+(y.charCodeAt(u+3)<<24);return p}function c(y){var p=[],u;for(u=0;u<64;u+=4)p[u>>2]=y[u]+(y[u+1]<<8)+(y[u+2]<<16)+(y[u+3]<<24);return p}function h(y){var p=y.length,u=[1732584193,-271733879,-1732584194,271733878],s,l,f,C,k,I;for(s=64;s<=p;s+=64)i(u,r(y.substring(s-64,s)));for(y=y.substring(s-64),l=y.length,f=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],s=0;s>2]|=y.charCodeAt(s)<<(s%4<<3);if(f[s>>2]|=128<<(s%4<<3),s>55)for(i(u,f),s=0;s<16;s+=1)f[s]=0;return C=p*8,C=C.toString(16).match(/(.*?)(.{0,8})$/),k=parseInt(C[2],16),I=parseInt(C[1],16)||0,f[14]=k,f[15]=I,i(u,f),u}function g(y){var p=y.length,u=[1732584193,-271733879,-1732584194,271733878],s,l,f,C,k,I;for(s=64;s<=p;s+=64)i(u,c(y.subarray(s-64,s)));for(y=s-64>2]|=y[s]<<(s%4<<3);if(f[s>>2]|=128<<(s%4<<3),s>55)for(i(u,f),s=0;s<16;s+=1)f[s]=0;return C=p*8,C=C.toString(16).match(/(.*?)(.{0,8})$/),k=parseInt(C[2],16),I=parseInt(C[1],16)||0,f[14]=k,f[15]=I,i(u,f),u}function a(y){var p="",u;for(u=0;u<4;u+=1)p+=n[y>>u*8+4&15]+n[y>>u*8&15];return p}function d(y){var p;for(p=0;pf?new ArrayBuffer(0):(C=f-l,k=new ArrayBuffer(C),I=new Uint8Array(k),Z=new Uint8Array(this,l,C),I.set(Z),k)}}();function v(y){return/[\u0080-\uFFFF]/.test(y)&&(y=unescape(encodeURIComponent(y))),y}function w(y,p){var u=y.length,s=new ArrayBuffer(u),l=new Uint8Array(s),f;for(f=0;f>2]|=p.charCodeAt(s)<<(s%4<<3);return this._finish(l,u),f=d(this._hash),y&&(f=A(f)),this.reset(),f},m.prototype.reset=function(){return this._buff="",this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},m.prototype.getState=function(){return{buff:this._buff,length:this._length,hash:this._hash.slice()}},m.prototype.setState=function(y){return this._buff=y.buff,this._length=y.length,this._hash=y.hash,this},m.prototype.destroy=function(){delete this._hash,delete this._buff,delete this._length},m.prototype._finish=function(y,p){var u=p,s,l,f;if(y[u>>2]|=128<<(u%4<<3),u>55)for(i(this._hash,y),u=0;u<16;u+=1)y[u]=0;s=this._length*8,s=s.toString(16).match(/(.*?)(.{0,8})$/),l=parseInt(s[2],16),f=parseInt(s[1],16)||0,y[14]=l,y[15]=f,i(this._hash,y)},m.hash=function(y,p){return m.hashBinary(v(y),p)},m.hashBinary=function(y,p){var u=h(y),s=d(u);return p?A(s):s},m.ArrayBuffer=function(){this.reset()},m.ArrayBuffer.prototype.append=function(y){var p=S(this._buff.buffer,y),u=p.length,s;for(this._length+=y.byteLength,s=64;s<=u;s+=64)i(this._hash,c(p.subarray(s-64,s)));return this._buff=s-64>2]|=p[l]<<(l%4<<3);return this._finish(s,u),f=d(this._hash),y&&(f=A(f)),this.reset(),f},m.ArrayBuffer.prototype.reset=function(){return this._buff=new Uint8Array(0),this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},m.ArrayBuffer.prototype.getState=function(){var y=m.prototype.getState.call(this);return y.buff=x(y.buff),y},m.ArrayBuffer.prototype.setState=function(y){return y.buff=w(y.buff,!0),m.prototype.setState.call(this,y)},m.ArrayBuffer.prototype.destroy=m.prototype.destroy,m.ArrayBuffer.prototype._finish=m.prototype._finish,m.ArrayBuffer.hash=function(y,p){var u=g(new Uint8Array(y)),s=d(u);return p?A(s):s},m})}(V)),V.exports}var Pe=Ee();const Le=ve(Pe);var M=function(){return M=Object.assign||function(o){for(var t,e=1,n=arguments.length;e0&&r[r.length-1])&&(a[0]===6||a[0]===2)){e=0;continue}if(a[0]===3&&(!r||a[1]>r[0]&&a[1]o.size)e=o.size;else for(;o.size>e*1e4;)e*=2;for(var n=[],i=Math.ceil(o.size/e),r=0;r3?t[1]:t[0];if(!e)throw new _(b.InvalidToken,"missing assess key field.");var n=null;try{n=JSON.parse(Re(t[t.length-1]))}catch{throw new _(b.InvalidToken,"token parse failed.")}if(n==null)throw new _(b.InvalidToken,"putPolicy is null.");if(n.scope==null)throw new _(b.InvalidToken,"scope field is null.");var i=n.scope.split(":")[0];if(!i)throw new _(b.InvalidToken,"resolve bucketName failed.");return{assessKey:e,bucketName:i,scope:n.scope}}var U,O={z0:"z0",z1:"z1",z2:"z2",na0:"na0",as0:"as0",cnEast2:"cn-east-2"},Ze=(U={},U[O.z0]={srcUphost:["up.qiniup.com"],cdnUphost:["upload.qiniup.com"]},U[O.z1]={srcUphost:["up-z1.qiniup.com"],cdnUphost:["upload-z1.qiniup.com"]},U[O.z2]={srcUphost:["up-z2.qiniup.com"],cdnUphost:["upload-z2.qiniup.com"]},U[O.na0]={srcUphost:["up-na0.qiniup.com"],cdnUphost:["upload-na0.qiniup.com"]},U[O.as0]={srcUphost:["up-as0.qiniup.com"],cdnUphost:["upload-as0.qiniup.com"]},U[O.cnEast2]={srcUphost:["up-cn-east-2.qiniup.com"],cdnUphost:["upload-cn-east-2.qiniup.com"]},U),z={},G,Q;function Ye(){if(Q)return G;Q=1;function o(t,e){return Object.prototype.hasOwnProperty.call(t,e)}return G=function(t,e,n,i){e=e||"&",n=n||"=";var r={};if(typeof t!="string"||t.length===0)return r;var c=/\+/g;t=t.split(e);var h=1e3;i&&typeof i.maxKeys=="number"&&(h=i.maxKeys);var g=t.length;h>0&&g>h&&(g=h);for(var a=0;a=0?(w=d.substr(0,v),x=d.substr(v+1)):(w=d,x=""),S=decodeURIComponent(w),A=decodeURIComponent(x),o(r,S)?Array.isArray(r[S])?r[S].push(A):r[S]=[r[S],A]:r[S]=A}return r},G}var N,ee;function Qe(){if(ee)return N;ee=1;var o=function(t){switch(typeof t){case"string":return t;case"boolean":return t?"true":"false";case"number":return isFinite(t)?t:"";default:return""}};return N=function(t,e,n,i){return e=e||"&",n=n||"=",t===null&&(t=void 0),typeof t=="object"?Object.keys(t).map(function(r){var c=encodeURIComponent(o(r))+n;return Array.isArray(t[r])?t[r].map(function(h){return c+encodeURIComponent(o(h))}).join(e):c+encodeURIComponent(o(t[r]))}).filter(Boolean).join(e):i?encodeURIComponent(o(i))+n+encodeURIComponent(o(t)):""},N}var te;function et(){return te||(te=1,z.decode=z.parse=Ye(),z.encode=z.stringify=Qe()),z}var tt=et(),F=function(){return F=Object.assign||function(o){for(var t,e=1,n=arguments.length;e0&&r[r.length-1])&&(a[0]===6||a[0]===2)){e=0;continue}if(a[0]===3&&(!r||a[1]>r[0]&&a[1]0&&r[r.length-1])&&(a[0]===6||a[0]===2)){e=0;continue}if(a[0]===3&&(!r||a[1]>r[0]&&a[1]0)&&!(i=n.next()).done;)r.push(i.value)}catch(h){c={error:h}}finally{try{i&&!i.done&&(e=n.return)&&e.call(n)}finally{if(c)throw c.error}}return r},ct=function(){for(var o=[],t=0;t1e4*dt)return this.handleError(new _(b.InvalidFile,"file size exceed maximum value 10000G")),[2];if(this.putExtra.customVars&&!Be(this.putExtra.customVars))return this.handleError(new _(b.InvalidCustomVars,"customVars key should start width x:")),[2];if(this.putExtra.metadata&&!De(this.putExtra.metadata))return this.handleError(new _(b.InvalidMetadata,"metadata key should start with x-qn-meta-")),[2];r.label=1;case 1:return r.trys.push([1,4,,5]),this.uploadAt=new Date().getTime(),[4,this.checkAndUpdateUploadHost()];case 2:return r.sent(),[4,this.run()];case 3:return t=r.sent(),this.onComplete(t.data),this.checkAndUnfreezeHost(),this.sendLog(t.reqId,200),[2];case 4:return e=r.sent(),this.aborted?(this.logger.warn("upload is aborted."),this.sendLog("",-2),[2]):(this.clear(),this.logger.error(e),e instanceof q&&(this.sendLog(e.reqId,e.code),this.checkAndFreezeHost(e),n=++this.retryCount<=this.config.retryCount,i=ht.includes(e.code),i&&n)?(this.logger.warn("error auto retry: "+this.retryCount+"/"+this.config.retryCount+"."),this.putFile(),[2]):(this.onError(e),[3,5]));case 5:return[2]}})})},o.prototype.clear=function(){this.xhrList.forEach(function(t){t.onreadystatechange=null,t.abort()}),this.xhrList=[],this.logger.info("cleanup uploading xhr.")},o.prototype.stop=function(){this.logger.info("aborted."),this.clear(),this.aborted=!0},o.prototype.addXhr=function(t){this.xhrList.push(t)},o.prototype.sendLog=function(t,e){var n,i;this.logger.report({code:e,reqId:t,remoteIp:"",upType:"jssdk-h5",size:this.file.size,time:Math.floor(this.uploadAt/1e3),port:Ke((n=this.uploadHost)===null||n===void 0?void 0:n.getUrl()),host:We((i=this.uploadHost)===null||i===void 0?void 0:i.getUrl()),bytesSent:this.progress?this.progress.total.loaded:0,duration:Math.floor((new Date().getTime()-this.uploadAt)/1e3)})},o.prototype.getProgressInfoItem=function(t,e,n){return j({size:e,loaded:t,percent:t/e*100},n==null?{}:{fromCache:n})},o}(),pt=function(){var o=function(t,e){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,i){n.__proto__=i}||function(n,i){for(var r in i)i.hasOwnProperty(r)&&(n[r]=i[r])},o(t,e)};return function(t,e){o(t,e);function n(){this.constructor=t}t.prototype=e===null?Object.create(e):(n.prototype=e.prototype,new n)}}(),H=function(){return H=Object.assign||function(o){for(var t,e=1,n=arguments.length;e0&&r[r.length-1])&&(a[0]===6||a[0]===2)){e=0;continue}if(a[0]===3&&(!r||a[1]>r[0]&&a[1]1024)throw new _(b.InvalidChunkSize,"chunkSize maximum value is 1024");return[4,this.initBeforeUploadChunks()];case 1:g.sent(),e=new Ce(function(a){return P(h,void 0,void 0,function(){return L(this,function(d){switch(d.label){case 0:if(this.aborted)throw e.abort(),new Error("pool is aborted");return[4,this.uploadChunk(a)];case 1:return d.sent(),[2]}})})},this.config.concurrentRequestLimit),n=null,i=this.getLocalKey(),r=this.chunks.map(function(a,d){return e.enqueue({chunk:a,index:d})}),g.label=2;case 2:return g.trys.push([2,5,,6]),[4,Promise.all(r)];case 3:return g.sent(),[4,this.mkFileReq()];case 4:return n=g.sent(),[3,6];case 5:throw c=g.sent(),c instanceof q&&(c.code===612||c.code===400)&&K(i,this.logger),c;case 6:return K(i,this.logger),[2,n]}})})},t.prototype.uploadChunk=function(e){return P(this,void 0,void 0,function(){var n,i,r,c,h,g,a,d,v,w=this;return L(this,function(x){switch(x.label){case 0:return n=e.index,i=e.chunk,r=this.cachedUploadedList[n],this.logger.info("upload part "+n+", cache:",r),c=this.config.checkByMD5,h=function(){w.usedCacheList[n]=!0,w.updateChunkProgress(i.size,n),w.uploadedList[n]=r,w.updateLocalCache()},r&&!c?(h(),[2]):[4,Xe(i)];case 1:return g=x.sent(),this.logger.info("computed part md5.",g),r&&g===r.md5?(h(),[2]):(this.usedCacheList[n]=!1,a=function(S){w.updateChunkProgress(S.loaded,n)},d={body:i,md5:this.config.checkByServer?g:void 0,onProgress:a,onCreate:function(S){return w.addXhr(S)}},this.logger.info("part "+n+" start uploading."),[4,at(this.token,this.key,e.index+1,this.getUploadInfo(),d)]);case 2:return v=x.sent(),this.logger.info("part "+n+" upload completed."),a({loaded:i.size,total:i.size}),this.uploadedList[n]={etag:v.data.etag,md5:v.data.md5,size:i.size},this.updateLocalCache(),[2]}})})},t.prototype.mkFileReq=function(){return P(this,void 0,void 0,function(){var e,n,i=this;return L(this,function(r){switch(r.label){case 0:return e=H(H(H({parts:this.uploadedList.map(function(c,h){return{etag:c.etag,partNumber:h+1}}),fname:this.putExtra.fname},this.putExtra.mimeType&&{mimeType:this.putExtra.mimeType}),this.putExtra.customVars&&{customVars:this.putExtra.customVars}),this.putExtra.metadata&&{metadata:this.putExtra.metadata}),this.logger.info("parts upload completed, make file.",e),[4,st(this.token,this.key,this.getUploadInfo(),{onCreate:function(c){return i.addXhr(c)},body:JSON.stringify(e)})];case 1:return n=r.sent(),this.logger.info("finish Resume Progress."),this.updateMkFileProgress(1),[2,n]}})})},t.prototype.initBeforeUploadChunks=function(){return P(this,void 0,void 0,function(){var e,n,i;return L(this,function(r){switch(r.label){case 0:return this.uploadedList=[],this.usedCacheList=[],e=Ve(this.getLocalKey(),this.logger),e?[3,2]:(this.logger.info("init upload parts from api."),[4,ot(this.token,this.bucketName,this.key,this.uploadHost.getUrl())]);case 1:return n=r.sent(),this.logger.info("initd upload parts of id: "+n.data.uploadId+"."),this.uploadId=n.data.uploadId,this.cachedUploadedList=[],[3,3];case 2:i=["resume upload parts from local cache,","total "+e.data.length+" part,","id is "+e.id+"."],this.logger.info(i.join(" ")),this.cachedUploadedList=e.data,this.uploadId=e.id,r.label=3;case 3:return this.chunks=qe(this.file,this.config.chunkSize),this.loaded={mkFileProgress:0,chunks:this.chunks.map(function(c){return 0})},this.notifyResumeProgress(),[2]}})})},t.prototype.getUploadInfo=function(){return{id:this.uploadId,url:this.uploadHost.getUrl()}},t.prototype.getLocalKey=function(){return $e(this.file.name,this.key,this.file.size)},t.prototype.updateLocalCache=function(){je(this.getLocalKey(),{id:this.uploadId,data:this.uploadedList},this.logger)},t.prototype.updateChunkProgress=function(e,n){this.loaded.chunks[n]=e,this.notifyResumeProgress()},t.prototype.updateMkFileProgress=function(e){this.loaded.mkFileProgress=e,this.notifyResumeProgress()},t.prototype.notifyResumeProgress=function(){var e=this;this.progress={total:this.getProgressInfoItem(Me(this.loaded.chunks)+this.loaded.mkFileProgress,this.file.size+1),chunks:this.chunks.map(function(n,i){var r=e.usedCacheList[i];return e.getProgressInfoItem(e.loaded.chunks[i],n.size,r)}),uploadInfo:{id:this.uploadId,url:this.uploadHost.getUrl()}},this.onData(this.progress)},t}(ye),ie=function(o,t,e,n){function i(r){return r instanceof e?r:new e(function(c){c(r)})}return new(e||(e=Promise))(function(r,c){function h(d){try{a(n.next(d))}catch(v){c(v)}}function g(d){try{a(n.throw(d))}catch(v){c(v)}}function a(d){d.done?r(d.value):i(d.value).then(h,g)}a((n=n.apply(o,t||[])).next())})},oe=function(o,t){var e={label:0,sent:function(){if(r[0]&1)throw r[1];return r[1]},trys:[],ops:[]},n,i,r,c;return c={next:h(0),throw:h(1),return:h(2)},typeof Symbol=="function"&&(c[Symbol.iterator]=function(){return this}),c;function h(a){return function(d){return g([a,d])}}function g(a){if(n)throw new TypeError("Generator is already executing.");for(;e;)try{if(n=1,i&&(r=a[0]&2?i.return:a[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,a[1])).done)return r;switch(i=0,r&&(a=[a[0]&2,r.value]),a[0]){case 0:case 1:r=a;break;case 4:return e.label++,{value:a[1],done:!1};case 5:e.label++,i=a[1],a=[0];continue;case 7:a=e.ops.pop(),e.trys.pop();continue;default:if(r=e.trys,!(r=r.length>0&&r[r.length-1])&&(a[0]===6||a[0]===2)){e=0;continue}if(a[0]===3&&(!r||a[1]>r[0]&&a[1]>>1^3988292384:n>>>=1;t[e]=n}return t},o.prototype.append=function(t){for(var e=this.crc,n=0;n>>8^this.table[(e^t[n])&255];this.crc=e},o.prototype.compute=function(){return(this.crc^-1)>>>0},o.prototype.readAsUint8Array=function(t){return ie(this,void 0,void 0,function(){var e;return oe(this,function(n){switch(n.label){case 0:return typeof t.arrayBuffer!="function"?[3,2]:(e=Uint8Array.bind,[4,t.arrayBuffer()]);case 1:return[2,new(e.apply(Uint8Array,[void 0,n.sent()]))];case 2:return[2,new Promise(function(i,r){var c=new FileReader;c.onload=function(){if(c.result==null){r();return}if(typeof c.result=="string"){r();return}i(new Uint8Array(c.result))},c.readAsArrayBuffer(t)})]}})})},o.prototype.file=function(t){return ie(this,void 0,void 0,function(){var e,n,i,r,c,h;return oe(this,function(g){switch(g.label){case 0:return t.size<=R?(e=this.append,[4,this.readAsUint8Array(t)]):[3,2];case 1:return e.apply(this,[g.sent()]),[2,this.compute()];case 2:n=Math.ceil(t.size/R),i=0,g.label=3;case 3:return i0&&r[r.length-1])&&(a[0]===6||a[0]===2)){e=0;continue}if(a[0]===3&&(!r||a[1]>r[0]&&a[1]0&&ge(o,t,e-1)};var i=[t.code||"",t.reqId||"",t.host||"",t.remoteIp||"",t.port||"",t.duration||"",t.time||"",t.bytesSent||"",t.upType||"",t.size||""].join(",");n.send(i)}var _t=function(o,t){var e=typeof Symbol=="function"&&o[Symbol.iterator];if(!e)return o;var n=e.call(o),i,r=[],c;try{for(;(t===void 0||t-- >0)&&!(i=n.next()).done;)r.push(i.value)}catch(h){c={error:h}}finally{try{i&&!i.done&&(e=n.return)&&e.call(n)}finally{if(c)throw c.error}}return r},X=function(){for(var o=[],t=0;t0&&r[r.length-1])&&(a[0]===6||a[0]===2)){e=0;continue}if(a[0]===3&&(!r||a[1]>r[0]&&a[1]0)&&!(i=n.next()).done;)r.push(i.value)}catch(h){c={error:h}}finally{try{i&&!i.done&&(e=n.return)&&e.call(n)}finally{if(c)throw c.error}}return r},St=function(){for(var o=[],t=0;t=t},o.prototype.freeze=function(t){t===void 0&&(t=20);var e=new Date().getTime()+t*1e3;B.set(this.host,e)},o.prototype.unfreeze=function(){B.delete(this.host)},o.prototype.getUrl=function(){return this.protocol+"://"+this.host},o.prototype.getUnfreezeTime=function(){return B.get(this.host)},o}(),kt=function(){function o(t){t===void 0&&(t=[]),this.initHosts=t,this.cachedHostsMap=new Map}return o.prototype.register=function(t,e,n,i){this.cachedHostsMap.set(t+"@"+e,n.map(function(r){return new At(r,i)}))},o.prototype.refresh=function(t,e,n){var i,r,c,h;return se(this,void 0,void 0,function(){var g,a,d;return ue(this,function(v){switch(v.label){case 0:return g=this.cachedHostsMap.get(t+"@"+e)||[],g.length>0?[2]:this.initHosts.length>0?(this.register(t,e,this.initHosts,n),[2]):[4,it(t,e,n)];case 1:return a=v.sent(),a?.data!=null&&(d=St(((r=(i=a.data.up)===null||i===void 0?void 0:i.acc)===null||r===void 0?void 0:r.main)||[],((h=(c=a.data.up)===null||c===void 0?void 0:c.acc)===null||h===void 0?void 0:h.backup)||[]),this.register(t,e,d,n)),[2]}})})},o.prototype.getUp=function(t,e,n){return se(this,void 0,void 0,function(){var i,r,c;return ue(this,function(h){switch(h.label){case 0:return[4,this.refresh(t,e,n)];case 1:return h.sent(),i=this.cachedHostsMap.get(t+"@"+e)||[],i.length===0?[2,null]:(r=i.filter(function(g){return!g.isFrozen()}),r.length>0?[2,r[0]]:(c=i.slice().sort(function(g,a){return(g.getUnfreezeTime()||0)-(a.getUnfreezeTime()||0)}),[2,c[0]]))}})})},o}();function It(o,t,e,n){return o.config&&o.config.forceDirect?(n.info("ues forceDirect mode."),new ae(o,t,e,n)):o.file.size>4*R?(n.info("file size over 4M, use Resume."),new gt(o,t,e,n)):(n.info("file size less or equal than 4M, use Direct."),new ae(o,t,e,n))}function Ut(o,t,e,n,i){var r=new xt(e,i?.disableStatisticsReport,i?.debugLogLevel,o.name),c={file:o,key:t,token:e,putExtra:n,config:zt(i,r)},h=new kt(c.config.uphost);return new Ie(function(g){var a=It(c,{onData:function(d){return g.next(d)},onError:function(d){return g.error(d)},onComplete:function(d){return g.complete(d)}},h,r);return a.putFile(),a.stop.bind(a)})}var E=function(){return E=Object.assign||function(o){for(var t,e=1,n=arguments.length;e0)&&!(i=n.next()).done;)r.push(i.value)}catch(h){c={error:h}}finally{try{i&&!i.done&&(e=n.return)&&e.call(n)}finally{if(c)throw c.error}}return r},J=function(){for(var o=[],t=0;t{Ut(o,i,r,n.putExtra,n.putConfig).subscribe({next(g){g&&e(g.total)},error(g){h(g)},async complete(g){let a={url:n.domain+"/"+i,key:i};if(n.successHandle){a=await n.successHandle(a),c(a);return}c(a)}})})}async function Tt(o){const{getConfig:t}=me(),e=t("qiniu"),n=o.options,i=be(we(e),n);return o.options=i,await Et(o)}export{Rt as getToken,Tt as upload};