import{S as Y}from"./spark-md5.2cc5764b.js";import{s as Q}from"./querystring.62f12500.js";var G=globalThis&&globalThis.__extends||function(){var o=function(r,t){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,i){n.__proto__=i}||function(n,i){for(var e in i)i.hasOwnProperty(e)&&(n[e]=i[e])},o(r,t)};return function(r,t){o(r,t);function n(){this.constructor=r}r.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}}(),f;(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"})(f||(f={}));var d=function(){function o(r,t){this.name=r,this.message=t,this.stack=new Error().stack}return o}(),x=function(o){G(r,o);function r(t,n,i,e){var s=o.call(this,f.RequestError,i)||this;return s.code=t,s.reqId=n,s.isRequestError=!0,s.data=e,s}return r}(d),tt=function(o){G(r,o);function r(t,n){return n===void 0&&(n=""),o.call(this,0,n,t)||this}return r}(x),et=function(){function o(r,t){this.runTask=r,this.limit=t,this.queue=[],this.processing=[]}return o.prototype.enqueue=function(r){var t=this;return new Promise(function(n,i){t.queue.push({task:r,resolve:n,reject:i}),t.check()})},o.prototype.run=function(r){var t=this;this.queue=this.queue.filter(function(n){return n!==r}),this.processing.push(r),this.runTask(r.task).then(function(){t.processing=t.processing.filter(function(n){return n!==r}),r.resolve(),t.check()},function(n){return r.reject(n)})},o.prototype.check=function(){var r=this,t=this.processing.length,n=this.limit-t;this.queue.slice(0,n).forEach(function(i){r.run(i)})},o}(),rt=globalThis&&globalThis.__extends||function(){var o=function(r,t){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,i){n.__proto__=i}||function(n,i){for(var e in i)i.hasOwnProperty(e)&&(n[e]=i[e])},o(r,t)};return function(r,t){o(r,t);function n(){this.constructor=r}r.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}}(),_=globalThis&&globalThis.__assign||function(){return _=Object.assign||function(o){for(var r,t=1,n=arguments.length;t127&&u<2048)c=String.fromCharCode(u>>6|192,u&63|128);else if((u&63488^55296)>0)c=String.fromCharCode(u>>12|224,u>>6&63|128,u&63|128);else{if((u&64512^55296)>0)throw new RangeError("Unmatched trail surrogate at "+s);var a=r.charCodeAt(++s);if((a&64512^56320)>0)throw new RangeError("Unmatched lead surrogate at "+(s-1));u=((u&1023)<<10)+(a&1023)+65536,c=String.fromCharCode(u>>18|240,u>>12&63|128,u>>6&63|128,u&63|128)}c!==null&&(i>n&&(t+=r.slice(n,i)),t+=c,n=i=s+1)}return i>n&&(t+=r.slice(n,e)),t}function st(o){var r=[],t=0,n=0,i=0;for(o+="";t>10&1023)),r.push(String.fromCharCode(56320|n&1023))):r.push(String.fromCharCode(n)),t+=i}return r.join("")}function ut(o){var r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",t,n,i,e,s,u,c,a,l=0,h=0,p="",g=[];if(!o)return o;o=at(o+"");do t=o.charCodeAt(l++),n=o.charCodeAt(l++),i=o.charCodeAt(l++),a=t<<16|n<<8|i,e=a>>18&63,s=a>>12&63,u=a>>6&63,c=a&63,g[h++]=r.charAt(e)+r.charAt(s)+r.charAt(u)+r.charAt(c);while(l>16&255,n=a>>8&255,i=a&255,u===64?g[h++]=String.fromCharCode(t):c===64?g[h++]=String.fromCharCode(t,n):g[h++]=String.fromCharCode(t,n,i);while(l0&&e[e.length-1])&&(a[0]===6||a[0]===2)){t=0;continue}if(a[0]===3&&(!e||a[1]>e[0]&&a[1]o.size)t=o.size;else for(;o.size>t*1e4;)t*=2;for(var n=[],i=Math.ceil(o.size/t),e=0;e3?r[1]:r[0];if(!t)throw new d(f.InvalidToken,"missing assess key field.");var n=null;try{n=JSON.parse(ct(r[r.length-1]))}catch{throw new d(f.InvalidToken,"token parse failed.")}if(n==null)throw new d(f.InvalidToken,"putPolicy is null.");if(n.scope==null)throw new d(f.InvalidToken,"scope field is null.");var i=n.scope.split(":")[0];if(!i)throw new d(f.InvalidToken,"resolve bucketName failed.");return{assessKey:t,bucketName:i,scope:n.scope}}var v,b={z0:"z0",z1:"z1",z2:"z2",na0:"na0",as0:"as0",cnEast2:"cn-east-2"},St=(v={},v[b.z0]={srcUphost:["up.qiniup.com"],cdnUphost:["upload.qiniup.com"]},v[b.z1]={srcUphost:["up-z1.qiniup.com"],cdnUphost:["upload-z1.qiniup.com"]},v[b.z2]={srcUphost:["up-z2.qiniup.com"],cdnUphost:["upload-z2.qiniup.com"]},v[b.na0]={srcUphost:["up-na0.qiniup.com"],cdnUphost:["upload-na0.qiniup.com"]},v[b.as0]={srcUphost:["up-as0.qiniup.com"],cdnUphost:["upload-as0.qiniup.com"]},v[b.cnEast2]={srcUphost:["up-cn-east-2.qiniup.com"],cdnUphost:["upload-cn-east-2.qiniup.com"]},v),y=globalThis&&globalThis.__assign||function(){return y=Object.assign||function(o){for(var r,t=1,n=arguments.length;t0&&e[e.length-1])&&(a[0]===6||a[0]===2)){t=0;continue}if(a[0]===3&&(!e||a[1]>e[0]&&a[1]0&&e[e.length-1])&&(a[0]===6||a[0]===2)){t=0;continue}if(a[0]===3&&(!e||a[1]>e[0]&&a[1]0)&&!(i=n.next()).done;)e.push(i.value)}catch(u){s={error:u}}finally{try{i&&!i.done&&(t=n.return)&&t.call(n)}finally{if(s)throw s.error}}return e},Rt=globalThis&&globalThis.__spread||function(){for(var o=[],r=0;r1e4*qt)return this.handleError(new d(f.InvalidFile,"file size exceed maximum value 10000G")),[2];if(this.putExtra.customVars&&!gt(this.putExtra.customVars))return this.handleError(new d(f.InvalidCustomVars,"customVars key should start width x:")),[2];if(this.putExtra.metadata&&!pt(this.putExtra.metadata))return this.handleError(new d(f.InvalidMetadata,"metadata key should start with x-qn-meta-")),[2];u.label=1;case 1:return u.trys.push([1,4,,5]),this.uploadAt=new Date().getTime(),[4,this.checkAndUpdateUploadHost()];case 2:return u.sent(),[4,this.run()];case 3:return r=u.sent(),this.onComplete(r.data),this.checkAndUnfreezeHost(),this.sendLog(r.reqId,200),[2];case 4:return t=u.sent(),this.logger.error(t),this.clear(),t instanceof x&&(n=this.aborted?"":t.reqId,i=this.aborted?-2:t.code,this.sendLog(n,i),this.checkAndFreezeHost(t),e=++this.retryCount<=this.config.retryCount,s=!this.aborted&&Ht.includes(t.code),s&&e)?(this.logger.warn("error auto retry: "+this.retryCount+"/"+this.config.retryCount+"."),this.putFile(),[2]):(this.onError(t),[3,5]);case 5:return[2]}})})},o.prototype.clear=function(){this.logger.info("start cleaning all xhr."),this.xhrList.forEach(function(r){r.onreadystatechange=null,r.abort()}),this.logger.info("cleanup completed."),this.xhrList=[]},o.prototype.stop=function(){this.logger.info("stop."),this.clear(),this.aborted=!0},o.prototype.addXhr=function(r){this.xhrList.push(r)},o.prototype.sendLog=function(r,t){var n,i;this.logger.report({code:t,reqId:r,remoteIp:"",upType:"jssdk-h5",size:this.file.size,time:Math.floor(this.uploadAt/1e3),port:Tt((n=this.uploadHost)===null||n===void 0?void 0:n.getUrl()),host:Ct((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(r,t,n){return O({size:t,loaded:r,percent:r/t*100},n==null?{}:{fromCache:n})},o}(),Dt=globalThis&&globalThis.__extends||function(){var o=function(r,t){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,i){n.__proto__=i}||function(n,i){for(var e in i)i.hasOwnProperty(e)&&(n[e]=i[e])},o(r,t)};return function(r,t){o(r,t);function n(){this.constructor=r}r.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}}(),k=globalThis&&globalThis.__assign||function(){return k=Object.assign||function(o){for(var r,t=1,n=arguments.length;t0&&e[e.length-1])&&(a[0]===6||a[0]===2)){t=0;continue}if(a[0]===3&&(!e||a[1]>e[0]&&a[1]1024)throw new d(f.InvalidChunkSize,"chunkSize maximum value is 1024");return[4,this.initBeforeUploadChunks()];case 1:c.sent(),t=new et(function(a){return u.uploadChunk(a)},this.config.concurrentRequestLimit),n=null,i=this.getLocalKey(),e=this.chunks.map(function(a,l){return t.enqueue({chunk:a,index:l})}),c.label=2;case 2:return c.trys.push([2,5,,6]),[4,Promise.all(e)];case 3:return c.sent(),[4,this.mkFileReq()];case 4:return n=c.sent(),[3,6];case 5:throw s=c.sent(),s instanceof x&&(s.code===612||s.code===400)&&A(i,this.logger),s;case 6:return A(i,this.logger),[2,n]}})})},r.prototype.uploadChunk=function(t){return C(this,void 0,void 0,function(){var n,i,e,s,u,c,a,l,h,p=this;return S(this,function(g){switch(g.label){case 0:return n=t.index,i=t.chunk,e=this.cachedUploadedList[n],this.logger.info("upload part "+n+", cache:",e),s=this.config.checkByMD5,u=function(){p.usedCacheList[n]=!0,p.updateChunkProgress(i.size,n),p.uploadedList[n]=e,p.updateLocalCache()},e&&!s?(u(),[2]):[4,kt(i)];case 1:return c=g.sent(),this.logger.info("computed part md5.",c),e&&c===e.md5?(u(),[2]):(this.usedCacheList[n]=!1,a=function(P){p.updateChunkProgress(P.loaded,n)},l={body:i,md5:this.config.checkByServer?c:void 0,onProgress:a,onCreate:function(P){return p.addXhr(P)}},this.logger.info("part "+n+" start uploading."),[4,Pt(this.token,this.key,t.index+1,this.getUploadInfo(),l)]);case 2:return h=g.sent(),this.logger.info("part "+n+" upload completed."),a({loaded:i.size,total:i.size}),this.uploadedList[n]={etag:h.data.etag,md5:h.data.md5,size:i.size},this.updateLocalCache(),[2]}})})},r.prototype.mkFileReq=function(){return C(this,void 0,void 0,function(){var t,n,i=this;return S(this,function(e){switch(e.label){case 0:return t=k(k(k({parts:this.uploadedList.map(function(s,u){return{etag:s.etag,partNumber:u+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.",t),[4,Et(this.token,this.key,this.getUploadInfo(),{onCreate:function(s){return i.addXhr(s)},body:JSON.stringify(t)})];case 1:return n=e.sent(),this.logger.info("finish Resume Progress."),this.updateMkFileProgress(1),[2,n]}})})},r.prototype.initBeforeUploadChunks=function(){return C(this,void 0,void 0,function(){var t,n,i;return S(this,function(e){switch(e.label){case 0:return this.uploadedList=[],this.usedCacheList=[],t=mt(this.getLocalKey(),this.logger),t?[3,2]:(this.logger.info("init upload parts from api."),[4,Ft(this.token,this.bucketName,this.key,this.uploadHost.getUrl())]);case 1:return n=e.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 "+t.data.length+" part,","id is "+t.id+"."],this.logger.info(i.join(" ")),this.cachedUploadedList=t.data,this.uploadId=t.id,e.label=3;case 3:return this.chunks=dt(this.file,this.config.chunkSize),this.loaded={mkFileProgress:0,chunks:this.chunks.map(function(s){return 0})},this.notifyResumeProgress(),[2]}})})},r.prototype.getUploadInfo=function(){return{id:this.uploadId,url:this.uploadHost.getUrl()}},r.prototype.getLocalKey=function(){return bt(this.file.name,this.key,this.file.size)},r.prototype.updateLocalCache=function(){yt(this.getLocalKey(),{id:this.uploadId,data:this.uploadedList},this.logger)},r.prototype.updateChunkProgress=function(t,n){this.loaded.chunks[n]=t,this.notifyResumeProgress()},r.prototype.updateMkFileProgress=function(t){this.loaded.mkFileProgress=t,this.notifyResumeProgress()},r.prototype.notifyResumeProgress=function(){var t=this;this.progress={total:this.getProgressInfoItem(vt(this.loaded.chunks)+this.loaded.mkFileProgress,this.file.size+1),chunks:this.chunks.map(function(n,i){var e=t.usedCacheList[i];return t.getProgressInfoItem(t.loaded.chunks[i],n.size,e)}),uploadInfo:{id:this.uploadId,url:this.uploadHost.getUrl()}},this.onData(this.progress)},r}(K),D=globalThis&&globalThis.__awaiter||function(o,r,t,n){function i(e){return e instanceof t?e:new t(function(s){s(e)})}return new(t||(t=Promise))(function(e,s){function u(l){try{a(n.next(l))}catch(h){s(h)}}function c(l){try{a(n.throw(l))}catch(h){s(h)}}function a(l){l.done?e(l.value):i(l.value).then(u,c)}a((n=n.apply(o,r||[])).next())})},j=globalThis&&globalThis.__generator||function(o,r){var t={label:0,sent:function(){if(e[0]&1)throw e[1];return e[1]},trys:[],ops:[]},n,i,e,s;return s={next:u(0),throw:u(1),return:u(2)},typeof Symbol=="function"&&(s[Symbol.iterator]=function(){return this}),s;function u(a){return function(l){return c([a,l])}}function c(a){if(n)throw new TypeError("Generator is already executing.");for(;t;)try{if(n=1,i&&(e=a[0]&2?i.return:a[0]?i.throw||((e=i.return)&&e.call(i),0):i.next)&&!(e=e.call(i,a[1])).done)return e;switch(i=0,e&&(a=[a[0]&2,e.value]),a[0]){case 0:case 1:e=a;break;case 4:return t.label++,{value:a[1],done:!1};case 5:t.label++,i=a[1],a=[0];continue;case 7:a=t.ops.pop(),t.trys.pop();continue;default:if(e=t.trys,!(e=e.length>0&&e[e.length-1])&&(a[0]===6||a[0]===2)){t=0;continue}if(a[0]===3&&(!e||a[1]>e[0]&&a[1]>>1^3988292384:n>>>=1;r[t]=n}return r},o.prototype.append=function(r){for(var t=this.crc,n=0;n>>8^this.table[(t^r[n])&255];this.crc=t},o.prototype.compute=function(){return(this.crc^-1)>>>0},o.prototype.readAsUint8Array=function(r){return D(this,void 0,void 0,function(){var t;return j(this,function(n){switch(n.label){case 0:return typeof r.arrayBuffer!="function"?[3,2]:(t=Uint8Array.bind,[4,r.arrayBuffer()]);case 1:return[2,new(t.apply(Uint8Array,[void 0,n.sent()]))];case 2:return[2,new Promise(function(i,e){var s=new FileReader;s.onload=function(){if(s.result==null){e();return}if(typeof s.result=="string"){e();return}i(new Uint8Array(s.result))},s.readAsArrayBuffer(r)})]}})})},o.prototype.file=function(r){return D(this,void 0,void 0,function(){var t,n,i,e,s,u;return j(this,function(c){switch(c.label){case 0:return r.size<=m?(t=this.append,[4,this.readAsUint8Array(r)]):[3,2];case 1:return t.apply(this,[c.sent()]),[2,this.compute()];case 2:n=Math.ceil(r.size/m),i=0,c.label=3;case 3:return i0&&e[e.length-1])&&(a[0]===6||a[0]===2)){t=0;continue}if(a[0]===3&&(!e||a[1]>e[0]&&a[1]0&&Z(o,r,t-1)};var i=[r.code||"",r.reqId||"",r.host||"",r.remoteIp||"",r.port||"",r.duration||"",r.time||"",r.bytesSent||"",r.upType||"",r.size||""].join(",");n.send(i)}var Nt=globalThis&&globalThis.__read||function(o,r){var t=typeof Symbol=="function"&&o[Symbol.iterator];if(!t)return o;var n=t.call(o),i,e=[],s;try{for(;(r===void 0||r-- >0)&&!(i=n.next()).done;)e.push(i.value)}catch(u){s={error:u}}finally{try{i&&!i.done&&(t=n.return)&&t.call(n)}finally{if(s)throw s.error}}return e},E=globalThis&&globalThis.__spread||function(){for(var o=[],r=0;r0&&e[e.length-1])&&(a[0]===6||a[0]===2)){t=0;continue}if(a[0]===3&&(!e||a[1]>e[0]&&a[1]0)&&!(i=n.next()).done;)e.push(i.value)}catch(u){s={error:u}}finally{try{i&&!i.done&&(t=n.return)&&t.call(n)}finally{if(s)throw s.error}}return e},Wt=globalThis&&globalThis.__spread||function(){for(var o=[],r=0;r=r},o.prototype.freeze=function(r){r===void 0&&(r=20);var t=new Date().getTime()+r*1e3;I.set(this.host,t)},o.prototype.unfreeze=function(){I.delete(this.host)},o.prototype.getUrl=function(){return this.protocol+"://"+this.host},o.prototype.getUnfreezeTime=function(){return I.get(this.host)},o}(),Zt=function(){function o(r){r===void 0&&(r=[]),this.initHosts=r,this.cachedHostsMap=new Map}return o.prototype.register=function(r,t,n,i){this.cachedHostsMap.set(r+"@"+t,n.map(function(e){return new Kt(e,i)}))},o.prototype.refresh=function(r,t,n){var i,e,s,u;return $(this,void 0,void 0,function(){var c,a,l;return B(this,function(h){switch(h.label){case 0:return c=this.cachedHostsMap.get(r+"@"+t)||[],c.length>0?[2]:this.initHosts.length>0?(this.register(r,t,this.initHosts,n),[2]):[4,Ot(r,t,n)];case 1:return a=h.sent(),(a==null?void 0:a.data)!=null&&(l=Wt(((e=(i=a.data.up)===null||i===void 0?void 0:i.acc)===null||e===void 0?void 0:e.main)||[],((u=(s=a.data.up)===null||s===void 0?void 0:s.acc)===null||u===void 0?void 0:u.backup)||[]),this.register(r,t,l,n)),[2]}})})},o.prototype.getUp=function(r,t,n){return $(this,void 0,void 0,function(){var i,e,s;return B(this,function(u){switch(u.label){case 0:return[4,this.refresh(r,t,n)];case 1:return u.sent(),i=this.cachedHostsMap.get(r+"@"+t)||[],i.length===0?[2,null]:(e=i.filter(function(c){return!c.isFrozen()}),e.length>0?[2,e[0]]:(s=i.slice().sort(function(c,a){return(c.getUnfreezeTime()||0)-(a.getUnfreezeTime()||0)}),[2,s[0]]))}})})},o}();function Yt(o,r,t,n){return o.config&&o.config.forceDirect?(n.info("ues forceDirect mode."),new M(o,r,t,n)):o.file.size>4*m?(n.info("file size over 4M, use Resume."),new Mt(o,r,t,n)):(n.info("file size less or equal than 4M, use Direct."),new M(o,r,t,n))}function ie(o,r,t,n,i){var e=new Xt(t,i==null?void 0:i.disableStatisticsReport,i==null?void 0:i.debugLogLevel,o.name),s={file:o,key:r,token:t,putExtra:n,config:ee(i,e)},u=new Zt(s.config.uphost);return new ot(function(c){var a=Yt(s,{onData:function(l){return c.next(l)},onError:function(l){return c.error(l)},onComplete:function(l){return c.complete(l)}},u,e);return a.putFile(),a.stop.bind(a)})}var w=globalThis&&globalThis.__assign||function(){return w=Object.assign||function(o){for(var r,t=1,n=arguments.length;t0)&&!(i=n.next()).done;)e.push(i.value)}catch(u){s={error:u}}finally{try{i&&!i.done&&(t=n.return)&&t.call(n)}finally{if(s)throw s.error}}return e},U=globalThis&&globalThis.__spread||function(){for(var o=[],r=0;r