diff --git a/themes/default/public/js/worker/cancel.js b/themes/default/public/js/worker/cancel.js index f6daa6e..23669f9 100644 --- a/themes/default/public/js/worker/cancel.js +++ b/themes/default/public/js/worker/cancel.js @@ -1 +1 @@ -var Et=Object.create;var De=Object.defineProperty;var At=Object.getOwnPropertyDescriptor;var Lt=Object.getOwnPropertyNames;var Ot=Object.getPrototypeOf,xt=Object.prototype.hasOwnProperty;var Dt=(e,t,r)=>t in e?De(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var bt=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,r)=>(typeof require<"u"?require:t)[r]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var Ue=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var kt=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Lt(t))!xt.call(e,o)&&o!==r&&De(e,o,{get:()=>t[o],enumerable:!(n=At(t,o))||n.enumerable});return e};var Ie=(e,t,r)=>(r=e!=null?Et(Ot(e)):{},kt(t||!e||!e.__esModule?De(r,"default",{value:e,enumerable:!0}):r,e));var T=(e,t,r)=>Dt(e,typeof t!="symbol"?t+"":t,r);var $e=Ue((lr,be)=>{"use strict";var G=typeof Reflect=="object"?Reflect:null,je=G&&typeof G.apply=="function"?G.apply:function(t,r,n){return Function.prototype.apply.call(t,r,n)},ye;G&&typeof G.ownKeys=="function"?ye=G.ownKeys:Object.getOwnPropertySymbols?ye=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:ye=function(t){return Object.getOwnPropertyNames(t)};function _t(e){console&&console.warn&&console.warn(e)}var Be=Number.isNaN||function(t){return t!==t};function p(){p.init.call(this)}be.exports=p;be.exports.once=Pt;p.EventEmitter=p;p.prototype._events=void 0;p.prototype._eventsCount=0;p.prototype._maxListeners=void 0;var Ne=10;function ve(e){if(typeof e!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}Object.defineProperty(p,"defaultMaxListeners",{enumerable:!0,get:function(){return Ne},set:function(e){if(typeof e!="number"||e<0||Be(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");Ne=e}});p.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0};p.prototype.setMaxListeners=function(t){if(typeof t!="number"||t<0||Be(t))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+t+".");return this._maxListeners=t,this};function We(e){return e._maxListeners===void 0?p.defaultMaxListeners:e._maxListeners}p.prototype.getMaxListeners=function(){return We(this)};p.prototype.emit=function(t){for(var r=[],n=1;n0&&(s=r[0]),s instanceof Error)throw s;var c=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw c.context=s,c}var u=i[t];if(u===void 0)return!1;if(typeof u=="function")je(u,this,r);else for(var f=u.length,h=Xe(u,f),n=0;n0&&s.length>o&&!s.warned){s.warned=!0;var c=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");c.name="MaxListenersExceededWarning",c.emitter=e,c.type=t,c.count=s.length,_t(c)}return e}p.prototype.addListener=function(t,r){return Fe(this,t,r,!1)};p.prototype.on=p.prototype.addListener;p.prototype.prependListener=function(t,r){return Fe(this,t,r,!0)};function St(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function Je(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},o=St.bind(n);return o.listener=r,n.wrapFn=o,o}p.prototype.once=function(t,r){return ve(r),this.on(t,Je(this,t,r)),this};p.prototype.prependOnceListener=function(t,r){return ve(r),this.prependListener(t,Je(this,t,r)),this};p.prototype.removeListener=function(t,r){var n,o,i,s,c;if(ve(r),o=this._events,o===void 0)return this;if(n=o[t],n===void 0)return this;if(n===r||n.listener===r)--this._eventsCount===0?this._events=Object.create(null):(delete o[t],o.removeListener&&this.emit("removeListener",t,n.listener||r));else if(typeof n!="function"){for(i=-1,s=n.length-1;s>=0;s--)if(n[s]===r||n[s].listener===r){c=n[s].listener,i=s;break}if(i<0)return this;i===0?n.shift():Ct(n,i),n.length===1&&(o[t]=n[0]),o.removeListener!==void 0&&this.emit("removeListener",t,c||r)}return this};p.prototype.off=p.prototype.removeListener;p.prototype.removeAllListeners=function(t){var r,n,o;if(n=this._events,n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[t]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[t]),this;if(arguments.length===0){var i=Object.keys(n),s;for(o=0;o=0;o--)this.removeListener(t,r[o]);return this};function ze(e,t,r){var n=e._events;if(n===void 0)return[];var o=n[t];return o===void 0?[]:typeof o=="function"?r?[o.listener||o]:[o]:r?Rt(o):Xe(o,o.length)}p.prototype.listeners=function(t){return ze(this,t,!0)};p.prototype.rawListeners=function(t){return ze(this,t,!1)};p.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):He.call(e,t)};p.prototype.listenerCount=He;function He(e){var t=this._events;if(t!==void 0){var r=t[e];if(typeof r=="function")return 1;if(r!==void 0)return r.length}return 0}p.prototype.eventNames=function(){return this._eventsCount>0?ye(this._events):[]};function Xe(e,t){for(var r=new Array(t),n=0;n{"use strict";var a={cipher:{},hash:{},keyexchange:{},mode:{},misc:{},codec:{},exception:{corrupt:function(e){this.toString=function(){return"CORRUPT: "+this.message},this.message=e},invalid:function(e){this.toString=function(){return"INVALID: "+this.message},this.message=e},bug:function(e){this.toString=function(){return"BUG: "+this.message},this.message=e},notReady:function(e){this.toString=function(){return"NOT READY: "+this.message},this.message=e}}};a.cipher.aes=function(e){this.w[0][0][0]||this.C();var t,r,n,o,i=this.w[0][4],s=this.w[1];t=e.length;var c=1;if(t!==4&&t!==6&&t!==8)throw new a.exception.invalid("invalid aes key size");for(this.b=[n=e.slice(0),o=[]],e=t;e<4*t+28;e++)r=n[e-1],(e%t===0||t===8&&e%t===4)&&(r=i[r>>>24]<<24^i[r>>16&255]<<16^i[r>>8&255]<<8^i[r&255],e%t===0&&(r=r<<8^r>>>24^c<<24,c=c<<1^283*(c>>7))),n[e]=n[e-t]^r;for(t=0;e;t++,e--)r=n[t&3?e:e-4],o[t]=4>=e||4>t?r:s[0][i[r>>>24]]^s[1][i[r>>16&255]]^s[2][i[r>>8&255]]^s[3][i[r&255]]};a.cipher.aes.prototype={encrypt:function(e){return ot(this,e,0)},decrypt:function(e){return ot(this,e,1)},w:[[[],[],[],[],[]],[[],[],[],[],[]]],C:function(){var e=this.w[0],t=this.w[1],r=e[4],n=t[4],o,i,s,c=[],u=[],f,h,l,y;for(o=0;256>o;o++)u[(c[o]=o<<1^283*(o>>7))^o]=o;for(i=s=0;!r[i];i^=f||1,s=u[s]||1)for(l=s^s<<1^s<<2^s<<3^s<<4,l=l>>8^l&255^99,r[i]=l,n[l]=i,h=c[o=c[f=c[i]]],y=16843009*h^65537*o^257*f^16843008*i,h=257*c[l]^16843008*l,o=0;4>o;o++)e[o][i]=h=h<<24^h>>>8,t[o][l]=y=y<<24^y>>>8;for(o=0;5>o;o++)e[o]=e[o].slice(0),t[o]=t[o].slice(0)}};function ot(e,t,r){if(t.length!==4)throw new a.exception.invalid("invalid aes block size");var n=e.b[r],o=t[0]^n[0],i=t[r?3:1]^n[1],s=t[2]^n[2];t=t[r?1:3]^n[3];var c,u,f,h=n.length/4-2,l,y=4,d=[0,0,0,0];c=e.w[r],e=c[0];var g=c[1],k=c[2],C=c[3],N=c[4];for(l=0;l>>24]^g[i>>16&255]^k[s>>8&255]^C[t&255]^n[y],u=e[i>>>24]^g[s>>16&255]^k[t>>8&255]^C[o&255]^n[y+1],f=e[s>>>24]^g[t>>16&255]^k[o>>8&255]^C[i&255]^n[y+2],t=e[t>>>24]^g[o>>16&255]^k[i>>8&255]^C[s&255]^n[y+3],y+=4,o=c,i=u,s=f;for(l=0;4>l;l++)d[r?3&-l:l]=N[o>>>24]<<24^N[i>>16&255]<<16^N[s>>8&255]<<8^N[t&255]^n[y++],c=o,o=i,i=s,s=t,t=c;return d}a.bitArray={bitSlice:function(e,t,r){return e=a.bitArray.Y(e.slice(t/32),32-(t&31)).slice(1),r===void 0?e:a.bitArray.clamp(e,r-t)},extract:function(e,t,r){var n=Math.floor(-t-r&31);return((t+r-1^t)&-32?e[t/32|0]<<32-n^e[t/32+1|0]>>>n:e[t/32|0]>>>n)&(1<>t-1,1)),e},partial:function(e,t,r){return e===32?t:(r?t|0:t<<32-e)+1099511627776*e},getPartial:function(e){return Math.round(e/1099511627776)||32},equal:function(e,t){if(a.bitArray.bitLength(e)!==a.bitArray.bitLength(t))return!1;var r=0,n;for(n=0;n>>t),r=e[o]<<32-t;return o=e.length?e[e.length-1]:0,e=a.bitArray.getPartial(o),n.push(a.bitArray.partial(t+e&31,32>>24|r>>>8&65280|(r&65280)<<8|r<<24;return e}};a.codec.utf8String={fromBits:function(e){var t="",r=a.bitArray.bitLength(e),n,o;for(n=0;n>>8>>>8>>>8),o<<=8;return decodeURIComponent(escape(t))},toBits:function(e){e=unescape(encodeURIComponent(e));var t=[],r,n=0;for(r=0;r>>o)>>>26),6>o?(s=e[r]<<6-o,o+=26,r++):(s<<=6,o-=6);for(;n.length&3&&!t;)n+="=";return n},toBits:function(e,t){e=e.replace(/\s|=/g,"");var r=[],n,o=0,i=a.codec.base64.S,s=0,c;for(t&&(i=i.substr(0,62)+"-_"),n=0;nc)throw new a.exception.invalid("this isn't base64!");26>>o),s=c<<32-o):(o+=6,s^=c<<32-o)}return o&56&&r.push(a.bitArray.partial(o&56,s,1)),r}};a.codec.base64url={fromBits:function(e){return a.codec.base64.fromBits(e,1,1)},toBits:function(e){return a.codec.base64.toBits(e,1)}};a.hash.sha256=function(e){this.b[0]||this.C(),e?(this.g=e.g.slice(0),this.f=e.f.slice(0),this.c=e.c):this.reset()};a.hash.sha256.hash=function(e){return new a.hash.sha256().update(e).finalize()};a.hash.sha256.prototype={blockSize:512,reset:function(){return this.g=this.o.slice(0),this.f=[],this.c=0,this},update:function(e){typeof e=="string"&&(e=a.codec.utf8String.toBits(e));var t,r=this.f=a.bitArray.concat(this.f,e);if(t=this.c,e=this.c=t+a.bitArray.bitLength(e),9007199254740991t;r++){for(o=!0,n=2;n*n<=r;n++)if(r%n===0){o=!1;break}o&&(8>t&&(this.o[t]=e(Math.pow(r,.5))),this.b[t]=e(Math.pow(r,1/3)),t++)}},l:function(e){var t,r,n,o=this.g,i=this.b,s=o[0],c=o[1],u=o[2],f=o[3],h=o[4],l=o[5],y=o[6],d=o[7];for(t=0;64>t;t++)16>t?r=e[t]:(r=e[t+1&15],n=e[t+14&15],r=e[t&15]=(r>>>7^r>>>18^r>>>3^r<<25^r<<14)+(n>>>17^n>>>19^n>>>10^n<<15^n<<13)+e[t&15]+e[t+9&15]|0),r=r+d+(h>>>6^h>>>11^h>>>25^h<<26^h<<21^h<<7)+(y^h&(l^y))+i[t],d=y,y=l,l=h,h=f+r|0,f=u,u=c,c=s,s=r+(c&u^f&(c^u))+(c>>>2^c>>>13^c>>>22^c<<30^c<<19^c<<10)|0;o[0]=o[0]+s|0,o[1]=o[1]+c|0,o[2]=o[2]+u|0,o[3]=o[3]+f|0,o[4]=o[4]+h|0,o[5]=o[5]+l|0,o[6]=o[6]+y|0,o[7]=o[7]+d|0}};a.hash.sha512=function(e){this.b[0]||this.C(),e?(this.g=e.g.slice(0),this.f=e.f.slice(0),this.c=e.c):this.reset()};a.hash.sha512.hash=function(e){return new a.hash.sha512().update(e).finalize()};a.hash.sha512.prototype={blockSize:1024,reset:function(){return this.g=this.o.slice(0),this.f=[],this.c=0,this},update:function(e){typeof e=="string"&&(e=a.codec.utf8String.toBits(e));var t,r=this.f=a.bitArray.concat(this.f,e);if(t=this.c,e=this.c=t+a.bitArray.bitLength(e),9007199254740991r;n++){for(i=!0,o=2;o*o<=n;o++)if(n%o===0){i=!1;break}i&&(8>r&&(this.o[2*r]=e(Math.pow(n,.5)),this.o[2*r+1]=t(Math.pow(n,.5))<<24|this.ia[r]),this.b[2*r]=e(Math.pow(n,1/3)),this.b[2*r+1]=t(Math.pow(n,1/3))<<24|this.ka[r],r++)}},l:function(e){var t,r,n=this.g,o=this.b,i=n[0],s=n[1],c=n[2],u=n[3],f=n[4],h=n[5],l=n[6],y=n[7],d=n[8],g=n[9],k=n[10],C=n[11],N=n[12],le=n[13],Pe=n[14],de=n[15],L;if(typeof Uint32Array<"u"){L=Array(160);for(var E=0;32>E;E++)L[E]=e[E]}else L=e;var E=i,x=s,Z=c,H=u,ee=f,X=h,Ae=l,te=y,R=d,D=g,pe=k,re=C,me=N,ne=le,Le=Pe,oe=de;for(e=0;80>e;e++){if(16>e)t=L[2*e],r=L[2*e+1];else{r=L[2*(e-15)];var v=L[2*(e-15)+1];t=(v<<31|r>>>1)^(v<<24|r>>>8)^r>>>7;var P=(r<<31|v>>>1)^(r<<24|v>>>8)^(r<<25|v>>>7);r=L[2*(e-2)];var M=L[2*(e-2)+1],v=(M<<13|r>>>19)^(r<<3|M>>>29)^r>>>6,M=(r<<13|M>>>19)^(M<<3|r>>>29)^(r<<26|M>>>6),Oe=L[2*(e-7)],xe=L[2*(e-16)],ie=L[2*(e-16)+1];r=P+L[2*(e-7)+1],t=t+Oe+(r>>>0

>>0?1:0),r+=M,t+=v+(r>>>0>>0?1:0),r+=ie,t+=xe+(r>>>0>>0?1:0)}L[2*e]=t|=0,L[2*e+1]=r|=0;var Oe=R&pe^~R&me,Me=D&re^~D&ne,M=E&Z^E&ee^Z&ee,gt=x&H^x&X^H&X,xe=(x<<4|E>>>28)^(E<<30|x>>>2)^(E<<25|x>>>7),ie=(E<<4|x>>>28)^(x<<30|E>>>2)^(x<<25|E>>>7),wt=o[2*e],Te=o[2*e+1],v=oe+((R<<18|D>>>14)^(R<<14|D>>>18)^(D<<23|R>>>9)),P=Le+((D<<18|R>>>14)^(D<<14|R>>>18)^(R<<23|D>>>9))+(v>>>0>>0?1:0),v=v+Me,P=P+(Oe+(v>>>0>>0?1:0)),v=v+Te,P=P+(wt+(v>>>0>>0?1:0)),v=v+r|0,P=P+(t+(v>>>0>>0?1:0));r=ie+gt,t=xe+M+(r>>>0>>0?1:0),Le=me,oe=ne,me=pe,ne=re,pe=R,re=D,D=te+v|0,R=Ae+P+(D>>>0>>0?1:0)|0,Ae=ee,te=X,ee=Z,X=H,Z=E,H=x,x=v+r|0,E=P+t+(x>>>0>>0?1:0)|0}s=n[1]=s+x|0,n[0]=i+E+(s>>>0>>0?1:0)|0,u=n[3]=u+H|0,n[2]=c+Z+(u>>>0>>0?1:0)|0,h=n[5]=h+X|0,n[4]=f+ee+(h>>>0>>0?1:0)|0,y=n[7]=y+te|0,n[6]=l+Ae+(y>>>0>>0?1:0)|0,g=n[9]=g+D|0,n[8]=d+R+(g>>>0>>0?1:0)|0,C=n[11]=C+re|0,n[10]=k+pe+(C>>>0>>0?1:0)|0,le=n[13]=le+ne|0,n[12]=N+me+(le>>>0>>0?1:0)|0,de=n[15]=de+oe|0,n[14]=Pe+Le+(de>>>0>>0?1:0)|0}};a.mode.ccm={name:"ccm",F:[],listenProgress:function(e){a.mode.ccm.F.push(e)},unListenProgress:function(e){e=a.mode.ccm.F.indexOf(e),-1u)throw new a.exception.invalid("ccm: iv must be at least 7 bytes");for(i=2;4>i&&f>>>8*i;i++);return i<15-u&&(i=15-u),r=c.clamp(r,8*(15-i)),t=a.mode.ccm.U(e,t,r,n,o,i),s=a.mode.ccm.V(e,s,r,t,o,i),c.concat(s.data,s.tag)},decrypt:function(e,t,r,n,o){o=o||64,n=n||[];var i=a.bitArray,s=i.bitLength(r)/8,f=i.bitLength(t),c=i.clamp(t,f-o),u=i.bitSlice(t,f-o),f=(f-o)/8;if(7>s)throw new a.exception.invalid("ccm: iv must be at least 7 bytes");for(t=2;4>t&&f>>>8*t;t++);if(t<15-s&&(t=15-s),r=i.clamp(r,8*(15-t)),c=a.mode.ccm.V(e,c,r,u,o,t),e=a.mode.ccm.U(e,c.data,r,n,o,t),!i.equal(c.tag,e))throw new a.exception.corrupt("ccm: tag doesn't match");return c.data},ma:function(e,t,r,n,o,i){var s=[],c=a.bitArray,u=c.P;if(n=[c.partial(8,(t.length?64:0)|n-2<<2|i-1)],n=c.concat(n,r),n[3]|=o,n=e.encrypt(n),t.length)for(r=c.bitLength(t)/8,65279>=r?s=[c.partial(16,r)]:4294967295>=r&&(s=c.concat([c.partial(16,65534)],[r])),s=c.concat(s,t),t=0;to||16h&&(a.mode.ccm.da(s/u),h+=l),r[3]++,o=e.encrypt(r),t[s]^=o[0],t[s+1]^=o[1],t[s+2]^=o[2],t[s+3]^=o[3];return{tag:n,data:c.clamp(t,f)}}};a.misc.hmac=function(e,t){this.W=t=t||a.hash.sha256;var r=[[],[]],n,o=t.prototype.blockSize/32;for(this.B=[new t,new t],e.length>o&&(e=t.hash(e)),n=0;nn||0>r)throw new a.exception.invalid("invalid params to pbkdf2");typeof e=="string"&&(e=a.codec.utf8String.toBits(e)),typeof t=="string"&&(t=a.codec.utf8String.toBits(t)),o=o||a.misc.hmac,e=new o(e);var i,s,c,u,f=[],h=a.bitArray;for(u=1;32*f.length<(n||1);u++){for(o=i=e.encrypt(h.concat(t,[u])),s=1;ss;s++)o.push(4294967296*Math.random()|0);for(s=0;s=1<this.u&&(this.u=i),this.N++,this.b=a.hash.sha256.hash(this.b.concat(o)),this.K=new a.cipher.aes(this.b),n=0;4>n&&(this.m[n]=this.m[n]+1|0,!this.m[n]);n++);}for(n=0;n>>1;this.h[s].update([n,this.M++,2,t,i,e.length].concat(e))}break;case"string":t===void 0&&(t=e.length),this.h[s].update([n,this.M++,3,t,i,e.length]),this.h[s].update(e);break;default:u=1}if(u)throw new a.exception.bug("random: addEntropy only supports number, array of numbers or string");this.s[s]+=t,this.i+=t,c===this.A&&(this.isReady()!==this.A&&it("seeded",Math.max(this.u,this.i)),it("progress",this.getProgress()))},isReady:function(e){return e=this.R[e!==void 0?e:this.L],this.u&&this.u>=e?this.s[0]>this.$&&new Date().valueOf()>this.X?this.I|this.H:this.H:this.i>=e?this.I|this.A:this.A},getProgress:function(e){return e=this.R[e||this.L],this.u>=e||this.i>e?1:this.i/e},startCollectors:function(){if(!this.D){if(this.a={loadTimeCollector:ue(this,this.la),mouseCollector:ue(this,this.na),keyboardCollector:ue(this,this.ja),accelerometerCollector:ue(this,this.ca),touchCollector:ue(this,this.pa)},window.addEventListener)window.addEventListener("load",this.a.loadTimeCollector,!1),window.addEventListener("mousemove",this.a.mouseCollector,!1),window.addEventListener("keypress",this.a.keyboardCollector,!1),window.addEventListener("devicemotion",this.a.accelerometerCollector,!1),window.addEventListener("touchmove",this.a.touchCollector,!1);else if(document.attachEvent)document.attachEvent("onload",this.a.loadTimeCollector),document.attachEvent("onmousemove",this.a.mouseCollector),document.attachEvent("keypress",this.a.keyboardCollector);else throw new a.exception.bug("can't attach event");this.D=!0}},stopCollectors:function(){this.D&&(window.removeEventListener?(window.removeEventListener("load",this.a.loadTimeCollector,!1),window.removeEventListener("mousemove",this.a.mouseCollector,!1),window.removeEventListener("keypress",this.a.keyboardCollector,!1),window.removeEventListener("devicemotion",this.a.accelerometerCollector,!1),window.removeEventListener("touchmove",this.a.touchCollector,!1)):document.detachEvent&&(document.detachEvent("onload",this.a.loadTimeCollector),document.detachEvent("onmousemove",this.a.mouseCollector),document.detachEvent("keypress",this.a.keyboardCollector)),this.D=!1)},addEventListener:function(e,t){this.J[e][this.ea++]=t},removeEventListener:function(e,t){var r,n,o=this.J[e],i=[];for(n in o)o.hasOwnProperty(n)&&o[n]===t&&i.push(n);for(r=0;rt&&(e.m[t]=e.m[t]+1|0,!e.m[t]);t++);return e.K.encrypt(e.m)}function ue(e,t){return function(){t.apply(e,arguments)}}a.random=new a.prng(6);e:try{if(we=typeof q<"u"&&q.exports){try{Ee=bt("crypto")}catch{Ee=null}we=ge=Ee}if(we&&ge.randomBytes)fe=ge.randomBytes(128),fe=new Uint32Array(new Uint8Array(fe).buffer),a.random.addEntropy(fe,1024,"crypto['randomBytes']");else if(typeof window<"u"&&typeof Uint32Array<"u"){if(he=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(he);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(he);else break e;a.random.addEntropy(he,1024,"crypto['getRandomValues']")}}catch(e){typeof window<"u"&&window.console&&(console.log("There was an error collecting entropy from the browser:"),console.log(e))}var fe,ge,he,we,Ee;a.json={defaults:{v:1,iter:1e4,ks:128,ts:64,mode:"ccm",adata:"",cipher:"aes"},ha:function(e,t,r,n){r=r||{},n=n||{};var o=a.json,i=o.j({iv:a.random.randomWords(4,0)},o.defaults),s;if(o.j(i,r),r=i.adata,typeof i.salt=="string"&&(i.salt=a.codec.base64.toBits(i.salt)),typeof i.iv=="string"&&(i.iv=a.codec.base64.toBits(i.iv)),!a.mode[i.mode]||!a.cipher[i.cipher]||typeof e=="string"&&100>=i.iter||i.ts!==64&&i.ts!==96&&i.ts!==128||i.ks!==128&&i.ks!==192&&i.ks!==256||2>i.iv.length||4=t.iter||t.ts!==64&&t.ts!==96&&t.ts!==128||t.ks!==128&&t.ks!==192&&t.ks!==256||!t.iv||2>t.iv.length||4{let n=t.isOk()?{type:"Ok",value:t.value}:{type:"Err",value:t.error},o=r.withStackTrace?new Error().stack:void 0;return{data:n,message:e,stack:o}};function $(e,t,r,n){function o(i){return i instanceof r?i:new r(function(s){s(i)})}return new(r||(r=Promise))(function(i,s){function c(h){try{f(n.next(h))}catch(l){s(l)}}function u(h){try{f(n.throw(h))}catch(l){s(l)}}function f(h){h.done?i(h.value):o(h.value).then(c,u)}f((n=n.apply(e,t||[])).next())})}function Ve(e){var t=typeof Symbol=="function"&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&typeof e.length=="number")return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function U(e){return this instanceof U?(this.v=e,this):new U(e)}function Ye(e,t,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=r.apply(e,t||[]),o,i=[];return o=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),c("next"),c("throw"),c("return",s),o[Symbol.asyncIterator]=function(){return this},o;function s(d){return function(g){return Promise.resolve(g).then(d,l)}}function c(d,g){n[d]&&(o[d]=function(k){return new Promise(function(C,N){i.push([d,k,C,N])>1||u(d,k)})},g&&(o[d]=g(o[d])))}function u(d,g){try{f(n[d](g))}catch(k){y(i[0][3],k)}}function f(d){d.value instanceof U?Promise.resolve(d.value.v).then(h,l):y(i[0][2],d)}function h(d){u("next",d)}function l(d){u("throw",d)}function y(d,g){d(g),i.shift(),i.length&&u(i[0][0],i[0][1])}}function Ut(e){var t,r;return t={},n("next"),n("throw",function(o){throw o}),n("return"),t[Symbol.iterator]=function(){return this},t;function n(o,i){t[o]=e[o]?function(s){return(r=!r)?{value:U(e[o](s)),done:!1}:i?i(s):s}:i}}function It(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=e[Symbol.asyncIterator],r;return t?t.call(e):(e=typeof Ve=="function"?Ve(e):e[Symbol.iterator](),r={},n("next"),n("throw"),n("return"),r[Symbol.asyncIterator]=function(){return this},r);function n(i){r[i]=e[i]&&function(s){return new Promise(function(c,u){s=e[i](s),o(c,u,s.done,s.value)})}}function o(i,s,c,u){Promise.resolve(u).then(function(f){i({value:f,done:c})},s)}}var A=class e{constructor(t){this._promise=t}static fromSafePromise(t){let r=t.then(n=>new _(n));return new e(r)}static fromPromise(t,r){let n=t.then(o=>new _(o)).catch(o=>new S(r(o)));return new e(n)}static fromThrowable(t,r){return(...n)=>new e($(this,void 0,void 0,function*(){try{return new _(yield t(...n))}catch(o){return new S(r?r(o):o)}}))}static combine(t){return jt(t)}static combineWithAllErrors(t){return Nt(t)}map(t){return new e(this._promise.then(r=>$(this,void 0,void 0,function*(){return r.isErr()?new S(r.error):new _(yield t(r.value))})))}andThrough(t){return new e(this._promise.then(r=>$(this,void 0,void 0,function*(){if(r.isErr())return new S(r.error);let n=yield t(r.value);return n.isErr()?new S(n.error):new _(r.value)})))}andTee(t){return new e(this._promise.then(r=>$(this,void 0,void 0,function*(){if(r.isErr())return new S(r.error);try{yield t(r.value)}catch{}return new _(r.value)})))}mapErr(t){return new e(this._promise.then(r=>$(this,void 0,void 0,function*(){return r.isOk()?new _(r.value):new S(yield t(r.error))})))}andThen(t){return new e(this._promise.then(r=>{if(r.isErr())return new S(r.error);let n=t(r.value);return n instanceof e?n._promise:n}))}orElse(t){return new e(this._promise.then(r=>$(this,void 0,void 0,function*(){return r.isErr()?t(r.error):new _(r.value)})))}match(t,r){return this._promise.then(n=>n.match(t,r))}unwrapOr(t){return this._promise.then(r=>r.unwrapOr(t))}safeUnwrap(){return Ye(this,arguments,function*(){return yield U(yield U(yield*Ut(It(yield U(this._promise.then(r=>r.safeUnwrap()))))))})}then(t,r){return this._promise.then(t,r)}[Symbol.asyncIterator](){return Ye(this,arguments,function*(){let r=yield U(this._promise);return r.isErr()&&(yield yield U(O(r.error))),yield U(r.value)})}},I=e=>new A(Promise.resolve(new _(e))),O=e=>new A(Promise.resolve(new S(e))),mr=A.fromPromise,yr=A.fromSafePromise,vr=A.fromThrowable,qe=e=>{let t=J([]);for(let r of e)if(r.isErr()){t=B(r.error);break}else t.map(n=>n.push(r.value));return t},jt=e=>A.fromSafePromise(Promise.all(e)).andThen(qe),Qe=e=>{let t=J([]);for(let r of e)r.isErr()&&t.isErr()?t.error.push(r.error):r.isErr()&&t.isOk()?t=B([r.error]):r.isOk()&&t.isOk()&&t.value.push(r.value);return t},Nt=e=>A.fromSafePromise(Promise.all(e)).andThen(Qe),ke;(function(e){function t(o,i){return(...s)=>{try{let c=o(...s);return J(c)}catch(c){return B(i?i(c):c)}}}e.fromThrowable=t;function r(o){return qe(o)}e.combine=r;function n(o){return Qe(o)}e.combineWithAllErrors=n})(ke||(ke={}));var J=e=>new _(e);function B(e){return new S(e)}var _=class{constructor(t){this.value=t}isOk(){return!0}isErr(){return!this.isOk()}map(t){return J(t(this.value))}mapErr(t){return J(this.value)}andThen(t){return t(this.value)}andThrough(t){return t(this.value).map(r=>this.value)}andTee(t){try{t(this.value)}catch{}return J(this.value)}orElse(t){return J(this.value)}asyncAndThen(t){return t(this.value)}asyncAndThrough(t){return t(this.value).map(()=>this.value)}asyncMap(t){return A.fromSafePromise(t(this.value))}unwrapOr(t){return this.value}match(t,r){return t(this.value)}safeUnwrap(){let t=this.value;return function*(){return t}()}_unsafeUnwrap(t){return this.value}_unsafeUnwrapErr(t){throw Ke("Called `_unsafeUnwrapErr` on an Ok",this,t)}*[Symbol.iterator](){return this.value}},S=class{constructor(t){this.error=t}isOk(){return!1}isErr(){return!this.isOk()}map(t){return B(this.error)}mapErr(t){return B(t(this.error))}andThrough(t){return B(this.error)}andTee(t){return B(this.error)}andThen(t){return B(this.error)}orElse(t){return t(this.error)}asyncAndThen(t){return O(this.error)}asyncAndThrough(t){return O(this.error)}asyncMap(t){return O(this.error)}unwrapOr(t){return t}match(t,r){return r(this.error)}safeUnwrap(){let t=this.error;return function*(){throw yield B(t),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(t){throw Ke("Called `_unsafeUnwrap` on an Err",this,t)}_unsafeUnwrapErr(t){return this.error}*[Symbol.iterator](){let t=this;return yield t,t}},gr=ke.fromThrowable;var F=class extends Error{constructor(r,n={}){let{cause:o,context:i}=n;super(r,{cause:o});T(this,"context");this.name=this.constructor.name,this.context=i}};var z=e=>{if(e instanceof Error)return e;let t="[Unable to stringify the thrown value]";try{t=JSON.stringify(e)}catch{}return new Error(t)};var Bt=()=>typeof Deno<"u";var V=e=>Bt()?new URL(`./worker/${e}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${e==="main"?`worker/${e}`:e}.js`));var m=new tt.default,w,Ze=!1;self.onmessage=e=>{Ft(e),Ze||(Ze=!0,m.once("OPERATION_FAILED",()=>{w&&w.terminate()}))};var Y=(e,t)=>(Object.assign(e,t),typeof WorkerGlobalScope<"u"&&self.postMessage({event:"FILE_UPDATED",lufiFile:e}),e);var Ft=(e,t)=>{let{action:r}=e.data;if(r===5||r===8)w.postMessage(e.data);else{switch(r){case 2:w=new Worker(V("cancel"),{type:"module"}),w.postMessage(e.data);break;case 3:w=new Worker(V("download"),{type:"module"}),w.postMessage(e.data);break;case 4:w=new Worker(V("infos"),{type:"module"}),w.postMessage(e.data);break;case 7:w=w||new Worker(V("remove"),{type:"module"}),w.postMessage(e.data);break;case 9:w=w||new Worker(V("upload"),{type:"module"}),w.postMessage(e.data);break;default:console.error("Action not found")}w.onmessage=n=>{t&&t(n),self.postMessage(n.data)},w.onerror=n=>{console.error(`Error: ${n.message}`)}}},rt=()=>{m.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),m.once("OPERATION_FAILED",e=>{self.postMessage({event:"OPERATION_FAILED",error:e})})};var j=class extends F{};var se=class extends j{constructor(){super(...arguments);T(this,"message","An error occured while trying to connect to WebSocket")}};var K=class{constructor(t,r){if(!t||t.length!=64)throw Error("Charset must contain 64 characters");this._charset=t,this._noPadding=!!r,this._valid=new RegExp("^["+this._charset.replace("-","\\-")+"]+={0,2}$")}Encode(t){let r=t.byteLength;if(!r)return"";let n=new Uint8Array(t),o="";for(let i=0;i>2]+this._charset[(n[i]&3)<<4|n[i+1]>>4]+this._charset[(n[i+1]&15)<<2|n[i+2]>>6]+this._charset[n[i+2]&63];return r%3==2?(o=o.substring(0,o.length-1),this._noPadding||(o+="=")):r%3==1&&(o=o.substring(0,o.length-2),this._noPadding||(o+="==")),o}Decode(t){if(t=(t||"").replace(/[\s]/g,""),!t)return new ArrayBuffer(0);if(!this._valid.test(t))throw Error("Invalid base64 input sequence");let r=Math.floor(t.length*.75);t[t.length-2]=="="?r-=2:t[t.length-1]=="="&&r--;let n=new Uint8Array(r),o,i,s,c,u=0,f=0;for(;u>4,n[u++]=(i&15)<<4|s>>2,n[u++]=(s&3)<<6|c;return n.buffer}};var Jt=new K("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");function ae(e){return Jt.Decode(e)}var zt=new K("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",!0);function _e(e){return zt.Decode(e)}var ut=Ie(at());var W=class extends F{};var Q=class extends W{constructor(){super(...arguments);T(this,"message","Unable to decrypt the provided data")}};var ft=(e,t)=>{try{let r=typeof t=="string"?t:t.data;return I(ae(ut.default.decrypt(e,r)))}catch(r){return O(new Q(void 0,{cause:z(r)}))}};var ht=(e,t)=>Vt(e).andThen(r=>A.fromPromise(crypto.subtle.decrypt({name:"AES-GCM",iv:t.iv},r,ae(t.data)),n=>new Q(void 0,{cause:z(n)})));var Vt=e=>A.fromPromise(crypto.subtle.importKey("raw",_e(e),{name:"AES-GCM"},!1,["encrypt","decrypt"]),t=>new W("Unable to import cryptography key",{cause:z(t)}));var lt=(e,t)=>t.algo===void 0||t.algo===0?ft(e,t):ht(e,t);var b={},dt=5,qt=e=>(m.emit("UPLOAD_CANCELLED",e.success),I(void 0)),Qt=(e,t)=>{let r=e.split("XXMOJOXX"),n=r.shift();if(n!==void 0){let o=JSON.parse(n);if(ar(o)){let i=r.shift();if(i){let s=JSON.parse(i);return s.iv&&(s.iv=new Uint8Array(Object.values(s.iv))),lt(t.keys.client,s).andThen(c=>{let u=typeof c=="string"?new TextEncoder().encode(c).buffer:c;return o.part===0?(Y(t,{chunksReady:t.chunksReady+1,delAtFirstView:o.del_at_first_view,delay:o.delay,name:o.name,size:o.size,totalChunks:o.total,type:o.type,zipped:o.zipped}),m.emit("DOWNLOAD_STARTED")):Y(t,{chunksReady:t.chunksReady+1}),m.emit("CHUNK_DOWNLOADED",u,o.part),++o.part===o.total?rr(t).andThen(()=>(m.emit("DOWNLOAD_COMPLETE"),m.emit("SOCKET_OPERATION_TERMINATED"),I(void 0))):I(void 0)})}else{let s=new j("Cannot retrieve metadata from data received by the server");return m.emit("OPERATION_FAILED",s),O(s)}}else{let i=new j(o.msg);return m.emit("OPERATION_FAILED",i),O(i)}}else{let o=new j("Cannot retrieve metadata from data received by the server");return m.emit("OPERATION_FAILED",o),O(o)}},Zt=(e,t)=>{if(e.success)return e.j===0&&(Y(t,{keys:{client:t.keys.client,server:e.short},actionToken:e.token,queueIndex:e.i}),m.emit("UPLOAD_STARTED")),Y(t,{chunksReady:t.chunksReady+1,createdAt:e.created_at}),m.emit("CHUNK_UPLOADED"),t.chunksReady===t.totalChunks&&(Y(t,{uploadStatus:1}),m.emit("UPLOAD_COMPLETE"),m.emit("SOCKET_OPERATION_TERMINATED")),I(void 0);{let r=new j(e.msg);return m.emit("OPERATION_FAILED",r),O(r)}},er=(e,t)=>{let r=sr(e.data),n;if(r)if(!r.action&&r.msg){let o=new j(r.msg);return m.emit("OPERATION_FAILED",o),O(o)}else"delay"in r?n=Zt(r,t):n=qt(r);else n=Qt(e.data,t);return n},tr=e=>b!==void 0&&b[e]!==void 0&&b[e].readyState===WebSocket.CONNECTING,Ce=e=>b!==void 0&&b[e]!==void 0&&b[e].readyState===WebSocket.OPEN,pt=e=>Re(ir(e),e,`${JSON.stringify({id:e.keys.server,mod_token:e.actionToken,cancel:!0,i:e.queueIndex})}XXMOJOXXuseless`);var rr=e=>{let t;return e.password?t={ended:!0,file_pwd:e.password}:t={ended:!0},Re(or(e),e,JSON.stringify(t))};var Re=(e,t,r)=>Ce(e)?(b[e].onmessage=n=>er(n,t),b[e].send(r),I(void 0)):mt(e).andThen(()=>Re(e,t,r)),mt=(e,t=0)=>(!Ce(e)&&!tr(e)&&(b[e]=new WebSocket(e),m.once("SOCKET_OPERATION_TERMINATED",()=>{b[e].close()}),m.once("OPERATION_FAILED",()=>{m.emit("SOCKET_OPERATION_TERMINATED")}),b[e].onopen=()=>{m.emit("SOCKET_OPENED")},b[e].onclose=()=>{},b[e].onerror=()=>++t<=dt?(console.error(`An error happened while trying to connect to WebSocket ${e}. Trying again. ${t} / ${dt}`),mt(e,t)):(m.emit("SOCKET_ONERROR"),O(new se(`Unable to connect to WebSocket ${e}.`)))),nr(e).andThen(()=>I(e)).orElse(r=>O(r))),nr=e=>A.fromPromise(new Promise((t,r)=>{Ce(e)?t(void 0):(m.once("SOCKET_OPENED",()=>{t(void 0)}),m.on("SOCKET_ONERROR",()=>{r(new se)}))}),t=>z(t));var yt=(e,t)=>{let r=new URL(e);return r.protocol=r.protocol==="http:"?"ws:":"wss:",r.pathname+=t,new URL(r.origin+r.pathname)},or=e=>yt(new URL(e.serverUrl),"download"+`/${e.keys.server}`).toString(),ir=e=>yt(new URL(e.serverUrl),"upload").toString(),sr=e=>{try{let t=JSON.parse(e);if(t&&typeof t=="object")return t}catch{}return!1},ar=e=>typeof e=="object"&&e!==null&&!("msg"in e);var vt=!1;self.onmessage=e=>{vt||(rt(),vt=!0),m.on("UPLOAD_CANCELLED",t=>{self.postMessage({event:"UPLOAD_CANCELLED",success:t})}),ur(e.data).mapErr(t=>{self.postMessage({event:"OPERATION_FAILED",error:t})})};var ur=e=>pt(e.args.lufiFile); +var Et=Object.create;var De=Object.defineProperty;var At=Object.getOwnPropertyDescriptor;var Lt=Object.getOwnPropertyNames;var Ot=Object.getPrototypeOf,xt=Object.prototype.hasOwnProperty;var Dt=(e,t,r)=>t in e?De(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var bt=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,r)=>(typeof require<"u"?require:t)[r]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var Ue=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var kt=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Lt(t))!xt.call(e,o)&&o!==r&&De(e,o,{get:()=>t[o],enumerable:!(n=At(t,o))||n.enumerable});return e};var Ie=(e,t,r)=>(r=e!=null?Et(Ot(e)):{},kt(t||!e||!e.__esModule?De(r,"default",{value:e,enumerable:!0}):r,e));var T=(e,t,r)=>Dt(e,typeof t!="symbol"?t+"":t,r);var $e=Ue((lr,be)=>{"use strict";var G=typeof Reflect=="object"?Reflect:null,je=G&&typeof G.apply=="function"?G.apply:function(t,r,n){return Function.prototype.apply.call(t,r,n)},ye;G&&typeof G.ownKeys=="function"?ye=G.ownKeys:Object.getOwnPropertySymbols?ye=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:ye=function(t){return Object.getOwnPropertyNames(t)};function _t(e){console&&console.warn&&console.warn(e)}var Be=Number.isNaN||function(t){return t!==t};function p(){p.init.call(this)}be.exports=p;be.exports.once=Pt;p.EventEmitter=p;p.prototype._events=void 0;p.prototype._eventsCount=0;p.prototype._maxListeners=void 0;var Ne=10;function ve(e){if(typeof e!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}Object.defineProperty(p,"defaultMaxListeners",{enumerable:!0,get:function(){return Ne},set:function(e){if(typeof e!="number"||e<0||Be(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");Ne=e}});p.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0};p.prototype.setMaxListeners=function(t){if(typeof t!="number"||t<0||Be(t))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+t+".");return this._maxListeners=t,this};function We(e){return e._maxListeners===void 0?p.defaultMaxListeners:e._maxListeners}p.prototype.getMaxListeners=function(){return We(this)};p.prototype.emit=function(t){for(var r=[],n=1;n0&&(s=r[0]),s instanceof Error)throw s;var c=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw c.context=s,c}var u=i[t];if(u===void 0)return!1;if(typeof u=="function")je(u,this,r);else for(var f=u.length,h=Xe(u,f),n=0;n0&&s.length>o&&!s.warned){s.warned=!0;var c=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");c.name="MaxListenersExceededWarning",c.emitter=e,c.type=t,c.count=s.length,_t(c)}return e}p.prototype.addListener=function(t,r){return Fe(this,t,r,!1)};p.prototype.on=p.prototype.addListener;p.prototype.prependListener=function(t,r){return Fe(this,t,r,!0)};function St(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function Je(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},o=St.bind(n);return o.listener=r,n.wrapFn=o,o}p.prototype.once=function(t,r){return ve(r),this.on(t,Je(this,t,r)),this};p.prototype.prependOnceListener=function(t,r){return ve(r),this.prependListener(t,Je(this,t,r)),this};p.prototype.removeListener=function(t,r){var n,o,i,s,c;if(ve(r),o=this._events,o===void 0)return this;if(n=o[t],n===void 0)return this;if(n===r||n.listener===r)--this._eventsCount===0?this._events=Object.create(null):(delete o[t],o.removeListener&&this.emit("removeListener",t,n.listener||r));else if(typeof n!="function"){for(i=-1,s=n.length-1;s>=0;s--)if(n[s]===r||n[s].listener===r){c=n[s].listener,i=s;break}if(i<0)return this;i===0?n.shift():Ct(n,i),n.length===1&&(o[t]=n[0]),o.removeListener!==void 0&&this.emit("removeListener",t,c||r)}return this};p.prototype.off=p.prototype.removeListener;p.prototype.removeAllListeners=function(t){var r,n,o;if(n=this._events,n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[t]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[t]),this;if(arguments.length===0){var i=Object.keys(n),s;for(o=0;o=0;o--)this.removeListener(t,r[o]);return this};function ze(e,t,r){var n=e._events;if(n===void 0)return[];var o=n[t];return o===void 0?[]:typeof o=="function"?r?[o.listener||o]:[o]:r?Rt(o):Xe(o,o.length)}p.prototype.listeners=function(t){return ze(this,t,!0)};p.prototype.rawListeners=function(t){return ze(this,t,!1)};p.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):He.call(e,t)};p.prototype.listenerCount=He;function He(e){var t=this._events;if(t!==void 0){var r=t[e];if(typeof r=="function")return 1;if(r!==void 0)return r.length}return 0}p.prototype.eventNames=function(){return this._eventsCount>0?ye(this._events):[]};function Xe(e,t){for(var r=new Array(t),n=0;n{"use strict";var a={cipher:{},hash:{},keyexchange:{},mode:{},misc:{},codec:{},exception:{corrupt:function(e){this.toString=function(){return"CORRUPT: "+this.message},this.message=e},invalid:function(e){this.toString=function(){return"INVALID: "+this.message},this.message=e},bug:function(e){this.toString=function(){return"BUG: "+this.message},this.message=e},notReady:function(e){this.toString=function(){return"NOT READY: "+this.message},this.message=e}}};a.cipher.aes=function(e){this.w[0][0][0]||this.C();var t,r,n,o,i=this.w[0][4],s=this.w[1];t=e.length;var c=1;if(t!==4&&t!==6&&t!==8)throw new a.exception.invalid("invalid aes key size");for(this.b=[n=e.slice(0),o=[]],e=t;e<4*t+28;e++)r=n[e-1],(e%t===0||t===8&&e%t===4)&&(r=i[r>>>24]<<24^i[r>>16&255]<<16^i[r>>8&255]<<8^i[r&255],e%t===0&&(r=r<<8^r>>>24^c<<24,c=c<<1^283*(c>>7))),n[e]=n[e-t]^r;for(t=0;e;t++,e--)r=n[t&3?e:e-4],o[t]=4>=e||4>t?r:s[0][i[r>>>24]]^s[1][i[r>>16&255]]^s[2][i[r>>8&255]]^s[3][i[r&255]]};a.cipher.aes.prototype={encrypt:function(e){return ot(this,e,0)},decrypt:function(e){return ot(this,e,1)},w:[[[],[],[],[],[]],[[],[],[],[],[]]],C:function(){var e=this.w[0],t=this.w[1],r=e[4],n=t[4],o,i,s,c=[],u=[],f,h,l,y;for(o=0;256>o;o++)u[(c[o]=o<<1^283*(o>>7))^o]=o;for(i=s=0;!r[i];i^=f||1,s=u[s]||1)for(l=s^s<<1^s<<2^s<<3^s<<4,l=l>>8^l&255^99,r[i]=l,n[l]=i,h=c[o=c[f=c[i]]],y=16843009*h^65537*o^257*f^16843008*i,h=257*c[l]^16843008*l,o=0;4>o;o++)e[o][i]=h=h<<24^h>>>8,t[o][l]=y=y<<24^y>>>8;for(o=0;5>o;o++)e[o]=e[o].slice(0),t[o]=t[o].slice(0)}};function ot(e,t,r){if(t.length!==4)throw new a.exception.invalid("invalid aes block size");var n=e.b[r],o=t[0]^n[0],i=t[r?3:1]^n[1],s=t[2]^n[2];t=t[r?1:3]^n[3];var c,u,f,h=n.length/4-2,l,y=4,d=[0,0,0,0];c=e.w[r],e=c[0];var g=c[1],k=c[2],C=c[3],N=c[4];for(l=0;l>>24]^g[i>>16&255]^k[s>>8&255]^C[t&255]^n[y],u=e[i>>>24]^g[s>>16&255]^k[t>>8&255]^C[o&255]^n[y+1],f=e[s>>>24]^g[t>>16&255]^k[o>>8&255]^C[i&255]^n[y+2],t=e[t>>>24]^g[o>>16&255]^k[i>>8&255]^C[s&255]^n[y+3],y+=4,o=c,i=u,s=f;for(l=0;4>l;l++)d[r?3&-l:l]=N[o>>>24]<<24^N[i>>16&255]<<16^N[s>>8&255]<<8^N[t&255]^n[y++],c=o,o=i,i=s,s=t,t=c;return d}a.bitArray={bitSlice:function(e,t,r){return e=a.bitArray.Y(e.slice(t/32),32-(t&31)).slice(1),r===void 0?e:a.bitArray.clamp(e,r-t)},extract:function(e,t,r){var n=Math.floor(-t-r&31);return((t+r-1^t)&-32?e[t/32|0]<<32-n^e[t/32+1|0]>>>n:e[t/32|0]>>>n)&(1<>t-1,1)),e},partial:function(e,t,r){return e===32?t:(r?t|0:t<<32-e)+1099511627776*e},getPartial:function(e){return Math.round(e/1099511627776)||32},equal:function(e,t){if(a.bitArray.bitLength(e)!==a.bitArray.bitLength(t))return!1;var r=0,n;for(n=0;n>>t),r=e[o]<<32-t;return o=e.length?e[e.length-1]:0,e=a.bitArray.getPartial(o),n.push(a.bitArray.partial(t+e&31,32>>24|r>>>8&65280|(r&65280)<<8|r<<24;return e}};a.codec.utf8String={fromBits:function(e){var t="",r=a.bitArray.bitLength(e),n,o;for(n=0;n>>8>>>8>>>8),o<<=8;return decodeURIComponent(escape(t))},toBits:function(e){e=unescape(encodeURIComponent(e));var t=[],r,n=0;for(r=0;r>>o)>>>26),6>o?(s=e[r]<<6-o,o+=26,r++):(s<<=6,o-=6);for(;n.length&3&&!t;)n+="=";return n},toBits:function(e,t){e=e.replace(/\s|=/g,"");var r=[],n,o=0,i=a.codec.base64.S,s=0,c;for(t&&(i=i.substr(0,62)+"-_"),n=0;nc)throw new a.exception.invalid("this isn't base64!");26>>o),s=c<<32-o):(o+=6,s^=c<<32-o)}return o&56&&r.push(a.bitArray.partial(o&56,s,1)),r}};a.codec.base64url={fromBits:function(e){return a.codec.base64.fromBits(e,1,1)},toBits:function(e){return a.codec.base64.toBits(e,1)}};a.hash.sha256=function(e){this.b[0]||this.C(),e?(this.g=e.g.slice(0),this.f=e.f.slice(0),this.c=e.c):this.reset()};a.hash.sha256.hash=function(e){return new a.hash.sha256().update(e).finalize()};a.hash.sha256.prototype={blockSize:512,reset:function(){return this.g=this.o.slice(0),this.f=[],this.c=0,this},update:function(e){typeof e=="string"&&(e=a.codec.utf8String.toBits(e));var t,r=this.f=a.bitArray.concat(this.f,e);if(t=this.c,e=this.c=t+a.bitArray.bitLength(e),9007199254740991t;r++){for(o=!0,n=2;n*n<=r;n++)if(r%n===0){o=!1;break}o&&(8>t&&(this.o[t]=e(Math.pow(r,.5))),this.b[t]=e(Math.pow(r,1/3)),t++)}},l:function(e){var t,r,n,o=this.g,i=this.b,s=o[0],c=o[1],u=o[2],f=o[3],h=o[4],l=o[5],y=o[6],d=o[7];for(t=0;64>t;t++)16>t?r=e[t]:(r=e[t+1&15],n=e[t+14&15],r=e[t&15]=(r>>>7^r>>>18^r>>>3^r<<25^r<<14)+(n>>>17^n>>>19^n>>>10^n<<15^n<<13)+e[t&15]+e[t+9&15]|0),r=r+d+(h>>>6^h>>>11^h>>>25^h<<26^h<<21^h<<7)+(y^h&(l^y))+i[t],d=y,y=l,l=h,h=f+r|0,f=u,u=c,c=s,s=r+(c&u^f&(c^u))+(c>>>2^c>>>13^c>>>22^c<<30^c<<19^c<<10)|0;o[0]=o[0]+s|0,o[1]=o[1]+c|0,o[2]=o[2]+u|0,o[3]=o[3]+f|0,o[4]=o[4]+h|0,o[5]=o[5]+l|0,o[6]=o[6]+y|0,o[7]=o[7]+d|0}};a.hash.sha512=function(e){this.b[0]||this.C(),e?(this.g=e.g.slice(0),this.f=e.f.slice(0),this.c=e.c):this.reset()};a.hash.sha512.hash=function(e){return new a.hash.sha512().update(e).finalize()};a.hash.sha512.prototype={blockSize:1024,reset:function(){return this.g=this.o.slice(0),this.f=[],this.c=0,this},update:function(e){typeof e=="string"&&(e=a.codec.utf8String.toBits(e));var t,r=this.f=a.bitArray.concat(this.f,e);if(t=this.c,e=this.c=t+a.bitArray.bitLength(e),9007199254740991r;n++){for(i=!0,o=2;o*o<=n;o++)if(n%o===0){i=!1;break}i&&(8>r&&(this.o[2*r]=e(Math.pow(n,.5)),this.o[2*r+1]=t(Math.pow(n,.5))<<24|this.ia[r]),this.b[2*r]=e(Math.pow(n,1/3)),this.b[2*r+1]=t(Math.pow(n,1/3))<<24|this.ka[r],r++)}},l:function(e){var t,r,n=this.g,o=this.b,i=n[0],s=n[1],c=n[2],u=n[3],f=n[4],h=n[5],l=n[6],y=n[7],d=n[8],g=n[9],k=n[10],C=n[11],N=n[12],le=n[13],Pe=n[14],de=n[15],L;if(typeof Uint32Array<"u"){L=Array(160);for(var E=0;32>E;E++)L[E]=e[E]}else L=e;var E=i,x=s,Z=c,H=u,ee=f,X=h,Ae=l,te=y,R=d,D=g,pe=k,re=C,me=N,ne=le,Le=Pe,oe=de;for(e=0;80>e;e++){if(16>e)t=L[2*e],r=L[2*e+1];else{r=L[2*(e-15)];var v=L[2*(e-15)+1];t=(v<<31|r>>>1)^(v<<24|r>>>8)^r>>>7;var P=(r<<31|v>>>1)^(r<<24|v>>>8)^(r<<25|v>>>7);r=L[2*(e-2)];var M=L[2*(e-2)+1],v=(M<<13|r>>>19)^(r<<3|M>>>29)^r>>>6,M=(r<<13|M>>>19)^(M<<3|r>>>29)^(r<<26|M>>>6),Oe=L[2*(e-7)],xe=L[2*(e-16)],ie=L[2*(e-16)+1];r=P+L[2*(e-7)+1],t=t+Oe+(r>>>0

>>0?1:0),r+=M,t+=v+(r>>>0>>0?1:0),r+=ie,t+=xe+(r>>>0>>0?1:0)}L[2*e]=t|=0,L[2*e+1]=r|=0;var Oe=R&pe^~R&me,Me=D&re^~D&ne,M=E&Z^E&ee^Z&ee,gt=x&H^x&X^H&X,xe=(x<<4|E>>>28)^(E<<30|x>>>2)^(E<<25|x>>>7),ie=(E<<4|x>>>28)^(x<<30|E>>>2)^(x<<25|E>>>7),wt=o[2*e],Te=o[2*e+1],v=oe+((R<<18|D>>>14)^(R<<14|D>>>18)^(D<<23|R>>>9)),P=Le+((D<<18|R>>>14)^(D<<14|R>>>18)^(R<<23|D>>>9))+(v>>>0>>0?1:0),v=v+Me,P=P+(Oe+(v>>>0>>0?1:0)),v=v+Te,P=P+(wt+(v>>>0>>0?1:0)),v=v+r|0,P=P+(t+(v>>>0>>0?1:0));r=ie+gt,t=xe+M+(r>>>0>>0?1:0),Le=me,oe=ne,me=pe,ne=re,pe=R,re=D,D=te+v|0,R=Ae+P+(D>>>0>>0?1:0)|0,Ae=ee,te=X,ee=Z,X=H,Z=E,H=x,x=v+r|0,E=P+t+(x>>>0>>0?1:0)|0}s=n[1]=s+x|0,n[0]=i+E+(s>>>0>>0?1:0)|0,u=n[3]=u+H|0,n[2]=c+Z+(u>>>0>>0?1:0)|0,h=n[5]=h+X|0,n[4]=f+ee+(h>>>0>>0?1:0)|0,y=n[7]=y+te|0,n[6]=l+Ae+(y>>>0>>0?1:0)|0,g=n[9]=g+D|0,n[8]=d+R+(g>>>0>>0?1:0)|0,C=n[11]=C+re|0,n[10]=k+pe+(C>>>0>>0?1:0)|0,le=n[13]=le+ne|0,n[12]=N+me+(le>>>0>>0?1:0)|0,de=n[15]=de+oe|0,n[14]=Pe+Le+(de>>>0>>0?1:0)|0}};a.mode.ccm={name:"ccm",F:[],listenProgress:function(e){a.mode.ccm.F.push(e)},unListenProgress:function(e){e=a.mode.ccm.F.indexOf(e),-1u)throw new a.exception.invalid("ccm: iv must be at least 7 bytes");for(i=2;4>i&&f>>>8*i;i++);return i<15-u&&(i=15-u),r=c.clamp(r,8*(15-i)),t=a.mode.ccm.U(e,t,r,n,o,i),s=a.mode.ccm.V(e,s,r,t,o,i),c.concat(s.data,s.tag)},decrypt:function(e,t,r,n,o){o=o||64,n=n||[];var i=a.bitArray,s=i.bitLength(r)/8,f=i.bitLength(t),c=i.clamp(t,f-o),u=i.bitSlice(t,f-o),f=(f-o)/8;if(7>s)throw new a.exception.invalid("ccm: iv must be at least 7 bytes");for(t=2;4>t&&f>>>8*t;t++);if(t<15-s&&(t=15-s),r=i.clamp(r,8*(15-t)),c=a.mode.ccm.V(e,c,r,u,o,t),e=a.mode.ccm.U(e,c.data,r,n,o,t),!i.equal(c.tag,e))throw new a.exception.corrupt("ccm: tag doesn't match");return c.data},ma:function(e,t,r,n,o,i){var s=[],c=a.bitArray,u=c.P;if(n=[c.partial(8,(t.length?64:0)|n-2<<2|i-1)],n=c.concat(n,r),n[3]|=o,n=e.encrypt(n),t.length)for(r=c.bitLength(t)/8,65279>=r?s=[c.partial(16,r)]:4294967295>=r&&(s=c.concat([c.partial(16,65534)],[r])),s=c.concat(s,t),t=0;to||16h&&(a.mode.ccm.da(s/u),h+=l),r[3]++,o=e.encrypt(r),t[s]^=o[0],t[s+1]^=o[1],t[s+2]^=o[2],t[s+3]^=o[3];return{tag:n,data:c.clamp(t,f)}}};a.misc.hmac=function(e,t){this.W=t=t||a.hash.sha256;var r=[[],[]],n,o=t.prototype.blockSize/32;for(this.B=[new t,new t],e.length>o&&(e=t.hash(e)),n=0;nn||0>r)throw new a.exception.invalid("invalid params to pbkdf2");typeof e=="string"&&(e=a.codec.utf8String.toBits(e)),typeof t=="string"&&(t=a.codec.utf8String.toBits(t)),o=o||a.misc.hmac,e=new o(e);var i,s,c,u,f=[],h=a.bitArray;for(u=1;32*f.length<(n||1);u++){for(o=i=e.encrypt(h.concat(t,[u])),s=1;ss;s++)o.push(4294967296*Math.random()|0);for(s=0;s=1<this.u&&(this.u=i),this.N++,this.b=a.hash.sha256.hash(this.b.concat(o)),this.K=new a.cipher.aes(this.b),n=0;4>n&&(this.m[n]=this.m[n]+1|0,!this.m[n]);n++);}for(n=0;n>>1;this.h[s].update([n,this.M++,2,t,i,e.length].concat(e))}break;case"string":t===void 0&&(t=e.length),this.h[s].update([n,this.M++,3,t,i,e.length]),this.h[s].update(e);break;default:u=1}if(u)throw new a.exception.bug("random: addEntropy only supports number, array of numbers or string");this.s[s]+=t,this.i+=t,c===this.A&&(this.isReady()!==this.A&&it("seeded",Math.max(this.u,this.i)),it("progress",this.getProgress()))},isReady:function(e){return e=this.R[e!==void 0?e:this.L],this.u&&this.u>=e?this.s[0]>this.$&&new Date().valueOf()>this.X?this.I|this.H:this.H:this.i>=e?this.I|this.A:this.A},getProgress:function(e){return e=this.R[e||this.L],this.u>=e||this.i>e?1:this.i/e},startCollectors:function(){if(!this.D){if(this.a={loadTimeCollector:ue(this,this.la),mouseCollector:ue(this,this.na),keyboardCollector:ue(this,this.ja),accelerometerCollector:ue(this,this.ca),touchCollector:ue(this,this.pa)},window.addEventListener)window.addEventListener("load",this.a.loadTimeCollector,!1),window.addEventListener("mousemove",this.a.mouseCollector,!1),window.addEventListener("keypress",this.a.keyboardCollector,!1),window.addEventListener("devicemotion",this.a.accelerometerCollector,!1),window.addEventListener("touchmove",this.a.touchCollector,!1);else if(document.attachEvent)document.attachEvent("onload",this.a.loadTimeCollector),document.attachEvent("onmousemove",this.a.mouseCollector),document.attachEvent("keypress",this.a.keyboardCollector);else throw new a.exception.bug("can't attach event");this.D=!0}},stopCollectors:function(){this.D&&(window.removeEventListener?(window.removeEventListener("load",this.a.loadTimeCollector,!1),window.removeEventListener("mousemove",this.a.mouseCollector,!1),window.removeEventListener("keypress",this.a.keyboardCollector,!1),window.removeEventListener("devicemotion",this.a.accelerometerCollector,!1),window.removeEventListener("touchmove",this.a.touchCollector,!1)):document.detachEvent&&(document.detachEvent("onload",this.a.loadTimeCollector),document.detachEvent("onmousemove",this.a.mouseCollector),document.detachEvent("keypress",this.a.keyboardCollector)),this.D=!1)},addEventListener:function(e,t){this.J[e][this.ea++]=t},removeEventListener:function(e,t){var r,n,o=this.J[e],i=[];for(n in o)o.hasOwnProperty(n)&&o[n]===t&&i.push(n);for(r=0;rt&&(e.m[t]=e.m[t]+1|0,!e.m[t]);t++);return e.K.encrypt(e.m)}function ue(e,t){return function(){t.apply(e,arguments)}}a.random=new a.prng(6);e:try{if(we=typeof q<"u"&&q.exports){try{Ee=bt("crypto")}catch{Ee=null}we=ge=Ee}if(we&&ge.randomBytes)fe=ge.randomBytes(128),fe=new Uint32Array(new Uint8Array(fe).buffer),a.random.addEntropy(fe,1024,"crypto['randomBytes']");else if(typeof window<"u"&&typeof Uint32Array<"u"){if(he=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(he);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(he);else break e;a.random.addEntropy(he,1024,"crypto['getRandomValues']")}}catch(e){typeof window<"u"&&window.console&&(console.log("There was an error collecting entropy from the browser:"),console.log(e))}var fe,ge,he,we,Ee;a.json={defaults:{v:1,iter:1e4,ks:128,ts:64,mode:"ccm",adata:"",cipher:"aes"},ha:function(e,t,r,n){r=r||{},n=n||{};var o=a.json,i=o.j({iv:a.random.randomWords(4,0)},o.defaults),s;if(o.j(i,r),r=i.adata,typeof i.salt=="string"&&(i.salt=a.codec.base64.toBits(i.salt)),typeof i.iv=="string"&&(i.iv=a.codec.base64.toBits(i.iv)),!a.mode[i.mode]||!a.cipher[i.cipher]||typeof e=="string"&&100>=i.iter||i.ts!==64&&i.ts!==96&&i.ts!==128||i.ks!==128&&i.ks!==192&&i.ks!==256||2>i.iv.length||4=t.iter||t.ts!==64&&t.ts!==96&&t.ts!==128||t.ks!==128&&t.ks!==192&&t.ks!==256||!t.iv||2>t.iv.length||4{let n=t.isOk()?{type:"Ok",value:t.value}:{type:"Err",value:t.error},o=r.withStackTrace?new Error().stack:void 0;return{data:n,message:e,stack:o}};function $(e,t,r,n){function o(i){return i instanceof r?i:new r(function(s){s(i)})}return new(r||(r=Promise))(function(i,s){function c(h){try{f(n.next(h))}catch(l){s(l)}}function u(h){try{f(n.throw(h))}catch(l){s(l)}}function f(h){h.done?i(h.value):o(h.value).then(c,u)}f((n=n.apply(e,t||[])).next())})}function Ve(e){var t=typeof Symbol=="function"&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&typeof e.length=="number")return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function U(e){return this instanceof U?(this.v=e,this):new U(e)}function Ye(e,t,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=r.apply(e,t||[]),o,i=[];return o=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),c("next"),c("throw"),c("return",s),o[Symbol.asyncIterator]=function(){return this},o;function s(d){return function(g){return Promise.resolve(g).then(d,l)}}function c(d,g){n[d]&&(o[d]=function(k){return new Promise(function(C,N){i.push([d,k,C,N])>1||u(d,k)})},g&&(o[d]=g(o[d])))}function u(d,g){try{f(n[d](g))}catch(k){y(i[0][3],k)}}function f(d){d.value instanceof U?Promise.resolve(d.value.v).then(h,l):y(i[0][2],d)}function h(d){u("next",d)}function l(d){u("throw",d)}function y(d,g){d(g),i.shift(),i.length&&u(i[0][0],i[0][1])}}function Ut(e){var t,r;return t={},n("next"),n("throw",function(o){throw o}),n("return"),t[Symbol.iterator]=function(){return this},t;function n(o,i){t[o]=e[o]?function(s){return(r=!r)?{value:U(e[o](s)),done:!1}:i?i(s):s}:i}}function It(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=e[Symbol.asyncIterator],r;return t?t.call(e):(e=typeof Ve=="function"?Ve(e):e[Symbol.iterator](),r={},n("next"),n("throw"),n("return"),r[Symbol.asyncIterator]=function(){return this},r);function n(i){r[i]=e[i]&&function(s){return new Promise(function(c,u){s=e[i](s),o(c,u,s.done,s.value)})}}function o(i,s,c,u){Promise.resolve(u).then(function(f){i({value:f,done:c})},s)}}var A=class e{constructor(t){this._promise=t}static fromSafePromise(t){let r=t.then(n=>new _(n));return new e(r)}static fromPromise(t,r){let n=t.then(o=>new _(o)).catch(o=>new S(r(o)));return new e(n)}static fromThrowable(t,r){return(...n)=>new e($(this,void 0,void 0,function*(){try{return new _(yield t(...n))}catch(o){return new S(r?r(o):o)}}))}static combine(t){return jt(t)}static combineWithAllErrors(t){return Nt(t)}map(t){return new e(this._promise.then(r=>$(this,void 0,void 0,function*(){return r.isErr()?new S(r.error):new _(yield t(r.value))})))}andThrough(t){return new e(this._promise.then(r=>$(this,void 0,void 0,function*(){if(r.isErr())return new S(r.error);let n=yield t(r.value);return n.isErr()?new S(n.error):new _(r.value)})))}andTee(t){return new e(this._promise.then(r=>$(this,void 0,void 0,function*(){if(r.isErr())return new S(r.error);try{yield t(r.value)}catch{}return new _(r.value)})))}mapErr(t){return new e(this._promise.then(r=>$(this,void 0,void 0,function*(){return r.isOk()?new _(r.value):new S(yield t(r.error))})))}andThen(t){return new e(this._promise.then(r=>{if(r.isErr())return new S(r.error);let n=t(r.value);return n instanceof e?n._promise:n}))}orElse(t){return new e(this._promise.then(r=>$(this,void 0,void 0,function*(){return r.isErr()?t(r.error):new _(r.value)})))}match(t,r){return this._promise.then(n=>n.match(t,r))}unwrapOr(t){return this._promise.then(r=>r.unwrapOr(t))}safeUnwrap(){return Ye(this,arguments,function*(){return yield U(yield U(yield*Ut(It(yield U(this._promise.then(r=>r.safeUnwrap()))))))})}then(t,r){return this._promise.then(t,r)}[Symbol.asyncIterator](){return Ye(this,arguments,function*(){let r=yield U(this._promise);return r.isErr()&&(yield yield U(O(r.error))),yield U(r.value)})}},I=e=>new A(Promise.resolve(new _(e))),O=e=>new A(Promise.resolve(new S(e))),mr=A.fromPromise,yr=A.fromSafePromise,vr=A.fromThrowable,qe=e=>{let t=J([]);for(let r of e)if(r.isErr()){t=B(r.error);break}else t.map(n=>n.push(r.value));return t},jt=e=>A.fromSafePromise(Promise.all(e)).andThen(qe),Qe=e=>{let t=J([]);for(let r of e)r.isErr()&&t.isErr()?t.error.push(r.error):r.isErr()&&t.isOk()?t=B([r.error]):r.isOk()&&t.isOk()&&t.value.push(r.value);return t},Nt=e=>A.fromSafePromise(Promise.all(e)).andThen(Qe),ke;(function(e){function t(o,i){return(...s)=>{try{let c=o(...s);return J(c)}catch(c){return B(i?i(c):c)}}}e.fromThrowable=t;function r(o){return qe(o)}e.combine=r;function n(o){return Qe(o)}e.combineWithAllErrors=n})(ke||(ke={}));var J=e=>new _(e);function B(e){return new S(e)}var _=class{constructor(t){this.value=t}isOk(){return!0}isErr(){return!this.isOk()}map(t){return J(t(this.value))}mapErr(t){return J(this.value)}andThen(t){return t(this.value)}andThrough(t){return t(this.value).map(r=>this.value)}andTee(t){try{t(this.value)}catch{}return J(this.value)}orElse(t){return J(this.value)}asyncAndThen(t){return t(this.value)}asyncAndThrough(t){return t(this.value).map(()=>this.value)}asyncMap(t){return A.fromSafePromise(t(this.value))}unwrapOr(t){return this.value}match(t,r){return t(this.value)}safeUnwrap(){let t=this.value;return function*(){return t}()}_unsafeUnwrap(t){return this.value}_unsafeUnwrapErr(t){throw Ke("Called `_unsafeUnwrapErr` on an Ok",this,t)}*[Symbol.iterator](){return this.value}},S=class{constructor(t){this.error=t}isOk(){return!1}isErr(){return!this.isOk()}map(t){return B(this.error)}mapErr(t){return B(t(this.error))}andThrough(t){return B(this.error)}andTee(t){return B(this.error)}andThen(t){return B(this.error)}orElse(t){return t(this.error)}asyncAndThen(t){return O(this.error)}asyncAndThrough(t){return O(this.error)}asyncMap(t){return O(this.error)}unwrapOr(t){return t}match(t,r){return r(this.error)}safeUnwrap(){let t=this.error;return function*(){throw yield B(t),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(t){throw Ke("Called `_unsafeUnwrap` on an Err",this,t)}_unsafeUnwrapErr(t){return this.error}*[Symbol.iterator](){let t=this;return yield t,t}},gr=ke.fromThrowable;var F=class extends Error{constructor(r,n={}){let{cause:o,context:i}=n;super(r,{cause:o});T(this,"context");this.name=this.constructor.name,this.context=i}};var z=e=>{if(e instanceof Error)return e;let t="[Unable to stringify the thrown value]";try{t=JSON.stringify(e)}catch{}return new Error(t)};var Bt=()=>typeof Deno<"u";var V=e=>Bt()?new URL(`./worker/${e}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${e==="main"?`worker/${e}`:e}.js`));var m=new tt.default,w,Ze=!1;self.onmessage=e=>{Ft(e),Ze||(Ze=!0,m.once("OPERATION_FAILED",()=>{w&&w.terminate()}))};var Y=(e,t)=>(Object.assign(e,t),typeof WorkerGlobalScope<"u"&&self.postMessage({event:"FILE_UPDATED",lufiFile:e}),e);var Ft=(e,t)=>{let{action:r}=e.data;if(r===5||r===8)w.postMessage(e.data,e.data);else{switch(r){case 2:w=new Worker(V("cancel"),{type:"module"}),w.postMessage(e.data,e.data);break;case 3:w=new Worker(V("download"),{type:"module"}),w.postMessage(e.data,e.data);break;case 4:w=new Worker(V("infos"),{type:"module"}),w.postMessage(e.data,e.data);break;case 7:w=w||new Worker(V("remove"),{type:"module"}),w.postMessage(e.data,e.data);break;case 9:w=w||new Worker(V("upload"),{type:"module"}),w.postMessage(e.data,e.data);break;default:console.error("Action not found")}w.onmessage=n=>{t&&t(n),self.postMessage(n.data,n.data)},w.onerror=n=>{console.error(`Error: ${n.message}`)}}},rt=()=>{m.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),m.once("OPERATION_FAILED",e=>{self.postMessage({event:"OPERATION_FAILED",error:e})})};var j=class extends F{};var se=class extends j{constructor(){super(...arguments);T(this,"message","An error occured while trying to connect to WebSocket")}};var K=class{constructor(t,r){if(!t||t.length!=64)throw Error("Charset must contain 64 characters");this._charset=t,this._noPadding=!!r,this._valid=new RegExp("^["+this._charset.replace("-","\\-")+"]+={0,2}$")}Encode(t){let r=t.byteLength;if(!r)return"";let n=new Uint8Array(t),o="";for(let i=0;i>2]+this._charset[(n[i]&3)<<4|n[i+1]>>4]+this._charset[(n[i+1]&15)<<2|n[i+2]>>6]+this._charset[n[i+2]&63];return r%3==2?(o=o.substring(0,o.length-1),this._noPadding||(o+="=")):r%3==1&&(o=o.substring(0,o.length-2),this._noPadding||(o+="==")),o}Decode(t){if(t=(t||"").replace(/[\s]/g,""),!t)return new ArrayBuffer(0);if(!this._valid.test(t))throw Error("Invalid base64 input sequence");let r=Math.floor(t.length*.75);t[t.length-2]=="="?r-=2:t[t.length-1]=="="&&r--;let n=new Uint8Array(r),o,i,s,c,u=0,f=0;for(;u>4,n[u++]=(i&15)<<4|s>>2,n[u++]=(s&3)<<6|c;return n.buffer}};var Jt=new K("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");function ae(e){return Jt.Decode(e)}var zt=new K("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",!0);function _e(e){return zt.Decode(e)}var ut=Ie(at());var W=class extends F{};var Q=class extends W{constructor(){super(...arguments);T(this,"message","Unable to decrypt the provided data")}};var ft=(e,t)=>{try{let r=typeof t=="string"?t:t.data;return I(ae(ut.default.decrypt(e,r)))}catch(r){return O(new Q(void 0,{cause:z(r)}))}};var ht=(e,t)=>Vt(e).andThen(r=>A.fromPromise(crypto.subtle.decrypt({name:"AES-GCM",iv:t.iv},r,ae(t.data)),n=>new Q(void 0,{cause:z(n)})));var Vt=e=>A.fromPromise(crypto.subtle.importKey("raw",_e(e),{name:"AES-GCM"},!1,["encrypt","decrypt"]),t=>new W("Unable to import cryptography key",{cause:z(t)}));var lt=(e,t)=>t.algo===void 0||t.algo===0?ft(e,t):ht(e,t);var b={},dt=5,qt=e=>(m.emit("UPLOAD_CANCELLED",e.success),I(void 0)),Qt=(e,t)=>{let r=e.split("XXMOJOXX"),n=r.shift();if(n!==void 0){let o=JSON.parse(n);if(ar(o)){let i=r.shift();if(i){let s=JSON.parse(i);return s.iv&&(s.iv=new Uint8Array(Object.values(s.iv))),lt(t.keys.client,s).andThen(c=>{let u=typeof c=="string"?new TextEncoder().encode(c).buffer:c;return o.part===0?(Y(t,{chunksReady:t.chunksReady+1,delAtFirstView:o.del_at_first_view,delay:o.delay,name:o.name,size:o.size,totalChunks:o.total,type:o.type,zipped:o.zipped}),m.emit("DOWNLOAD_STARTED")):Y(t,{chunksReady:t.chunksReady+1}),m.emit("CHUNK_DOWNLOADED",u,o.part),++o.part===o.total?rr(t).andThen(()=>(m.emit("DOWNLOAD_COMPLETE"),m.emit("SOCKET_OPERATION_TERMINATED"),I(void 0))):I(void 0)})}else{let s=new j("Cannot retrieve metadata from data received by the server");return m.emit("OPERATION_FAILED",s),O(s)}}else{let i=new j(o.msg);return m.emit("OPERATION_FAILED",i),O(i)}}else{let o=new j("Cannot retrieve metadata from data received by the server");return m.emit("OPERATION_FAILED",o),O(o)}},Zt=(e,t)=>{if(e.success)return e.j===0&&(Y(t,{keys:{client:t.keys.client,server:e.short},actionToken:e.token,queueIndex:e.i}),m.emit("UPLOAD_STARTED")),Y(t,{chunksReady:t.chunksReady+1,createdAt:e.created_at}),m.emit("CHUNK_UPLOADED"),t.chunksReady===t.totalChunks&&(Y(t,{uploadStatus:1}),m.emit("UPLOAD_COMPLETE"),m.emit("SOCKET_OPERATION_TERMINATED")),I(void 0);{let r=new j(e.msg);return m.emit("OPERATION_FAILED",r),O(r)}},er=(e,t)=>{let r=sr(e.data),n;if(r)if(!r.action&&r.msg){let o=new j(r.msg);return m.emit("OPERATION_FAILED",o),O(o)}else"delay"in r?n=Zt(r,t):n=qt(r);else n=Qt(e.data,t);return n},tr=e=>b!==void 0&&b[e]!==void 0&&b[e].readyState===WebSocket.CONNECTING,Ce=e=>b!==void 0&&b[e]!==void 0&&b[e].readyState===WebSocket.OPEN,pt=e=>Re(ir(e),e,`${JSON.stringify({id:e.keys.server,mod_token:e.actionToken,cancel:!0,i:e.queueIndex})}XXMOJOXXuseless`);var rr=e=>{let t;return e.password?t={ended:!0,file_pwd:e.password}:t={ended:!0},Re(or(e),e,JSON.stringify(t))};var Re=(e,t,r)=>Ce(e)?(b[e].onmessage=n=>er(n,t),b[e].send(r),I(void 0)):mt(e).andThen(()=>Re(e,t,r)),mt=(e,t=0)=>(!Ce(e)&&!tr(e)&&(b[e]=new WebSocket(e),m.once("SOCKET_OPERATION_TERMINATED",()=>{b[e].close()}),m.once("OPERATION_FAILED",()=>{m.emit("SOCKET_OPERATION_TERMINATED")}),b[e].onopen=()=>{m.emit("SOCKET_OPENED")},b[e].onclose=()=>{},b[e].onerror=()=>++t<=dt?(console.error(`An error happened while trying to connect to WebSocket ${e}. Trying again. ${t} / ${dt}`),mt(e,t)):(m.emit("SOCKET_ONERROR"),O(new se(`Unable to connect to WebSocket ${e}.`)))),nr(e).andThen(()=>I(e)).orElse(r=>O(r))),nr=e=>A.fromPromise(new Promise((t,r)=>{Ce(e)?t(void 0):(m.once("SOCKET_OPENED",()=>{t(void 0)}),m.on("SOCKET_ONERROR",()=>{r(new se)}))}),t=>z(t));var yt=(e,t)=>{let r=new URL(e);return r.protocol=r.protocol==="http:"?"ws:":"wss:",r.pathname+=t,new URL(r.origin+r.pathname)},or=e=>yt(new URL(e.serverUrl),"download"+`/${e.keys.server}`).toString(),ir=e=>yt(new URL(e.serverUrl),"upload").toString(),sr=e=>{try{let t=JSON.parse(e);if(t&&typeof t=="object")return t}catch{}return!1},ar=e=>typeof e=="object"&&e!==null&&!("msg"in e);var vt=!1;self.onmessage=e=>{vt||(rt(),vt=!0),m.on("UPLOAD_CANCELLED",t=>{self.postMessage({event:"UPLOAD_CANCELLED",success:t})}),ur(e.data).mapErr(t=>{self.postMessage({event:"OPERATION_FAILED",error:t})})};var ur=e=>pt(e.args.lufiFile); diff --git a/themes/default/public/js/worker/download.js b/themes/default/public/js/worker/download.js index 747f440..dab3eca 100644 --- a/themes/default/public/js/worker/download.js +++ b/themes/default/public/js/worker/download.js @@ -1 +1 @@ -var Ar=Object.create;var it=Object.defineProperty;var xr=Object.getOwnPropertyDescriptor;var Or=Object.getOwnPropertyNames;var br=Object.getPrototypeOf,Lr=Object.prototype.hasOwnProperty;var Dt=t=>{throw TypeError(t)};var _r=(t,e,r)=>e in t?it(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var Dr=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var st=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var Cr=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Or(e))!Lr.call(t,o)&&o!==r&&it(t,o,{get:()=>e[o],enumerable:!(n=xr(e,o))||n.enumerable});return t};var at=(t,e,r)=>(r=t!=null?Ar(br(t)):{},Cr(e||!t||!t.__esModule?it(r,"default",{value:t,enumerable:!0}):r,t));var U=(t,e,r)=>_r(t,typeof e!="symbol"?e+"":e,r),ct=(t,e,r)=>e.has(t)||Dt("Cannot "+r);var d=(t,e,r)=>(ct(t,e,"read from private field"),r?r.call(t):e.get(t)),x=(t,e,r)=>e.has(t)?Dt("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),w=(t,e,r,n)=>(ct(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),O=(t,e,r)=>(ct(t,e,"access private method"),r);var ze=(t,e,r,n)=>({set _(o){w(t,e,o,r)},get _(){return d(t,e,n)}});var Bt=st((yn,ut)=>{"use strict";var se=typeof Reflect=="object"?Reflect:null,Ct=se&&typeof se.apply=="function"?se.apply:function(e,r,n){return Function.prototype.apply.call(e,r,n)},Je;se&&typeof se.ownKeys=="function"?Je=se.ownKeys:Object.getOwnPropertySymbols?Je=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:Je=function(e){return Object.getOwnPropertyNames(e)};function Sr(t){console&&console.warn&&console.warn(t)}var kt=Number.isNaN||function(e){return e!==e};function g(){g.init.call(this)}ut.exports=g;ut.exports.once=Rr;g.EventEmitter=g;g.prototype._events=void 0;g.prototype._eventsCount=0;g.prototype._maxListeners=void 0;var St=10;function He(t){if(typeof t!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t)}Object.defineProperty(g,"defaultMaxListeners",{enumerable:!0,get:function(){return St},set:function(t){if(typeof t!="number"||t<0||kt(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");St=t}});g.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0};g.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||kt(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this};function Pt(t){return t._maxListeners===void 0?g.defaultMaxListeners:t._maxListeners}g.prototype.getMaxListeners=function(){return Pt(this)};g.prototype.emit=function(e){for(var r=[],n=1;n0&&(s=r[0]),s instanceof Error)throw s;var c=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw c.context=s,c}var u=i[e];if(u===void 0)return!1;if(typeof u=="function")Ct(u,this,r);else for(var f=u.length,h=Ut(u,f),n=0;n0&&s.length>o&&!s.warned){s.warned=!0;var c=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");c.name="MaxListenersExceededWarning",c.emitter=t,c.type=e,c.count=s.length,Sr(c)}return t}g.prototype.addListener=function(e,r){return Tt(this,e,r,!1)};g.prototype.on=g.prototype.addListener;g.prototype.prependListener=function(e,r){return Tt(this,e,r,!0)};function kr(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function Rt(t,e,r){var n={fired:!1,wrapFn:void 0,target:t,type:e,listener:r},o=kr.bind(n);return o.listener=r,n.wrapFn=o,o}g.prototype.once=function(e,r){return He(r),this.on(e,Rt(this,e,r)),this};g.prototype.prependOnceListener=function(e,r){return He(r),this.prependListener(e,Rt(this,e,r)),this};g.prototype.removeListener=function(e,r){var n,o,i,s,c;if(He(r),o=this._events,o===void 0)return this;if(n=o[e],n===void 0)return this;if(n===r||n.listener===r)--this._eventsCount===0?this._events=Object.create(null):(delete o[e],o.removeListener&&this.emit("removeListener",e,n.listener||r));else if(typeof n!="function"){for(i=-1,s=n.length-1;s>=0;s--)if(n[s]===r||n[s].listener===r){c=n[s].listener,i=s;break}if(i<0)return this;i===0?n.shift():Pr(n,i),n.length===1&&(o[e]=n[0]),o.removeListener!==void 0&&this.emit("removeListener",e,c||r)}return this};g.prototype.off=g.prototype.removeListener;g.prototype.removeAllListeners=function(e){var r,n,o;if(n=this._events,n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[e]),this;if(arguments.length===0){var i=Object.keys(n),s;for(o=0;o=0;o--)this.removeListener(e,r[o]);return this};function It(t,e,r){var n=t._events;if(n===void 0)return[];var o=n[e];return o===void 0?[]:typeof o=="function"?r?[o.listener||o]:[o]:r?Tr(o):Ut(o,o.length)}g.prototype.listeners=function(e){return It(this,e,!0)};g.prototype.rawListeners=function(e){return It(this,e,!1)};g.listenerCount=function(t,e){return typeof t.listenerCount=="function"?t.listenerCount(e):Mt.call(t,e)};g.prototype.listenerCount=Mt;function Mt(t){var e=this._events;if(e!==void 0){var r=e[t];if(typeof r=="function")return 1;if(r!==void 0)return r.length}return 0}g.prototype.eventNames=function(){return this._eventsCount>0?Je(this._events):[]};function Ut(t,e){for(var r=new Array(e),n=0;n{"use strict";var a={cipher:{},hash:{},keyexchange:{},mode:{},misc:{},codec:{},exception:{corrupt:function(t){this.toString=function(){return"CORRUPT: "+this.message},this.message=t},invalid:function(t){this.toString=function(){return"INVALID: "+this.message},this.message=t},bug:function(t){this.toString=function(){return"BUG: "+this.message},this.message=t},notReady:function(t){this.toString=function(){return"NOT READY: "+this.message},this.message=t}}};a.cipher.aes=function(t){this.w[0][0][0]||this.C();var e,r,n,o,i=this.w[0][4],s=this.w[1];e=t.length;var c=1;if(e!==4&&e!==6&&e!==8)throw new a.exception.invalid("invalid aes key size");for(this.b=[n=t.slice(0),o=[]],t=e;t<4*e+28;t++)r=n[t-1],(t%e===0||e===8&&t%e===4)&&(r=i[r>>>24]<<24^i[r>>16&255]<<16^i[r>>8&255]<<8^i[r&255],t%e===0&&(r=r<<8^r>>>24^c<<24,c=c<<1^283*(c>>7))),n[t]=n[t-e]^r;for(e=0;t;e++,t--)r=n[e&3?t:t-4],o[e]=4>=t||4>e?r:s[0][i[r>>>24]]^s[1][i[r>>16&255]]^s[2][i[r>>8&255]]^s[3][i[r&255]]};a.cipher.aes.prototype={encrypt:function(t){return Vt(this,t,0)},decrypt:function(t){return Vt(this,t,1)},w:[[[],[],[],[],[]],[[],[],[],[],[]]],C:function(){var t=this.w[0],e=this.w[1],r=t[4],n=e[4],o,i,s,c=[],u=[],f,h,l,m;for(o=0;256>o;o++)u[(c[o]=o<<1^283*(o>>7))^o]=o;for(i=s=0;!r[i];i^=f||1,s=u[s]||1)for(l=s^s<<1^s<<2^s<<3^s<<4,l=l>>8^l&255^99,r[i]=l,n[l]=i,h=c[o=c[f=c[i]]],m=16843009*h^65537*o^257*f^16843008*i,h=257*c[l]^16843008*l,o=0;4>o;o++)t[o][i]=h=h<<24^h>>>8,e[o][l]=m=m<<24^m>>>8;for(o=0;5>o;o++)t[o]=t[o].slice(0),e[o]=e[o].slice(0)}};function Vt(t,e,r){if(e.length!==4)throw new a.exception.invalid("invalid aes block size");var n=t.b[r],o=e[0]^n[0],i=e[r?3:1]^n[1],s=e[2]^n[2];e=e[r?1:3]^n[3];var c,u,f,h=n.length/4-2,l,m=4,p=[0,0,0,0];c=t.w[r],t=c[0];var A=c[1],M=c[2],F=c[3],Y=c[4];for(l=0;l>>24]^A[i>>16&255]^M[s>>8&255]^F[e&255]^n[m],u=t[i>>>24]^A[s>>16&255]^M[e>>8&255]^F[o&255]^n[m+1],f=t[s>>>24]^A[e>>16&255]^M[o>>8&255]^F[i&255]^n[m+2],e=t[e>>>24]^A[o>>16&255]^M[i>>8&255]^F[s&255]^n[m+3],m+=4,o=c,i=u,s=f;for(l=0;4>l;l++)p[r?3&-l:l]=Y[o>>>24]<<24^Y[i>>16&255]<<16^Y[s>>8&255]<<8^Y[e&255]^n[m++],c=o,o=i,i=s,s=e,e=c;return p}a.bitArray={bitSlice:function(t,e,r){return t=a.bitArray.Y(t.slice(e/32),32-(e&31)).slice(1),r===void 0?t:a.bitArray.clamp(t,r-e)},extract:function(t,e,r){var n=Math.floor(-e-r&31);return((e+r-1^e)&-32?t[e/32|0]<<32-n^t[e/32+1|0]>>>n:t[e/32|0]>>>n)&(1<>e-1,1)),t},partial:function(t,e,r){return t===32?e:(r?e|0:e<<32-t)+1099511627776*t},getPartial:function(t){return Math.round(t/1099511627776)||32},equal:function(t,e){if(a.bitArray.bitLength(t)!==a.bitArray.bitLength(e))return!1;var r=0,n;for(n=0;n>>e),r=t[o]<<32-e;return o=t.length?t[t.length-1]:0,t=a.bitArray.getPartial(o),n.push(a.bitArray.partial(e+t&31,32>>24|r>>>8&65280|(r&65280)<<8|r<<24;return t}};a.codec.utf8String={fromBits:function(t){var e="",r=a.bitArray.bitLength(t),n,o;for(n=0;n>>8>>>8>>>8),o<<=8;return decodeURIComponent(escape(e))},toBits:function(t){t=unescape(encodeURIComponent(t));var e=[],r,n=0;for(r=0;r>>o)>>>26),6>o?(s=t[r]<<6-o,o+=26,r++):(s<<=6,o-=6);for(;n.length&3&&!e;)n+="=";return n},toBits:function(t,e){t=t.replace(/\s|=/g,"");var r=[],n,o=0,i=a.codec.base64.S,s=0,c;for(e&&(i=i.substr(0,62)+"-_"),n=0;nc)throw new a.exception.invalid("this isn't base64!");26>>o),s=c<<32-o):(o+=6,s^=c<<32-o)}return o&56&&r.push(a.bitArray.partial(o&56,s,1)),r}};a.codec.base64url={fromBits:function(t){return a.codec.base64.fromBits(t,1,1)},toBits:function(t){return a.codec.base64.toBits(t,1)}};a.hash.sha256=function(t){this.b[0]||this.C(),t?(this.g=t.g.slice(0),this.f=t.f.slice(0),this.c=t.c):this.reset()};a.hash.sha256.hash=function(t){return new a.hash.sha256().update(t).finalize()};a.hash.sha256.prototype={blockSize:512,reset:function(){return this.g=this.o.slice(0),this.f=[],this.c=0,this},update:function(t){typeof t=="string"&&(t=a.codec.utf8String.toBits(t));var e,r=this.f=a.bitArray.concat(this.f,t);if(e=this.c,t=this.c=e+a.bitArray.bitLength(t),9007199254740991e;r++){for(o=!0,n=2;n*n<=r;n++)if(r%n===0){o=!1;break}o&&(8>e&&(this.o[e]=t(Math.pow(r,.5))),this.b[e]=t(Math.pow(r,1/3)),e++)}},l:function(t){var e,r,n,o=this.g,i=this.b,s=o[0],c=o[1],u=o[2],f=o[3],h=o[4],l=o[5],m=o[6],p=o[7];for(e=0;64>e;e++)16>e?r=t[e]:(r=t[e+1&15],n=t[e+14&15],r=t[e&15]=(r>>>7^r>>>18^r>>>3^r<<25^r<<14)+(n>>>17^n>>>19^n>>>10^n<<15^n<<13)+t[e&15]+t[e+9&15]|0),r=r+p+(h>>>6^h>>>11^h>>>25^h<<26^h<<21^h<<7)+(m^h&(l^m))+i[e],p=m,m=l,l=h,h=f+r|0,f=u,u=c,c=s,s=r+(c&u^f&(c^u))+(c>>>2^c>>>13^c>>>22^c<<30^c<<19^c<<10)|0;o[0]=o[0]+s|0,o[1]=o[1]+c|0,o[2]=o[2]+u|0,o[3]=o[3]+f|0,o[4]=o[4]+h|0,o[5]=o[5]+l|0,o[6]=o[6]+m|0,o[7]=o[7]+p|0}};a.hash.sha512=function(t){this.b[0]||this.C(),t?(this.g=t.g.slice(0),this.f=t.f.slice(0),this.c=t.c):this.reset()};a.hash.sha512.hash=function(t){return new a.hash.sha512().update(t).finalize()};a.hash.sha512.prototype={blockSize:1024,reset:function(){return this.g=this.o.slice(0),this.f=[],this.c=0,this},update:function(t){typeof t=="string"&&(t=a.codec.utf8String.toBits(t));var e,r=this.f=a.bitArray.concat(this.f,t);if(e=this.c,t=this.c=e+a.bitArray.bitLength(t),9007199254740991r;n++){for(i=!0,o=2;o*o<=n;o++)if(n%o===0){i=!1;break}i&&(8>r&&(this.o[2*r]=t(Math.pow(n,.5)),this.o[2*r+1]=e(Math.pow(n,.5))<<24|this.ia[r]),this.b[2*r]=t(Math.pow(n,1/3)),this.b[2*r+1]=e(Math.pow(n,1/3))<<24|this.ka[r],r++)}},l:function(t){var e,r,n=this.g,o=this.b,i=n[0],s=n[1],c=n[2],u=n[3],f=n[4],h=n[5],l=n[6],m=n[7],p=n[8],A=n[9],M=n[10],F=n[11],Y=n[12],Be=n[13],bt=n[14],je=n[15],C;if(typeof Uint32Array<"u"){C=Array(160);for(var L=0;32>L;L++)C[L]=t[L]}else C=t;var L=i,T=s,ve=c,oe=u,ge=f,ie=h,tt=l,we=m,z=p,R=A,We=M,Ee=F,Fe=Y,Ae=Be,rt=bt,xe=je;for(t=0;80>t;t++){if(16>t)e=C[2*t],r=C[2*t+1];else{r=C[2*(t-15)];var E=C[2*(t-15)+1];e=(E<<31|r>>>1)^(E<<24|r>>>8)^r>>>7;var J=(r<<31|E>>>1)^(r<<24|E>>>8)^(r<<25|E>>>7);r=C[2*(t-2)];var H=C[2*(t-2)+1],E=(H<<13|r>>>19)^(r<<3|H>>>29)^r>>>6,H=(r<<13|H>>>19)^(H<<3|r>>>29)^(r<<26|H>>>6),nt=C[2*(t-7)],ot=C[2*(t-16)],Oe=C[2*(t-16)+1];r=J+C[2*(t-7)+1],e=e+nt+(r>>>0>>0?1:0),r+=H,e+=E+(r>>>0>>0?1:0),r+=Oe,e+=ot+(r>>>0>>0?1:0)}C[2*t]=e|=0,C[2*t+1]=r|=0;var nt=z&We^~z&Fe,Lt=R&Ee^~R&Ae,H=L&ve^L&ge^ve&ge,wr=T&oe^T&ie^oe&ie,ot=(T<<4|L>>>28)^(L<<30|T>>>2)^(L<<25|T>>>7),Oe=(L<<4|T>>>28)^(T<<30|L>>>2)^(T<<25|L>>>7),Er=o[2*t],_t=o[2*t+1],E=xe+((z<<18|R>>>14)^(z<<14|R>>>18)^(R<<23|z>>>9)),J=rt+((R<<18|z>>>14)^(R<<14|z>>>18)^(z<<23|R>>>9))+(E>>>0>>0?1:0),E=E+Lt,J=J+(nt+(E>>>0>>0?1:0)),E=E+_t,J=J+(Er+(E>>>0<_t>>>0?1:0)),E=E+r|0,J=J+(e+(E>>>0>>0?1:0));r=Oe+wr,e=ot+H+(r>>>0>>0?1:0),rt=Fe,xe=Ae,Fe=We,Ae=Ee,We=z,Ee=R,R=we+E|0,z=tt+J+(R>>>0>>0?1:0)|0,tt=ge,we=ie,ge=ve,ie=oe,ve=L,oe=T,T=E+r|0,L=J+e+(T>>>0>>0?1:0)|0}s=n[1]=s+T|0,n[0]=i+L+(s>>>0>>0?1:0)|0,u=n[3]=u+oe|0,n[2]=c+ve+(u>>>0>>0?1:0)|0,h=n[5]=h+ie|0,n[4]=f+ge+(h>>>0>>0?1:0)|0,m=n[7]=m+we|0,n[6]=l+tt+(m>>>0>>0?1:0)|0,A=n[9]=A+R|0,n[8]=p+z+(A>>>0>>0?1:0)|0,F=n[11]=F+Ee|0,n[10]=M+We+(F>>>0>>0?1:0)|0,Be=n[13]=Be+Ae|0,n[12]=Y+Fe+(Be>>>0>>0?1:0)|0,je=n[15]=je+xe|0,n[14]=bt+rt+(je>>>0>>0?1:0)|0}};a.mode.ccm={name:"ccm",F:[],listenProgress:function(t){a.mode.ccm.F.push(t)},unListenProgress:function(t){t=a.mode.ccm.F.indexOf(t),-1u)throw new a.exception.invalid("ccm: iv must be at least 7 bytes");for(i=2;4>i&&f>>>8*i;i++);return i<15-u&&(i=15-u),r=c.clamp(r,8*(15-i)),e=a.mode.ccm.U(t,e,r,n,o,i),s=a.mode.ccm.V(t,s,r,e,o,i),c.concat(s.data,s.tag)},decrypt:function(t,e,r,n,o){o=o||64,n=n||[];var i=a.bitArray,s=i.bitLength(r)/8,f=i.bitLength(e),c=i.clamp(e,f-o),u=i.bitSlice(e,f-o),f=(f-o)/8;if(7>s)throw new a.exception.invalid("ccm: iv must be at least 7 bytes");for(e=2;4>e&&f>>>8*e;e++);if(e<15-s&&(e=15-s),r=i.clamp(r,8*(15-e)),c=a.mode.ccm.V(t,c,r,u,o,e),t=a.mode.ccm.U(t,c.data,r,n,o,e),!i.equal(c.tag,t))throw new a.exception.corrupt("ccm: tag doesn't match");return c.data},ma:function(t,e,r,n,o,i){var s=[],c=a.bitArray,u=c.P;if(n=[c.partial(8,(e.length?64:0)|n-2<<2|i-1)],n=c.concat(n,r),n[3]|=o,n=t.encrypt(n),e.length)for(r=c.bitLength(e)/8,65279>=r?s=[c.partial(16,r)]:4294967295>=r&&(s=c.concat([c.partial(16,65534)],[r])),s=c.concat(s,e),e=0;eo||16h&&(a.mode.ccm.da(s/u),h+=l),r[3]++,o=t.encrypt(r),e[s]^=o[0],e[s+1]^=o[1],e[s+2]^=o[2],e[s+3]^=o[3];return{tag:n,data:c.clamp(e,f)}}};a.misc.hmac=function(t,e){this.W=e=e||a.hash.sha256;var r=[[],[]],n,o=e.prototype.blockSize/32;for(this.B=[new e,new e],t.length>o&&(t=e.hash(t)),n=0;nn||0>r)throw new a.exception.invalid("invalid params to pbkdf2");typeof t=="string"&&(t=a.codec.utf8String.toBits(t)),typeof e=="string"&&(e=a.codec.utf8String.toBits(e)),o=o||a.misc.hmac,t=new o(t);var i,s,c,u,f=[],h=a.bitArray;for(u=1;32*f.length<(n||1);u++){for(o=i=t.encrypt(h.concat(e,[u])),s=1;ss;s++)o.push(4294967296*Math.random()|0);for(s=0;s=1<this.u&&(this.u=i),this.N++,this.b=a.hash.sha256.hash(this.b.concat(o)),this.K=new a.cipher.aes(this.b),n=0;4>n&&(this.m[n]=this.m[n]+1|0,!this.m[n]);n++);}for(n=0;n>>1;this.h[s].update([n,this.M++,2,e,i,t.length].concat(t))}break;case"string":e===void 0&&(e=t.length),this.h[s].update([n,this.M++,3,e,i,t.length]),this.h[s].update(t);break;default:u=1}if(u)throw new a.exception.bug("random: addEntropy only supports number, array of numbers or string");this.s[s]+=e,this.i+=e,c===this.A&&(this.isReady()!==this.A&&Kt("seeded",Math.max(this.u,this.i)),Kt("progress",this.getProgress()))},isReady:function(t){return t=this.R[t!==void 0?t:this.L],this.u&&this.u>=t?this.s[0]>this.$&&new Date().valueOf()>this.X?this.I|this.H:this.H:this.i>=t?this.I|this.A:this.A},getProgress:function(t){return t=this.R[t||this.L],this.u>=t||this.i>t?1:this.i/t},startCollectors:function(){if(!this.D){if(this.a={loadTimeCollector:De(this,this.la),mouseCollector:De(this,this.na),keyboardCollector:De(this,this.ja),accelerometerCollector:De(this,this.ca),touchCollector:De(this,this.pa)},window.addEventListener)window.addEventListener("load",this.a.loadTimeCollector,!1),window.addEventListener("mousemove",this.a.mouseCollector,!1),window.addEventListener("keypress",this.a.keyboardCollector,!1),window.addEventListener("devicemotion",this.a.accelerometerCollector,!1),window.addEventListener("touchmove",this.a.touchCollector,!1);else if(document.attachEvent)document.attachEvent("onload",this.a.loadTimeCollector),document.attachEvent("onmousemove",this.a.mouseCollector),document.attachEvent("keypress",this.a.keyboardCollector);else throw new a.exception.bug("can't attach event");this.D=!0}},stopCollectors:function(){this.D&&(window.removeEventListener?(window.removeEventListener("load",this.a.loadTimeCollector,!1),window.removeEventListener("mousemove",this.a.mouseCollector,!1),window.removeEventListener("keypress",this.a.keyboardCollector,!1),window.removeEventListener("devicemotion",this.a.accelerometerCollector,!1),window.removeEventListener("touchmove",this.a.touchCollector,!1)):document.detachEvent&&(document.detachEvent("onload",this.a.loadTimeCollector),document.detachEvent("onmousemove",this.a.mouseCollector),document.detachEvent("keypress",this.a.keyboardCollector)),this.D=!1)},addEventListener:function(t,e){this.J[t][this.ea++]=e},removeEventListener:function(t,e){var r,n,o=this.J[t],i=[];for(n in o)o.hasOwnProperty(n)&&o[n]===e&&i.push(n);for(r=0;re&&(t.m[e]=t.m[e]+1|0,!t.m[e]);e++);return t.K.encrypt(t.m)}function De(t,e){return function(){e.apply(t,arguments)}}a.random=new a.prng(6);e:try{if(Xe=typeof fe<"u"&&fe.exports){try{Ge=Dr("crypto")}catch{Ge=null}Xe=$e=Ge}if(Xe&&$e.randomBytes)Ce=$e.randomBytes(128),Ce=new Uint32Array(new Uint8Array(Ce).buffer),a.random.addEntropy(Ce,1024,"crypto['randomBytes']");else if(typeof window<"u"&&typeof Uint32Array<"u"){if(Se=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(Se);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(Se);else break e;a.random.addEntropy(Se,1024,"crypto['getRandomValues']")}}catch(t){typeof window<"u"&&window.console&&(console.log("There was an error collecting entropy from the browser:"),console.log(t))}var Ce,$e,Se,Xe,Ge;a.json={defaults:{v:1,iter:1e4,ks:128,ts:64,mode:"ccm",adata:"",cipher:"aes"},ha:function(t,e,r,n){r=r||{},n=n||{};var o=a.json,i=o.j({iv:a.random.randomWords(4,0)},o.defaults),s;if(o.j(i,r),r=i.adata,typeof i.salt=="string"&&(i.salt=a.codec.base64.toBits(i.salt)),typeof i.iv=="string"&&(i.iv=a.codec.base64.toBits(i.iv)),!a.mode[i.mode]||!a.cipher[i.cipher]||typeof t=="string"&&100>=i.iter||i.ts!==64&&i.ts!==96&&i.ts!==128||i.ks!==128&&i.ks!==192&&i.ks!==256||2>i.iv.length||4=e.iter||e.ts!==64&&e.ts!==96&&e.ts!==128||e.ks!==128&&e.ks!==192&&e.ks!==256||!e.iv||2>e.iv.length||4{"use strict";var hn=Object.prototype.hasOwnProperty,k="~";function ke(){}Object.create&&(ke.prototype=Object.create(null),new ke().__proto__||(k=!1));function ln(t,e,r){this.fn=t,this.context=e,this.once=r||!1}function cr(t,e,r,n,o){if(typeof r!="function")throw new TypeError("The listener must be a function");var i=new ln(r,n||t,o),s=k?k+e:e;return t._events[s]?t._events[s].fn?t._events[s]=[t._events[s],i]:t._events[s].push(i):(t._events[s]=i,t._eventsCount++),t}function qe(t,e){--t._eventsCount===0?t._events=new ke:delete t._events[e]}function D(){this._events=new ke,this._eventsCount=0}D.prototype.eventNames=function(){var e=[],r,n;if(this._eventsCount===0)return e;for(n in r=this._events)hn.call(r,n)&&e.push(k?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(r)):e};D.prototype.listeners=function(e){var r=k?k+e:e,n=this._events[r];if(!n)return[];if(n.fn)return[n.fn];for(var o=0,i=n.length,s=new Array(i);o{let n=e.isOk()?{type:"Ok",value:e.value}:{type:"Err",value:e.error},o=r.withStackTrace?new Error().stack:void 0;return{data:n,message:t,stack:o}};function ae(t,e,r,n){function o(i){return i instanceof r?i:new r(function(s){s(i)})}return new(r||(r=Promise))(function(i,s){function c(h){try{f(n.next(h))}catch(l){s(l)}}function u(h){try{f(n.throw(h))}catch(l){s(l)}}function f(h){h.done?i(h.value):o(h.value).then(c,u)}f((n=n.apply(t,e||[])).next())})}function jt(t){var e=typeof Symbol=="function"&&Symbol.iterator,r=e&&t[e],n=0;if(r)return r.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function $(t){return this instanceof $?(this.v=t,this):new $(t)}function Wt(t,e,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=r.apply(t,e||[]),o,i=[];return o=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),c("next"),c("throw"),c("return",s),o[Symbol.asyncIterator]=function(){return this},o;function s(p){return function(A){return Promise.resolve(A).then(p,l)}}function c(p,A){n[p]&&(o[p]=function(M){return new Promise(function(F,Y){i.push([p,M,F,Y])>1||u(p,M)})},A&&(o[p]=A(o[p])))}function u(p,A){try{f(n[p](A))}catch(M){m(i[0][3],M)}}function f(p){p.value instanceof $?Promise.resolve(p.value.v).then(h,l):m(i[0][2],p)}function h(p){u("next",p)}function l(p){u("throw",p)}function m(p,A){p(A),i.shift(),i.length&&u(i[0][0],i[0][1])}}function Ur(t){var e,r;return e={},n("next"),n("throw",function(o){throw o}),n("return"),e[Symbol.iterator]=function(){return this},e;function n(o,i){e[o]=t[o]?function(s){return(r=!r)?{value:$(t[o](s)),done:!1}:i?i(s):s}:i}}function Nr(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e=t[Symbol.asyncIterator],r;return e?e.call(t):(t=typeof jt=="function"?jt(t):t[Symbol.iterator](),r={},n("next"),n("throw"),n("return"),r[Symbol.asyncIterator]=function(){return this},r);function n(i){r[i]=t[i]&&function(s){return new Promise(function(c,u){s=t[i](s),o(c,u,s.done,s.value)})}}function o(i,s,c,u){Promise.resolve(u).then(function(f){i({value:f,done:c})},s)}}var _=class t{constructor(e){this._promise=e}static fromSafePromise(e){let r=e.then(n=>new N(n));return new t(r)}static fromPromise(e,r){let n=e.then(o=>new N(o)).catch(o=>new B(r(o)));return new t(n)}static fromThrowable(e,r){return(...n)=>new t(ae(this,void 0,void 0,function*(){try{return new N(yield e(...n))}catch(o){return new B(r?r(o):o)}}))}static combine(e){return Br(e)}static combineWithAllErrors(e){return jr(e)}map(e){return new t(this._promise.then(r=>ae(this,void 0,void 0,function*(){return r.isErr()?new B(r.error):new N(yield e(r.value))})))}andThrough(e){return new t(this._promise.then(r=>ae(this,void 0,void 0,function*(){if(r.isErr())return new B(r.error);let n=yield e(r.value);return n.isErr()?new B(n.error):new N(r.value)})))}andTee(e){return new t(this._promise.then(r=>ae(this,void 0,void 0,function*(){if(r.isErr())return new B(r.error);try{yield e(r.value)}catch{}return new N(r.value)})))}mapErr(e){return new t(this._promise.then(r=>ae(this,void 0,void 0,function*(){return r.isOk()?new N(r.value):new B(yield e(r.error))})))}andThen(e){return new t(this._promise.then(r=>{if(r.isErr())return new B(r.error);let n=e(r.value);return n instanceof t?n._promise:n}))}orElse(e){return new t(this._promise.then(r=>ae(this,void 0,void 0,function*(){return r.isErr()?e(r.error):new N(r.value)})))}match(e,r){return this._promise.then(n=>n.match(e,r))}unwrapOr(e){return this._promise.then(r=>r.unwrapOr(e))}safeUnwrap(){return Wt(this,arguments,function*(){return yield $(yield $(yield*Ur(Nr(yield $(this._promise.then(r=>r.safeUnwrap()))))))})}then(e,r){return this._promise.then(e,r)}[Symbol.asyncIterator](){return Wt(this,arguments,function*(){let r=yield $(this._promise);return r.isErr()&&(yield yield $(S(r.error))),yield $(r.value)})}},X=t=>new _(Promise.resolve(new N(t))),S=t=>new _(Promise.resolve(new B(t))),wn=_.fromPromise,En=_.fromSafePromise,An=_.fromThrowable,zt=t=>{let e=re([]);for(let r of t)if(r.isErr()){e=V(r.error);break}else e.map(n=>n.push(r.value));return e},Br=t=>_.fromSafePromise(Promise.all(t)).andThen(zt),Jt=t=>{let e=re([]);for(let r of t)r.isErr()&&e.isErr()?e.error.push(r.error):r.isErr()&&e.isOk()?e=V([r.error]):r.isOk()&&e.isOk()&&e.value.push(r.value);return e},jr=t=>_.fromSafePromise(Promise.all(t)).andThen(Jt),ft;(function(t){function e(o,i){return(...s)=>{try{let c=o(...s);return re(c)}catch(c){return V(i?i(c):c)}}}t.fromThrowable=e;function r(o){return zt(o)}t.combine=r;function n(o){return Jt(o)}t.combineWithAllErrors=n})(ft||(ft={}));var re=t=>new N(t);function V(t){return new B(t)}var N=class{constructor(e){this.value=e}isOk(){return!0}isErr(){return!this.isOk()}map(e){return re(e(this.value))}mapErr(e){return re(this.value)}andThen(e){return e(this.value)}andThrough(e){return e(this.value).map(r=>this.value)}andTee(e){try{e(this.value)}catch{}return re(this.value)}orElse(e){return re(this.value)}asyncAndThen(e){return e(this.value)}asyncAndThrough(e){return e(this.value).map(()=>this.value)}asyncMap(e){return _.fromSafePromise(e(this.value))}unwrapOr(e){return this.value}match(e,r){return e(this.value)}safeUnwrap(){let e=this.value;return function*(){return e}()}_unsafeUnwrap(e){return this.value}_unsafeUnwrapErr(e){throw Ft("Called `_unsafeUnwrapErr` on an Ok",this,e)}*[Symbol.iterator](){return this.value}},B=class{constructor(e){this.error=e}isOk(){return!1}isErr(){return!this.isOk()}map(e){return V(this.error)}mapErr(e){return V(e(this.error))}andThrough(e){return V(this.error)}andTee(e){return V(this.error)}andThen(e){return V(this.error)}orElse(e){return e(this.error)}asyncAndThen(e){return S(this.error)}asyncAndThrough(e){return S(this.error)}asyncMap(e){return S(this.error)}unwrapOr(e){return e}match(e,r){return r(this.error)}safeUnwrap(){let e=this.error;return function*(){throw yield V(e),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(e){throw Ft("Called `_unsafeUnwrap` on an Err",this,e)}_unsafeUnwrapErr(e){return this.error}*[Symbol.iterator](){let e=this;return yield e,e}},xn=ft.fromThrowable;var ee=class extends Error{constructor(r,n={}){let{cause:o,context:i}=n;super(r,{cause:o});U(this,"context");this.name=this.constructor.name,this.context=i}};var ne=t=>{if(t instanceof Error)return t;let e="[Unable to stringify the thrown value]";try{e=JSON.stringify(t)}catch{}return new Error(e)};var Wr=()=>typeof Deno<"u";var ce=t=>Wr()?new URL(`./worker/${t}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${t==="main"?`worker/${t}`:t}.js`));var v=new Xt.default,b,Ht=!1;self.onmessage=t=>{Jr(t),Ht||(Ht=!0,v.once("OPERATION_FAILED",()=>{b&&b.terminate()}))};var K=(t,e)=>(Object.assign(t,e),typeof WorkerGlobalScope<"u"&&self.postMessage({event:"FILE_UPDATED",lufiFile:t}),t),Gt=(t,e)=>{K(t,{uploadStatus:2}),self.postMessage({event:"OPERATION_FAILED",error:e})},Jr=(t,e)=>{let{action:r}=t.data;if(r===5||r===8)b.postMessage(t.data);else{switch(r){case 2:b=new Worker(ce("cancel"),{type:"module"}),b.postMessage(t.data);break;case 3:b=new Worker(ce("download"),{type:"module"}),b.postMessage(t.data);break;case 4:b=new Worker(ce("infos"),{type:"module"}),b.postMessage(t.data);break;case 7:b=b||new Worker(ce("remove"),{type:"module"}),b.postMessage(t.data);break;case 9:b=b||new Worker(ce("upload"),{type:"module"}),b.postMessage(t.data);break;default:console.error("Action not found")}b.onmessage=n=>{e&&e(n),self.postMessage(n.data)},b.onerror=n=>{console.error(`Error: ${n.message}`)}}},qt=()=>{v.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),v.once("OPERATION_FAILED",t=>{self.postMessage({event:"OPERATION_FAILED",error:t})})};var G=class extends ee{};var be=class extends G{constructor(){super(...arguments);U(this,"message","An error occured while trying to connect to WebSocket")}};var ue=class{constructor(e,r){if(!e||e.length!=64)throw Error("Charset must contain 64 characters");this._charset=e,this._noPadding=!!r,this._valid=new RegExp("^["+this._charset.replace("-","\\-")+"]+={0,2}$")}Encode(e){let r=e.byteLength;if(!r)return"";let n=new Uint8Array(e),o="";for(let i=0;i>2]+this._charset[(n[i]&3)<<4|n[i+1]>>4]+this._charset[(n[i+1]&15)<<2|n[i+2]>>6]+this._charset[n[i+2]&63];return r%3==2?(o=o.substring(0,o.length-1),this._noPadding||(o+="=")):r%3==1&&(o=o.substring(0,o.length-2),this._noPadding||(o+="==")),o}Decode(e){if(e=(e||"").replace(/[\s]/g,""),!e)return new ArrayBuffer(0);if(!this._valid.test(e))throw Error("Invalid base64 input sequence");let r=Math.floor(e.length*.75);e[e.length-2]=="="?r-=2:e[e.length-1]=="="&&r--;let n=new Uint8Array(r),o,i,s,c,u=0,f=0;for(;u>4,n[u++]=(i&15)<<4|s>>2,n[u++]=(s&3)<<6|c;return n.buffer}};var Hr=new ue("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");function Le(t){return Hr.Decode(t)}var $r=new ue("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",!0);function ht(t){return $r.Decode(t)}var tr=at(Zt());var Q=class extends ee{};var he=class extends Q{constructor(){super(...arguments);U(this,"message","Unable to decrypt the provided data")}};var rr=(t,e)=>{try{let r=typeof e=="string"?e:e.data;return X(Le(tr.default.decrypt(t,r)))}catch(r){return S(new he(void 0,{cause:ne(r)}))}};var nr=(t,e)=>Vr(t).andThen(r=>_.fromPromise(crypto.subtle.decrypt({name:"AES-GCM",iv:e.iv},r,Le(e.data)),n=>new he(void 0,{cause:ne(n)})));var Vr=t=>_.fromPromise(crypto.subtle.importKey("raw",ht(t),{name:"AES-GCM"},!1,["encrypt","decrypt"]),e=>new Q("Unable to import cryptography key",{cause:ne(e)}));var or=(t,e)=>e.algo===void 0||e.algo===0?rr(t,e):nr(t,e);var I={},ir=5,Zr=t=>(v.emit("UPLOAD_CANCELLED",t.success),X(void 0)),en=(t,e)=>{let r=t.split("XXMOJOXX"),n=r.shift();if(n!==void 0){let o=JSON.parse(n);if(un(o)){let i=r.shift();if(i){let s=JSON.parse(i);return s.iv&&(s.iv=new Uint8Array(Object.values(s.iv))),or(e.keys.client,s).andThen(c=>{let u=typeof c=="string"?new TextEncoder().encode(c).buffer:c;return o.part===0?(K(e,{chunksReady:e.chunksReady+1,delAtFirstView:o.del_at_first_view,delay:o.delay,name:o.name,size:o.size,totalChunks:o.total,type:o.type,zipped:o.zipped}),v.emit("DOWNLOAD_STARTED")):K(e,{chunksReady:e.chunksReady+1}),v.emit("CHUNK_DOWNLOADED",u,o.part),++o.part===o.total?on(e).andThen(()=>(v.emit("DOWNLOAD_COMPLETE"),v.emit("SOCKET_OPERATION_TERMINATED"),X(void 0))):X(void 0)})}else{let s=new G("Cannot retrieve metadata from data received by the server");return v.emit("OPERATION_FAILED",s),S(s)}}else{let i=new G(o.msg);return v.emit("OPERATION_FAILED",i),S(i)}}else{let o=new G("Cannot retrieve metadata from data received by the server");return v.emit("OPERATION_FAILED",o),S(o)}},tn=(t,e)=>{if(t.success)return t.j===0&&(K(e,{keys:{client:e.keys.client,server:t.short},actionToken:t.token,queueIndex:t.i}),v.emit("UPLOAD_STARTED")),K(e,{chunksReady:e.chunksReady+1,createdAt:t.created_at}),v.emit("CHUNK_UPLOADED"),e.chunksReady===e.totalChunks&&(K(e,{uploadStatus:1}),v.emit("UPLOAD_COMPLETE"),v.emit("SOCKET_OPERATION_TERMINATED")),X(void 0);{let r=new G(t.msg);return v.emit("OPERATION_FAILED",r),S(r)}},rn=(t,e)=>{let r=cn(t.data),n;if(r)if(!r.action&&r.msg){let o=new G(r.msg);return v.emit("OPERATION_FAILED",o),S(o)}else"delay"in r?n=tn(r,e):n=Zr(r);else n=en(t.data,e);return n},nn=t=>I!==void 0&&I[t]!==void 0&&I[t].readyState===WebSocket.CONNECTING,dt=t=>I!==void 0&&I[t]!==void 0&&I[t].readyState===WebSocket.OPEN;var pt=(t,e)=>{let r;return t.password?r={part:e,file_pwd:t.password}:r={part:e},mt(ar(t),t,JSON.stringify(r))},on=t=>{let e;return t.password?e={ended:!0,file_pwd:t.password}:e={ended:!0},mt(ar(t),t,JSON.stringify(e))};var mt=(t,e,r)=>dt(t)?(I[t].onmessage=n=>rn(n,e),I[t].send(r),X(void 0)):sr(t).andThen(()=>mt(t,e,r)),sr=(t,e=0)=>(!dt(t)&&!nn(t)&&(I[t]=new WebSocket(t),v.once("SOCKET_OPERATION_TERMINATED",()=>{I[t].close()}),v.once("OPERATION_FAILED",()=>{v.emit("SOCKET_OPERATION_TERMINATED")}),I[t].onopen=()=>{v.emit("SOCKET_OPENED")},I[t].onclose=()=>{},I[t].onerror=()=>++e<=ir?(console.error(`An error happened while trying to connect to WebSocket ${t}. Trying again. ${e} / ${ir}`),sr(t,e)):(v.emit("SOCKET_ONERROR"),S(new be(`Unable to connect to WebSocket ${t}.`)))),sn(t).andThen(()=>X(t)).orElse(r=>S(r))),sn=t=>_.fromPromise(new Promise((e,r)=>{dt(t)?e(void 0):(v.once("SOCKET_OPENED",()=>{e(void 0)}),v.on("SOCKET_ONERROR",()=>{r(new be)}))}),e=>ne(e));var an=(t,e)=>{let r=new URL(t);return r.protocol=r.protocol==="http:"?"ws:":"wss:",r.pathname+=e,new URL(r.origin+r.pathname)},ar=t=>an(new URL(t.serverUrl),"download"+`/${t.keys.server}`).toString();var cn=t=>{try{let e=JSON.parse(t);if(e&&typeof e=="object")return e}catch{}return!1},un=t=>typeof t=="object"&&t!==null&&!("msg"in t);var vt=at(ur(),1);var Pe=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},gt=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},fr=t=>globalThis.DOMException===void 0?new gt(t):new DOMException(t),hr=t=>{let e=t.reason===void 0?fr("This operation was aborted."):t.reason;return e instanceof Error?e:fr(e)};function wt(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout}}=e,s,u=new Promise((f,h)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(e.signal){let{signal:m}=e;m.aborted&&h(hr(m));let p=()=>{h(hr(m))};m.addEventListener("abort",p,{once:!0}),t.finally(()=>{m.removeEventListener("abort",p)})}if(r===Number.POSITIVE_INFINITY){t.then(f,h);return}let l=new Pe;s=i.setTimeout.call(void 0,()=>{if(n){try{f(n())}catch(m){h(m)}return}typeof t.cancel=="function"&&t.cancel(),o===!1?f():o instanceof Error?h(o):(l.message=o!=null?o:`Promise timed out after ${r} milliseconds`,h(l))},r),(async()=>{try{f(await t)}catch(m){h(m)}})()}).finally(()=>{u.clear()});return u.clear=()=>{i.clearTimeout.call(void 0,s),s=void 0},u}function Et(t,e,r){let n=0,o=t.length;for(;o>0;){let i=Math.trunc(o/2),s=n+i;r(t[s],e)<=0?(n=++s,o-=i+1):o=i}return n}var q,Te=class{constructor(){x(this,q,[])}enqueue(e,r){r={priority:0,...r};let n={priority:r.priority,run:e};if(this.size&&d(this,q)[this.size-1].priority>=r.priority){d(this,q).push(n);return}let o=Et(d(this,q),n,(i,s)=>s.priority-i.priority);d(this,q).splice(o,0,n)}dequeue(){let e=d(this,q).shift();return e==null?void 0:e.run}filter(e){return d(this,q).filter(r=>r.priority===e.priority).map(r=>r.run)}get size(){return d(this,q).length}};q=new WeakMap;var le,de,te,Ie,pe,Me,j,me,P,Ue,W,ye,Z,Ne,y,lr,dr,pr,mr,yr,Ye,At,xt,Ve,vr,Ke,Re=class extends vt.default{constructor(r){var n,o,i,s;super();x(this,y);x(this,le);x(this,de);x(this,te,0);x(this,Ie);x(this,pe);x(this,Me,0);x(this,j);x(this,me);x(this,P);x(this,Ue);x(this,W,0);x(this,ye);x(this,Z);x(this,Ne);U(this,"timeout");if(r={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:Te,...r},!(typeof r.intervalCap=="number"&&r.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${(o=(n=r.intervalCap)==null?void 0:n.toString())!=null?o:""}\` (${typeof r.intervalCap})`);if(r.interval===void 0||!(Number.isFinite(r.interval)&&r.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${(s=(i=r.interval)==null?void 0:i.toString())!=null?s:""}\` (${typeof r.interval})`);w(this,le,r.carryoverConcurrencyCount),w(this,de,r.intervalCap===Number.POSITIVE_INFINITY||r.interval===0),w(this,Ie,r.intervalCap),w(this,pe,r.interval),w(this,P,new r.queueClass),w(this,Ue,r.queueClass),this.concurrency=r.concurrency,this.timeout=r.timeout,w(this,Ne,r.throwOnTimeout===!0),w(this,Z,r.autoStart===!1)}get concurrency(){return d(this,ye)}set concurrency(r){if(!(typeof r=="number"&&r>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${r}\` (${typeof r})`);w(this,ye,r),O(this,y,Ve).call(this)}async add(r,n={}){return n={timeout:this.timeout,throwOnTimeout:d(this,Ne),...n},new Promise((o,i)=>{d(this,P).enqueue(async()=>{var s;ze(this,W)._++,ze(this,te)._++;try{(s=n.signal)==null||s.throwIfAborted();let c=r({signal:n.signal});n.timeout&&(c=wt(Promise.resolve(c),{milliseconds:n.timeout})),n.signal&&(c=Promise.race([c,O(this,y,vr).call(this,n.signal)]));let u=await c;o(u),this.emit("completed",u)}catch(c){if(c instanceof Pe&&!n.throwOnTimeout){o();return}i(c),this.emit("error",c)}finally{O(this,y,pr).call(this)}},n),this.emit("add"),O(this,y,Ye).call(this)})}async addAll(r,n){return Promise.all(r.map(async o=>this.add(o,n)))}start(){return d(this,Z)?(w(this,Z,!1),O(this,y,Ve).call(this),this):this}pause(){w(this,Z,!0)}clear(){w(this,P,new(d(this,Ue)))}async onEmpty(){d(this,P).size!==0&&await O(this,y,Ke).call(this,"empty")}async onSizeLessThan(r){d(this,P).sized(this,P).size{O(this,y,mr).call(this)},n)),!0}return!1},Ye=function(){if(d(this,P).size===0)return d(this,j)&&clearInterval(d(this,j)),w(this,j,void 0),this.emit("empty"),d(this,W)===0&&this.emit("idle"),!1;if(!d(this,Z)){let r=!d(this,y,yr);if(d(this,y,lr)&&d(this,y,dr)){let n=d(this,P).dequeue();return n?(this.emit("active"),n(),r&&O(this,y,At).call(this),!0):!1}}return!1},At=function(){d(this,de)||d(this,j)!==void 0||(w(this,j,setInterval(()=>{O(this,y,xt).call(this)},d(this,pe))),w(this,Me,Date.now()+d(this,pe)))},xt=function(){d(this,te)===0&&d(this,W)===0&&d(this,j)&&(clearInterval(d(this,j)),w(this,j,void 0)),w(this,te,d(this,le)?d(this,W):0),O(this,y,Ve).call(this)},Ve=function(){for(;O(this,y,Ye).call(this););},vr=async function(r){return new Promise((n,o)=>{r.addEventListener("abort",()=>{o(r.reason)},{once:!0})})},Ke=async function(r,n){return new Promise(o=>{let i=()=>{n&&!n()||(this.off(r,i),o())};this.on(r,i)})};var Ot=navigator.hardwareConcurrency||4,Qe=new Re({concurrency:Ot,autoStart:!1}),Ze=0,gr=!1,et=!1;self.onmessage=t=>{gr||(qt(),gr=!0);let e=t.data;switch(e.action){case 5:et=!0,self.postMessage({event:"JOB_PAUSED"});break;case 8:et=!1,self.postMessage({event:"JOB_RESUMED"});break;default:v.once("DOWNLOAD_COMPLETE",()=>{self.postMessage({event:"DOWNLOAD_COMPLETE"})}),v.on("FILE_UPDATED",K),v.on("CHUNK_DOWNLOADED",(r,n)=>{self.postMessage({event:"CHUNK_DOWNLOADED",chunk:{buffer:r,index:n}})}),dn(e).mapErr(r=>{Gt(e.args.lufiFile,r)})}};var dn=t=>{let{lufiFile:e}=t.args;return v.on("CHUNK_DOWNLOADED",()=>{Ze--,!et&&Ze{for(let r=1;r{await pt(e,r),Ze++,(et||Ze===Ot)&&Qe.pause()});Qe.start()}),pt(e,0)};export{Ot as QUEUE_CONCURRENCY_LIMIT,Ze as itemsInQueue,Qe as queue}; +var Ar=Object.create;var it=Object.defineProperty;var Or=Object.getOwnPropertyDescriptor;var xr=Object.getOwnPropertyNames;var Lr=Object.getPrototypeOf,br=Object.prototype.hasOwnProperty;var Dt=t=>{throw TypeError(t)};var _r=(t,e,r)=>e in t?it(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var Dr=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var st=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var Cr=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of xr(e))!br.call(t,o)&&o!==r&&it(t,o,{get:()=>e[o],enumerable:!(n=Or(e,o))||n.enumerable});return t};var at=(t,e,r)=>(r=t!=null?Ar(Lr(t)):{},Cr(e||!t||!t.__esModule?it(r,"default",{value:t,enumerable:!0}):r,t));var U=(t,e,r)=>_r(t,typeof e!="symbol"?e+"":e,r),ct=(t,e,r)=>e.has(t)||Dt("Cannot "+r);var d=(t,e,r)=>(ct(t,e,"read from private field"),r?r.call(t):e.get(t)),O=(t,e,r)=>e.has(t)?Dt("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),w=(t,e,r,n)=>(ct(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),x=(t,e,r)=>(ct(t,e,"access private method"),r);var ze=(t,e,r,n)=>({set _(o){w(t,e,o,r)},get _(){return d(t,e,n)}});var Bt=st((yn,ut)=>{"use strict";var se=typeof Reflect=="object"?Reflect:null,Ct=se&&typeof se.apply=="function"?se.apply:function(e,r,n){return Function.prototype.apply.call(e,r,n)},Je;se&&typeof se.ownKeys=="function"?Je=se.ownKeys:Object.getOwnPropertySymbols?Je=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:Je=function(e){return Object.getOwnPropertyNames(e)};function Sr(t){console&&console.warn&&console.warn(t)}var kt=Number.isNaN||function(e){return e!==e};function g(){g.init.call(this)}ut.exports=g;ut.exports.once=Rr;g.EventEmitter=g;g.prototype._events=void 0;g.prototype._eventsCount=0;g.prototype._maxListeners=void 0;var St=10;function He(t){if(typeof t!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t)}Object.defineProperty(g,"defaultMaxListeners",{enumerable:!0,get:function(){return St},set:function(t){if(typeof t!="number"||t<0||kt(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");St=t}});g.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0};g.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||kt(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this};function Pt(t){return t._maxListeners===void 0?g.defaultMaxListeners:t._maxListeners}g.prototype.getMaxListeners=function(){return Pt(this)};g.prototype.emit=function(e){for(var r=[],n=1;n0&&(s=r[0]),s instanceof Error)throw s;var c=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw c.context=s,c}var u=i[e];if(u===void 0)return!1;if(typeof u=="function")Ct(u,this,r);else for(var f=u.length,h=Ut(u,f),n=0;n0&&s.length>o&&!s.warned){s.warned=!0;var c=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");c.name="MaxListenersExceededWarning",c.emitter=t,c.type=e,c.count=s.length,Sr(c)}return t}g.prototype.addListener=function(e,r){return Tt(this,e,r,!1)};g.prototype.on=g.prototype.addListener;g.prototype.prependListener=function(e,r){return Tt(this,e,r,!0)};function kr(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function Rt(t,e,r){var n={fired:!1,wrapFn:void 0,target:t,type:e,listener:r},o=kr.bind(n);return o.listener=r,n.wrapFn=o,o}g.prototype.once=function(e,r){return He(r),this.on(e,Rt(this,e,r)),this};g.prototype.prependOnceListener=function(e,r){return He(r),this.prependListener(e,Rt(this,e,r)),this};g.prototype.removeListener=function(e,r){var n,o,i,s,c;if(He(r),o=this._events,o===void 0)return this;if(n=o[e],n===void 0)return this;if(n===r||n.listener===r)--this._eventsCount===0?this._events=Object.create(null):(delete o[e],o.removeListener&&this.emit("removeListener",e,n.listener||r));else if(typeof n!="function"){for(i=-1,s=n.length-1;s>=0;s--)if(n[s]===r||n[s].listener===r){c=n[s].listener,i=s;break}if(i<0)return this;i===0?n.shift():Pr(n,i),n.length===1&&(o[e]=n[0]),o.removeListener!==void 0&&this.emit("removeListener",e,c||r)}return this};g.prototype.off=g.prototype.removeListener;g.prototype.removeAllListeners=function(e){var r,n,o;if(n=this._events,n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[e]),this;if(arguments.length===0){var i=Object.keys(n),s;for(o=0;o=0;o--)this.removeListener(e,r[o]);return this};function It(t,e,r){var n=t._events;if(n===void 0)return[];var o=n[e];return o===void 0?[]:typeof o=="function"?r?[o.listener||o]:[o]:r?Tr(o):Ut(o,o.length)}g.prototype.listeners=function(e){return It(this,e,!0)};g.prototype.rawListeners=function(e){return It(this,e,!1)};g.listenerCount=function(t,e){return typeof t.listenerCount=="function"?t.listenerCount(e):Mt.call(t,e)};g.prototype.listenerCount=Mt;function Mt(t){var e=this._events;if(e!==void 0){var r=e[t];if(typeof r=="function")return 1;if(r!==void 0)return r.length}return 0}g.prototype.eventNames=function(){return this._eventsCount>0?Je(this._events):[]};function Ut(t,e){for(var r=new Array(e),n=0;n{"use strict";var a={cipher:{},hash:{},keyexchange:{},mode:{},misc:{},codec:{},exception:{corrupt:function(t){this.toString=function(){return"CORRUPT: "+this.message},this.message=t},invalid:function(t){this.toString=function(){return"INVALID: "+this.message},this.message=t},bug:function(t){this.toString=function(){return"BUG: "+this.message},this.message=t},notReady:function(t){this.toString=function(){return"NOT READY: "+this.message},this.message=t}}};a.cipher.aes=function(t){this.w[0][0][0]||this.C();var e,r,n,o,i=this.w[0][4],s=this.w[1];e=t.length;var c=1;if(e!==4&&e!==6&&e!==8)throw new a.exception.invalid("invalid aes key size");for(this.b=[n=t.slice(0),o=[]],t=e;t<4*e+28;t++)r=n[t-1],(t%e===0||e===8&&t%e===4)&&(r=i[r>>>24]<<24^i[r>>16&255]<<16^i[r>>8&255]<<8^i[r&255],t%e===0&&(r=r<<8^r>>>24^c<<24,c=c<<1^283*(c>>7))),n[t]=n[t-e]^r;for(e=0;t;e++,t--)r=n[e&3?t:t-4],o[e]=4>=t||4>e?r:s[0][i[r>>>24]]^s[1][i[r>>16&255]]^s[2][i[r>>8&255]]^s[3][i[r&255]]};a.cipher.aes.prototype={encrypt:function(t){return Vt(this,t,0)},decrypt:function(t){return Vt(this,t,1)},w:[[[],[],[],[],[]],[[],[],[],[],[]]],C:function(){var t=this.w[0],e=this.w[1],r=t[4],n=e[4],o,i,s,c=[],u=[],f,h,l,m;for(o=0;256>o;o++)u[(c[o]=o<<1^283*(o>>7))^o]=o;for(i=s=0;!r[i];i^=f||1,s=u[s]||1)for(l=s^s<<1^s<<2^s<<3^s<<4,l=l>>8^l&255^99,r[i]=l,n[l]=i,h=c[o=c[f=c[i]]],m=16843009*h^65537*o^257*f^16843008*i,h=257*c[l]^16843008*l,o=0;4>o;o++)t[o][i]=h=h<<24^h>>>8,e[o][l]=m=m<<24^m>>>8;for(o=0;5>o;o++)t[o]=t[o].slice(0),e[o]=e[o].slice(0)}};function Vt(t,e,r){if(e.length!==4)throw new a.exception.invalid("invalid aes block size");var n=t.b[r],o=e[0]^n[0],i=e[r?3:1]^n[1],s=e[2]^n[2];e=e[r?1:3]^n[3];var c,u,f,h=n.length/4-2,l,m=4,p=[0,0,0,0];c=t.w[r],t=c[0];var A=c[1],M=c[2],F=c[3],Y=c[4];for(l=0;l>>24]^A[i>>16&255]^M[s>>8&255]^F[e&255]^n[m],u=t[i>>>24]^A[s>>16&255]^M[e>>8&255]^F[o&255]^n[m+1],f=t[s>>>24]^A[e>>16&255]^M[o>>8&255]^F[i&255]^n[m+2],e=t[e>>>24]^A[o>>16&255]^M[i>>8&255]^F[s&255]^n[m+3],m+=4,o=c,i=u,s=f;for(l=0;4>l;l++)p[r?3&-l:l]=Y[o>>>24]<<24^Y[i>>16&255]<<16^Y[s>>8&255]<<8^Y[e&255]^n[m++],c=o,o=i,i=s,s=e,e=c;return p}a.bitArray={bitSlice:function(t,e,r){return t=a.bitArray.Y(t.slice(e/32),32-(e&31)).slice(1),r===void 0?t:a.bitArray.clamp(t,r-e)},extract:function(t,e,r){var n=Math.floor(-e-r&31);return((e+r-1^e)&-32?t[e/32|0]<<32-n^t[e/32+1|0]>>>n:t[e/32|0]>>>n)&(1<>e-1,1)),t},partial:function(t,e,r){return t===32?e:(r?e|0:e<<32-t)+1099511627776*t},getPartial:function(t){return Math.round(t/1099511627776)||32},equal:function(t,e){if(a.bitArray.bitLength(t)!==a.bitArray.bitLength(e))return!1;var r=0,n;for(n=0;n>>e),r=t[o]<<32-e;return o=t.length?t[t.length-1]:0,t=a.bitArray.getPartial(o),n.push(a.bitArray.partial(e+t&31,32>>24|r>>>8&65280|(r&65280)<<8|r<<24;return t}};a.codec.utf8String={fromBits:function(t){var e="",r=a.bitArray.bitLength(t),n,o;for(n=0;n>>8>>>8>>>8),o<<=8;return decodeURIComponent(escape(e))},toBits:function(t){t=unescape(encodeURIComponent(t));var e=[],r,n=0;for(r=0;r>>o)>>>26),6>o?(s=t[r]<<6-o,o+=26,r++):(s<<=6,o-=6);for(;n.length&3&&!e;)n+="=";return n},toBits:function(t,e){t=t.replace(/\s|=/g,"");var r=[],n,o=0,i=a.codec.base64.S,s=0,c;for(e&&(i=i.substr(0,62)+"-_"),n=0;nc)throw new a.exception.invalid("this isn't base64!");26>>o),s=c<<32-o):(o+=6,s^=c<<32-o)}return o&56&&r.push(a.bitArray.partial(o&56,s,1)),r}};a.codec.base64url={fromBits:function(t){return a.codec.base64.fromBits(t,1,1)},toBits:function(t){return a.codec.base64.toBits(t,1)}};a.hash.sha256=function(t){this.b[0]||this.C(),t?(this.g=t.g.slice(0),this.f=t.f.slice(0),this.c=t.c):this.reset()};a.hash.sha256.hash=function(t){return new a.hash.sha256().update(t).finalize()};a.hash.sha256.prototype={blockSize:512,reset:function(){return this.g=this.o.slice(0),this.f=[],this.c=0,this},update:function(t){typeof t=="string"&&(t=a.codec.utf8String.toBits(t));var e,r=this.f=a.bitArray.concat(this.f,t);if(e=this.c,t=this.c=e+a.bitArray.bitLength(t),9007199254740991e;r++){for(o=!0,n=2;n*n<=r;n++)if(r%n===0){o=!1;break}o&&(8>e&&(this.o[e]=t(Math.pow(r,.5))),this.b[e]=t(Math.pow(r,1/3)),e++)}},l:function(t){var e,r,n,o=this.g,i=this.b,s=o[0],c=o[1],u=o[2],f=o[3],h=o[4],l=o[5],m=o[6],p=o[7];for(e=0;64>e;e++)16>e?r=t[e]:(r=t[e+1&15],n=t[e+14&15],r=t[e&15]=(r>>>7^r>>>18^r>>>3^r<<25^r<<14)+(n>>>17^n>>>19^n>>>10^n<<15^n<<13)+t[e&15]+t[e+9&15]|0),r=r+p+(h>>>6^h>>>11^h>>>25^h<<26^h<<21^h<<7)+(m^h&(l^m))+i[e],p=m,m=l,l=h,h=f+r|0,f=u,u=c,c=s,s=r+(c&u^f&(c^u))+(c>>>2^c>>>13^c>>>22^c<<30^c<<19^c<<10)|0;o[0]=o[0]+s|0,o[1]=o[1]+c|0,o[2]=o[2]+u|0,o[3]=o[3]+f|0,o[4]=o[4]+h|0,o[5]=o[5]+l|0,o[6]=o[6]+m|0,o[7]=o[7]+p|0}};a.hash.sha512=function(t){this.b[0]||this.C(),t?(this.g=t.g.slice(0),this.f=t.f.slice(0),this.c=t.c):this.reset()};a.hash.sha512.hash=function(t){return new a.hash.sha512().update(t).finalize()};a.hash.sha512.prototype={blockSize:1024,reset:function(){return this.g=this.o.slice(0),this.f=[],this.c=0,this},update:function(t){typeof t=="string"&&(t=a.codec.utf8String.toBits(t));var e,r=this.f=a.bitArray.concat(this.f,t);if(e=this.c,t=this.c=e+a.bitArray.bitLength(t),9007199254740991r;n++){for(i=!0,o=2;o*o<=n;o++)if(n%o===0){i=!1;break}i&&(8>r&&(this.o[2*r]=t(Math.pow(n,.5)),this.o[2*r+1]=e(Math.pow(n,.5))<<24|this.ia[r]),this.b[2*r]=t(Math.pow(n,1/3)),this.b[2*r+1]=e(Math.pow(n,1/3))<<24|this.ka[r],r++)}},l:function(t){var e,r,n=this.g,o=this.b,i=n[0],s=n[1],c=n[2],u=n[3],f=n[4],h=n[5],l=n[6],m=n[7],p=n[8],A=n[9],M=n[10],F=n[11],Y=n[12],Be=n[13],Lt=n[14],je=n[15],C;if(typeof Uint32Array<"u"){C=Array(160);for(var b=0;32>b;b++)C[b]=t[b]}else C=t;var b=i,T=s,ve=c,oe=u,ge=f,ie=h,tt=l,we=m,z=p,R=A,We=M,Ee=F,Fe=Y,Ae=Be,rt=Lt,Oe=je;for(t=0;80>t;t++){if(16>t)e=C[2*t],r=C[2*t+1];else{r=C[2*(t-15)];var E=C[2*(t-15)+1];e=(E<<31|r>>>1)^(E<<24|r>>>8)^r>>>7;var J=(r<<31|E>>>1)^(r<<24|E>>>8)^(r<<25|E>>>7);r=C[2*(t-2)];var H=C[2*(t-2)+1],E=(H<<13|r>>>19)^(r<<3|H>>>29)^r>>>6,H=(r<<13|H>>>19)^(H<<3|r>>>29)^(r<<26|H>>>6),nt=C[2*(t-7)],ot=C[2*(t-16)],xe=C[2*(t-16)+1];r=J+C[2*(t-7)+1],e=e+nt+(r>>>0>>0?1:0),r+=H,e+=E+(r>>>0>>0?1:0),r+=xe,e+=ot+(r>>>0>>0?1:0)}C[2*t]=e|=0,C[2*t+1]=r|=0;var nt=z&We^~z&Fe,bt=R&Ee^~R&Ae,H=b&ve^b&ge^ve&ge,wr=T&oe^T&ie^oe&ie,ot=(T<<4|b>>>28)^(b<<30|T>>>2)^(b<<25|T>>>7),xe=(b<<4|T>>>28)^(T<<30|b>>>2)^(T<<25|b>>>7),Er=o[2*t],_t=o[2*t+1],E=Oe+((z<<18|R>>>14)^(z<<14|R>>>18)^(R<<23|z>>>9)),J=rt+((R<<18|z>>>14)^(R<<14|z>>>18)^(z<<23|R>>>9))+(E>>>0>>0?1:0),E=E+bt,J=J+(nt+(E>>>0>>0?1:0)),E=E+_t,J=J+(Er+(E>>>0<_t>>>0?1:0)),E=E+r|0,J=J+(e+(E>>>0>>0?1:0));r=xe+wr,e=ot+H+(r>>>0>>0?1:0),rt=Fe,Oe=Ae,Fe=We,Ae=Ee,We=z,Ee=R,R=we+E|0,z=tt+J+(R>>>0>>0?1:0)|0,tt=ge,we=ie,ge=ve,ie=oe,ve=b,oe=T,T=E+r|0,b=J+e+(T>>>0>>0?1:0)|0}s=n[1]=s+T|0,n[0]=i+b+(s>>>0>>0?1:0)|0,u=n[3]=u+oe|0,n[2]=c+ve+(u>>>0>>0?1:0)|0,h=n[5]=h+ie|0,n[4]=f+ge+(h>>>0>>0?1:0)|0,m=n[7]=m+we|0,n[6]=l+tt+(m>>>0>>0?1:0)|0,A=n[9]=A+R|0,n[8]=p+z+(A>>>0>>0?1:0)|0,F=n[11]=F+Ee|0,n[10]=M+We+(F>>>0>>0?1:0)|0,Be=n[13]=Be+Ae|0,n[12]=Y+Fe+(Be>>>0>>0?1:0)|0,je=n[15]=je+Oe|0,n[14]=Lt+rt+(je>>>0>>0?1:0)|0}};a.mode.ccm={name:"ccm",F:[],listenProgress:function(t){a.mode.ccm.F.push(t)},unListenProgress:function(t){t=a.mode.ccm.F.indexOf(t),-1u)throw new a.exception.invalid("ccm: iv must be at least 7 bytes");for(i=2;4>i&&f>>>8*i;i++);return i<15-u&&(i=15-u),r=c.clamp(r,8*(15-i)),e=a.mode.ccm.U(t,e,r,n,o,i),s=a.mode.ccm.V(t,s,r,e,o,i),c.concat(s.data,s.tag)},decrypt:function(t,e,r,n,o){o=o||64,n=n||[];var i=a.bitArray,s=i.bitLength(r)/8,f=i.bitLength(e),c=i.clamp(e,f-o),u=i.bitSlice(e,f-o),f=(f-o)/8;if(7>s)throw new a.exception.invalid("ccm: iv must be at least 7 bytes");for(e=2;4>e&&f>>>8*e;e++);if(e<15-s&&(e=15-s),r=i.clamp(r,8*(15-e)),c=a.mode.ccm.V(t,c,r,u,o,e),t=a.mode.ccm.U(t,c.data,r,n,o,e),!i.equal(c.tag,t))throw new a.exception.corrupt("ccm: tag doesn't match");return c.data},ma:function(t,e,r,n,o,i){var s=[],c=a.bitArray,u=c.P;if(n=[c.partial(8,(e.length?64:0)|n-2<<2|i-1)],n=c.concat(n,r),n[3]|=o,n=t.encrypt(n),e.length)for(r=c.bitLength(e)/8,65279>=r?s=[c.partial(16,r)]:4294967295>=r&&(s=c.concat([c.partial(16,65534)],[r])),s=c.concat(s,e),e=0;eo||16h&&(a.mode.ccm.da(s/u),h+=l),r[3]++,o=t.encrypt(r),e[s]^=o[0],e[s+1]^=o[1],e[s+2]^=o[2],e[s+3]^=o[3];return{tag:n,data:c.clamp(e,f)}}};a.misc.hmac=function(t,e){this.W=e=e||a.hash.sha256;var r=[[],[]],n,o=e.prototype.blockSize/32;for(this.B=[new e,new e],t.length>o&&(t=e.hash(t)),n=0;nn||0>r)throw new a.exception.invalid("invalid params to pbkdf2");typeof t=="string"&&(t=a.codec.utf8String.toBits(t)),typeof e=="string"&&(e=a.codec.utf8String.toBits(e)),o=o||a.misc.hmac,t=new o(t);var i,s,c,u,f=[],h=a.bitArray;for(u=1;32*f.length<(n||1);u++){for(o=i=t.encrypt(h.concat(e,[u])),s=1;ss;s++)o.push(4294967296*Math.random()|0);for(s=0;s=1<this.u&&(this.u=i),this.N++,this.b=a.hash.sha256.hash(this.b.concat(o)),this.K=new a.cipher.aes(this.b),n=0;4>n&&(this.m[n]=this.m[n]+1|0,!this.m[n]);n++);}for(n=0;n>>1;this.h[s].update([n,this.M++,2,e,i,t.length].concat(t))}break;case"string":e===void 0&&(e=t.length),this.h[s].update([n,this.M++,3,e,i,t.length]),this.h[s].update(t);break;default:u=1}if(u)throw new a.exception.bug("random: addEntropy only supports number, array of numbers or string");this.s[s]+=e,this.i+=e,c===this.A&&(this.isReady()!==this.A&&Kt("seeded",Math.max(this.u,this.i)),Kt("progress",this.getProgress()))},isReady:function(t){return t=this.R[t!==void 0?t:this.L],this.u&&this.u>=t?this.s[0]>this.$&&new Date().valueOf()>this.X?this.I|this.H:this.H:this.i>=t?this.I|this.A:this.A},getProgress:function(t){return t=this.R[t||this.L],this.u>=t||this.i>t?1:this.i/t},startCollectors:function(){if(!this.D){if(this.a={loadTimeCollector:De(this,this.la),mouseCollector:De(this,this.na),keyboardCollector:De(this,this.ja),accelerometerCollector:De(this,this.ca),touchCollector:De(this,this.pa)},window.addEventListener)window.addEventListener("load",this.a.loadTimeCollector,!1),window.addEventListener("mousemove",this.a.mouseCollector,!1),window.addEventListener("keypress",this.a.keyboardCollector,!1),window.addEventListener("devicemotion",this.a.accelerometerCollector,!1),window.addEventListener("touchmove",this.a.touchCollector,!1);else if(document.attachEvent)document.attachEvent("onload",this.a.loadTimeCollector),document.attachEvent("onmousemove",this.a.mouseCollector),document.attachEvent("keypress",this.a.keyboardCollector);else throw new a.exception.bug("can't attach event");this.D=!0}},stopCollectors:function(){this.D&&(window.removeEventListener?(window.removeEventListener("load",this.a.loadTimeCollector,!1),window.removeEventListener("mousemove",this.a.mouseCollector,!1),window.removeEventListener("keypress",this.a.keyboardCollector,!1),window.removeEventListener("devicemotion",this.a.accelerometerCollector,!1),window.removeEventListener("touchmove",this.a.touchCollector,!1)):document.detachEvent&&(document.detachEvent("onload",this.a.loadTimeCollector),document.detachEvent("onmousemove",this.a.mouseCollector),document.detachEvent("keypress",this.a.keyboardCollector)),this.D=!1)},addEventListener:function(t,e){this.J[t][this.ea++]=e},removeEventListener:function(t,e){var r,n,o=this.J[t],i=[];for(n in o)o.hasOwnProperty(n)&&o[n]===e&&i.push(n);for(r=0;re&&(t.m[e]=t.m[e]+1|0,!t.m[e]);e++);return t.K.encrypt(t.m)}function De(t,e){return function(){e.apply(t,arguments)}}a.random=new a.prng(6);e:try{if(Xe=typeof fe<"u"&&fe.exports){try{Ge=Dr("crypto")}catch{Ge=null}Xe=$e=Ge}if(Xe&&$e.randomBytes)Ce=$e.randomBytes(128),Ce=new Uint32Array(new Uint8Array(Ce).buffer),a.random.addEntropy(Ce,1024,"crypto['randomBytes']");else if(typeof window<"u"&&typeof Uint32Array<"u"){if(Se=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(Se);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(Se);else break e;a.random.addEntropy(Se,1024,"crypto['getRandomValues']")}}catch(t){typeof window<"u"&&window.console&&(console.log("There was an error collecting entropy from the browser:"),console.log(t))}var Ce,$e,Se,Xe,Ge;a.json={defaults:{v:1,iter:1e4,ks:128,ts:64,mode:"ccm",adata:"",cipher:"aes"},ha:function(t,e,r,n){r=r||{},n=n||{};var o=a.json,i=o.j({iv:a.random.randomWords(4,0)},o.defaults),s;if(o.j(i,r),r=i.adata,typeof i.salt=="string"&&(i.salt=a.codec.base64.toBits(i.salt)),typeof i.iv=="string"&&(i.iv=a.codec.base64.toBits(i.iv)),!a.mode[i.mode]||!a.cipher[i.cipher]||typeof t=="string"&&100>=i.iter||i.ts!==64&&i.ts!==96&&i.ts!==128||i.ks!==128&&i.ks!==192&&i.ks!==256||2>i.iv.length||4=e.iter||e.ts!==64&&e.ts!==96&&e.ts!==128||e.ks!==128&&e.ks!==192&&e.ks!==256||!e.iv||2>e.iv.length||4{"use strict";var hn=Object.prototype.hasOwnProperty,k="~";function ke(){}Object.create&&(ke.prototype=Object.create(null),new ke().__proto__||(k=!1));function ln(t,e,r){this.fn=t,this.context=e,this.once=r||!1}function cr(t,e,r,n,o){if(typeof r!="function")throw new TypeError("The listener must be a function");var i=new ln(r,n||t,o),s=k?k+e:e;return t._events[s]?t._events[s].fn?t._events[s]=[t._events[s],i]:t._events[s].push(i):(t._events[s]=i,t._eventsCount++),t}function qe(t,e){--t._eventsCount===0?t._events=new ke:delete t._events[e]}function D(){this._events=new ke,this._eventsCount=0}D.prototype.eventNames=function(){var e=[],r,n;if(this._eventsCount===0)return e;for(n in r=this._events)hn.call(r,n)&&e.push(k?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(r)):e};D.prototype.listeners=function(e){var r=k?k+e:e,n=this._events[r];if(!n)return[];if(n.fn)return[n.fn];for(var o=0,i=n.length,s=new Array(i);o{let n=e.isOk()?{type:"Ok",value:e.value}:{type:"Err",value:e.error},o=r.withStackTrace?new Error().stack:void 0;return{data:n,message:t,stack:o}};function ae(t,e,r,n){function o(i){return i instanceof r?i:new r(function(s){s(i)})}return new(r||(r=Promise))(function(i,s){function c(h){try{f(n.next(h))}catch(l){s(l)}}function u(h){try{f(n.throw(h))}catch(l){s(l)}}function f(h){h.done?i(h.value):o(h.value).then(c,u)}f((n=n.apply(t,e||[])).next())})}function jt(t){var e=typeof Symbol=="function"&&Symbol.iterator,r=e&&t[e],n=0;if(r)return r.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function $(t){return this instanceof $?(this.v=t,this):new $(t)}function Wt(t,e,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=r.apply(t,e||[]),o,i=[];return o=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),c("next"),c("throw"),c("return",s),o[Symbol.asyncIterator]=function(){return this},o;function s(p){return function(A){return Promise.resolve(A).then(p,l)}}function c(p,A){n[p]&&(o[p]=function(M){return new Promise(function(F,Y){i.push([p,M,F,Y])>1||u(p,M)})},A&&(o[p]=A(o[p])))}function u(p,A){try{f(n[p](A))}catch(M){m(i[0][3],M)}}function f(p){p.value instanceof $?Promise.resolve(p.value.v).then(h,l):m(i[0][2],p)}function h(p){u("next",p)}function l(p){u("throw",p)}function m(p,A){p(A),i.shift(),i.length&&u(i[0][0],i[0][1])}}function Ur(t){var e,r;return e={},n("next"),n("throw",function(o){throw o}),n("return"),e[Symbol.iterator]=function(){return this},e;function n(o,i){e[o]=t[o]?function(s){return(r=!r)?{value:$(t[o](s)),done:!1}:i?i(s):s}:i}}function Nr(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e=t[Symbol.asyncIterator],r;return e?e.call(t):(t=typeof jt=="function"?jt(t):t[Symbol.iterator](),r={},n("next"),n("throw"),n("return"),r[Symbol.asyncIterator]=function(){return this},r);function n(i){r[i]=t[i]&&function(s){return new Promise(function(c,u){s=t[i](s),o(c,u,s.done,s.value)})}}function o(i,s,c,u){Promise.resolve(u).then(function(f){i({value:f,done:c})},s)}}var _=class t{constructor(e){this._promise=e}static fromSafePromise(e){let r=e.then(n=>new N(n));return new t(r)}static fromPromise(e,r){let n=e.then(o=>new N(o)).catch(o=>new B(r(o)));return new t(n)}static fromThrowable(e,r){return(...n)=>new t(ae(this,void 0,void 0,function*(){try{return new N(yield e(...n))}catch(o){return new B(r?r(o):o)}}))}static combine(e){return Br(e)}static combineWithAllErrors(e){return jr(e)}map(e){return new t(this._promise.then(r=>ae(this,void 0,void 0,function*(){return r.isErr()?new B(r.error):new N(yield e(r.value))})))}andThrough(e){return new t(this._promise.then(r=>ae(this,void 0,void 0,function*(){if(r.isErr())return new B(r.error);let n=yield e(r.value);return n.isErr()?new B(n.error):new N(r.value)})))}andTee(e){return new t(this._promise.then(r=>ae(this,void 0,void 0,function*(){if(r.isErr())return new B(r.error);try{yield e(r.value)}catch{}return new N(r.value)})))}mapErr(e){return new t(this._promise.then(r=>ae(this,void 0,void 0,function*(){return r.isOk()?new N(r.value):new B(yield e(r.error))})))}andThen(e){return new t(this._promise.then(r=>{if(r.isErr())return new B(r.error);let n=e(r.value);return n instanceof t?n._promise:n}))}orElse(e){return new t(this._promise.then(r=>ae(this,void 0,void 0,function*(){return r.isErr()?e(r.error):new N(r.value)})))}match(e,r){return this._promise.then(n=>n.match(e,r))}unwrapOr(e){return this._promise.then(r=>r.unwrapOr(e))}safeUnwrap(){return Wt(this,arguments,function*(){return yield $(yield $(yield*Ur(Nr(yield $(this._promise.then(r=>r.safeUnwrap()))))))})}then(e,r){return this._promise.then(e,r)}[Symbol.asyncIterator](){return Wt(this,arguments,function*(){let r=yield $(this._promise);return r.isErr()&&(yield yield $(S(r.error))),yield $(r.value)})}},X=t=>new _(Promise.resolve(new N(t))),S=t=>new _(Promise.resolve(new B(t))),wn=_.fromPromise,En=_.fromSafePromise,An=_.fromThrowable,zt=t=>{let e=re([]);for(let r of t)if(r.isErr()){e=V(r.error);break}else e.map(n=>n.push(r.value));return e},Br=t=>_.fromSafePromise(Promise.all(t)).andThen(zt),Jt=t=>{let e=re([]);for(let r of t)r.isErr()&&e.isErr()?e.error.push(r.error):r.isErr()&&e.isOk()?e=V([r.error]):r.isOk()&&e.isOk()&&e.value.push(r.value);return e},jr=t=>_.fromSafePromise(Promise.all(t)).andThen(Jt),ft;(function(t){function e(o,i){return(...s)=>{try{let c=o(...s);return re(c)}catch(c){return V(i?i(c):c)}}}t.fromThrowable=e;function r(o){return zt(o)}t.combine=r;function n(o){return Jt(o)}t.combineWithAllErrors=n})(ft||(ft={}));var re=t=>new N(t);function V(t){return new B(t)}var N=class{constructor(e){this.value=e}isOk(){return!0}isErr(){return!this.isOk()}map(e){return re(e(this.value))}mapErr(e){return re(this.value)}andThen(e){return e(this.value)}andThrough(e){return e(this.value).map(r=>this.value)}andTee(e){try{e(this.value)}catch{}return re(this.value)}orElse(e){return re(this.value)}asyncAndThen(e){return e(this.value)}asyncAndThrough(e){return e(this.value).map(()=>this.value)}asyncMap(e){return _.fromSafePromise(e(this.value))}unwrapOr(e){return this.value}match(e,r){return e(this.value)}safeUnwrap(){let e=this.value;return function*(){return e}()}_unsafeUnwrap(e){return this.value}_unsafeUnwrapErr(e){throw Ft("Called `_unsafeUnwrapErr` on an Ok",this,e)}*[Symbol.iterator](){return this.value}},B=class{constructor(e){this.error=e}isOk(){return!1}isErr(){return!this.isOk()}map(e){return V(this.error)}mapErr(e){return V(e(this.error))}andThrough(e){return V(this.error)}andTee(e){return V(this.error)}andThen(e){return V(this.error)}orElse(e){return e(this.error)}asyncAndThen(e){return S(this.error)}asyncAndThrough(e){return S(this.error)}asyncMap(e){return S(this.error)}unwrapOr(e){return e}match(e,r){return r(this.error)}safeUnwrap(){let e=this.error;return function*(){throw yield V(e),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(e){throw Ft("Called `_unsafeUnwrap` on an Err",this,e)}_unsafeUnwrapErr(e){return this.error}*[Symbol.iterator](){let e=this;return yield e,e}},On=ft.fromThrowable;var ee=class extends Error{constructor(r,n={}){let{cause:o,context:i}=n;super(r,{cause:o});U(this,"context");this.name=this.constructor.name,this.context=i}};var ne=t=>{if(t instanceof Error)return t;let e="[Unable to stringify the thrown value]";try{e=JSON.stringify(t)}catch{}return new Error(e)};var Wr=()=>typeof Deno<"u";var ce=t=>Wr()?new URL(`./worker/${t}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${t==="main"?`worker/${t}`:t}.js`));var v=new Xt.default,L,Ht=!1;self.onmessage=t=>{Jr(t),Ht||(Ht=!0,v.once("OPERATION_FAILED",()=>{L&&L.terminate()}))};var K=(t,e)=>(Object.assign(t,e),typeof WorkerGlobalScope<"u"&&self.postMessage({event:"FILE_UPDATED",lufiFile:t}),t),Gt=(t,e)=>{K(t,{uploadStatus:2}),self.postMessage({event:"OPERATION_FAILED",error:e})},Jr=(t,e)=>{let{action:r}=t.data;if(r===5||r===8)L.postMessage(t.data,t.data);else{switch(r){case 2:L=new Worker(ce("cancel"),{type:"module"}),L.postMessage(t.data,t.data);break;case 3:L=new Worker(ce("download"),{type:"module"}),L.postMessage(t.data,t.data);break;case 4:L=new Worker(ce("infos"),{type:"module"}),L.postMessage(t.data,t.data);break;case 7:L=L||new Worker(ce("remove"),{type:"module"}),L.postMessage(t.data,t.data);break;case 9:L=L||new Worker(ce("upload"),{type:"module"}),L.postMessage(t.data,t.data);break;default:console.error("Action not found")}L.onmessage=n=>{e&&e(n),self.postMessage(n.data,n.data)},L.onerror=n=>{console.error(`Error: ${n.message}`)}}},qt=()=>{v.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),v.once("OPERATION_FAILED",t=>{self.postMessage({event:"OPERATION_FAILED",error:t})})};var G=class extends ee{};var Le=class extends G{constructor(){super(...arguments);U(this,"message","An error occured while trying to connect to WebSocket")}};var ue=class{constructor(e,r){if(!e||e.length!=64)throw Error("Charset must contain 64 characters");this._charset=e,this._noPadding=!!r,this._valid=new RegExp("^["+this._charset.replace("-","\\-")+"]+={0,2}$")}Encode(e){let r=e.byteLength;if(!r)return"";let n=new Uint8Array(e),o="";for(let i=0;i>2]+this._charset[(n[i]&3)<<4|n[i+1]>>4]+this._charset[(n[i+1]&15)<<2|n[i+2]>>6]+this._charset[n[i+2]&63];return r%3==2?(o=o.substring(0,o.length-1),this._noPadding||(o+="=")):r%3==1&&(o=o.substring(0,o.length-2),this._noPadding||(o+="==")),o}Decode(e){if(e=(e||"").replace(/[\s]/g,""),!e)return new ArrayBuffer(0);if(!this._valid.test(e))throw Error("Invalid base64 input sequence");let r=Math.floor(e.length*.75);e[e.length-2]=="="?r-=2:e[e.length-1]=="="&&r--;let n=new Uint8Array(r),o,i,s,c,u=0,f=0;for(;u>4,n[u++]=(i&15)<<4|s>>2,n[u++]=(s&3)<<6|c;return n.buffer}};var Hr=new ue("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");function be(t){return Hr.Decode(t)}var $r=new ue("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",!0);function ht(t){return $r.Decode(t)}var tr=at(Zt());var Q=class extends ee{};var he=class extends Q{constructor(){super(...arguments);U(this,"message","Unable to decrypt the provided data")}};var rr=(t,e)=>{try{let r=typeof e=="string"?e:e.data;return X(be(tr.default.decrypt(t,r)))}catch(r){return S(new he(void 0,{cause:ne(r)}))}};var nr=(t,e)=>Vr(t).andThen(r=>_.fromPromise(crypto.subtle.decrypt({name:"AES-GCM",iv:e.iv},r,be(e.data)),n=>new he(void 0,{cause:ne(n)})));var Vr=t=>_.fromPromise(crypto.subtle.importKey("raw",ht(t),{name:"AES-GCM"},!1,["encrypt","decrypt"]),e=>new Q("Unable to import cryptography key",{cause:ne(e)}));var or=(t,e)=>e.algo===void 0||e.algo===0?rr(t,e):nr(t,e);var I={},ir=5,Zr=t=>(v.emit("UPLOAD_CANCELLED",t.success),X(void 0)),en=(t,e)=>{let r=t.split("XXMOJOXX"),n=r.shift();if(n!==void 0){let o=JSON.parse(n);if(un(o)){let i=r.shift();if(i){let s=JSON.parse(i);return s.iv&&(s.iv=new Uint8Array(Object.values(s.iv))),or(e.keys.client,s).andThen(c=>{let u=typeof c=="string"?new TextEncoder().encode(c).buffer:c;return o.part===0?(K(e,{chunksReady:e.chunksReady+1,delAtFirstView:o.del_at_first_view,delay:o.delay,name:o.name,size:o.size,totalChunks:o.total,type:o.type,zipped:o.zipped}),v.emit("DOWNLOAD_STARTED")):K(e,{chunksReady:e.chunksReady+1}),v.emit("CHUNK_DOWNLOADED",u,o.part),++o.part===o.total?on(e).andThen(()=>(v.emit("DOWNLOAD_COMPLETE"),v.emit("SOCKET_OPERATION_TERMINATED"),X(void 0))):X(void 0)})}else{let s=new G("Cannot retrieve metadata from data received by the server");return v.emit("OPERATION_FAILED",s),S(s)}}else{let i=new G(o.msg);return v.emit("OPERATION_FAILED",i),S(i)}}else{let o=new G("Cannot retrieve metadata from data received by the server");return v.emit("OPERATION_FAILED",o),S(o)}},tn=(t,e)=>{if(t.success)return t.j===0&&(K(e,{keys:{client:e.keys.client,server:t.short},actionToken:t.token,queueIndex:t.i}),v.emit("UPLOAD_STARTED")),K(e,{chunksReady:e.chunksReady+1,createdAt:t.created_at}),v.emit("CHUNK_UPLOADED"),e.chunksReady===e.totalChunks&&(K(e,{uploadStatus:1}),v.emit("UPLOAD_COMPLETE"),v.emit("SOCKET_OPERATION_TERMINATED")),X(void 0);{let r=new G(t.msg);return v.emit("OPERATION_FAILED",r),S(r)}},rn=(t,e)=>{let r=cn(t.data),n;if(r)if(!r.action&&r.msg){let o=new G(r.msg);return v.emit("OPERATION_FAILED",o),S(o)}else"delay"in r?n=tn(r,e):n=Zr(r);else n=en(t.data,e);return n},nn=t=>I!==void 0&&I[t]!==void 0&&I[t].readyState===WebSocket.CONNECTING,dt=t=>I!==void 0&&I[t]!==void 0&&I[t].readyState===WebSocket.OPEN;var pt=(t,e)=>{let r;return t.password?r={part:e,file_pwd:t.password}:r={part:e},mt(ar(t),t,JSON.stringify(r))},on=t=>{let e;return t.password?e={ended:!0,file_pwd:t.password}:e={ended:!0},mt(ar(t),t,JSON.stringify(e))};var mt=(t,e,r)=>dt(t)?(I[t].onmessage=n=>rn(n,e),I[t].send(r),X(void 0)):sr(t).andThen(()=>mt(t,e,r)),sr=(t,e=0)=>(!dt(t)&&!nn(t)&&(I[t]=new WebSocket(t),v.once("SOCKET_OPERATION_TERMINATED",()=>{I[t].close()}),v.once("OPERATION_FAILED",()=>{v.emit("SOCKET_OPERATION_TERMINATED")}),I[t].onopen=()=>{v.emit("SOCKET_OPENED")},I[t].onclose=()=>{},I[t].onerror=()=>++e<=ir?(console.error(`An error happened while trying to connect to WebSocket ${t}. Trying again. ${e} / ${ir}`),sr(t,e)):(v.emit("SOCKET_ONERROR"),S(new Le(`Unable to connect to WebSocket ${t}.`)))),sn(t).andThen(()=>X(t)).orElse(r=>S(r))),sn=t=>_.fromPromise(new Promise((e,r)=>{dt(t)?e(void 0):(v.once("SOCKET_OPENED",()=>{e(void 0)}),v.on("SOCKET_ONERROR",()=>{r(new Le)}))}),e=>ne(e));var an=(t,e)=>{let r=new URL(t);return r.protocol=r.protocol==="http:"?"ws:":"wss:",r.pathname+=e,new URL(r.origin+r.pathname)},ar=t=>an(new URL(t.serverUrl),"download"+`/${t.keys.server}`).toString();var cn=t=>{try{let e=JSON.parse(t);if(e&&typeof e=="object")return e}catch{}return!1},un=t=>typeof t=="object"&&t!==null&&!("msg"in t);var vt=at(ur(),1);var Pe=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},gt=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},fr=t=>globalThis.DOMException===void 0?new gt(t):new DOMException(t),hr=t=>{let e=t.reason===void 0?fr("This operation was aborted."):t.reason;return e instanceof Error?e:fr(e)};function wt(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout}}=e,s,u=new Promise((f,h)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(e.signal){let{signal:m}=e;m.aborted&&h(hr(m));let p=()=>{h(hr(m))};m.addEventListener("abort",p,{once:!0}),t.finally(()=>{m.removeEventListener("abort",p)})}if(r===Number.POSITIVE_INFINITY){t.then(f,h);return}let l=new Pe;s=i.setTimeout.call(void 0,()=>{if(n){try{f(n())}catch(m){h(m)}return}typeof t.cancel=="function"&&t.cancel(),o===!1?f():o instanceof Error?h(o):(l.message=o!=null?o:`Promise timed out after ${r} milliseconds`,h(l))},r),(async()=>{try{f(await t)}catch(m){h(m)}})()}).finally(()=>{u.clear()});return u.clear=()=>{i.clearTimeout.call(void 0,s),s=void 0},u}function Et(t,e,r){let n=0,o=t.length;for(;o>0;){let i=Math.trunc(o/2),s=n+i;r(t[s],e)<=0?(n=++s,o-=i+1):o=i}return n}var q,Te=class{constructor(){O(this,q,[])}enqueue(e,r){r={priority:0,...r};let n={priority:r.priority,run:e};if(this.size&&d(this,q)[this.size-1].priority>=r.priority){d(this,q).push(n);return}let o=Et(d(this,q),n,(i,s)=>s.priority-i.priority);d(this,q).splice(o,0,n)}dequeue(){let e=d(this,q).shift();return e==null?void 0:e.run}filter(e){return d(this,q).filter(r=>r.priority===e.priority).map(r=>r.run)}get size(){return d(this,q).length}};q=new WeakMap;var le,de,te,Ie,pe,Me,j,me,P,Ue,W,ye,Z,Ne,y,lr,dr,pr,mr,yr,Ye,At,Ot,Ve,vr,Ke,Re=class extends vt.default{constructor(r){var n,o,i,s;super();O(this,y);O(this,le);O(this,de);O(this,te,0);O(this,Ie);O(this,pe);O(this,Me,0);O(this,j);O(this,me);O(this,P);O(this,Ue);O(this,W,0);O(this,ye);O(this,Z);O(this,Ne);U(this,"timeout");if(r={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:Te,...r},!(typeof r.intervalCap=="number"&&r.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${(o=(n=r.intervalCap)==null?void 0:n.toString())!=null?o:""}\` (${typeof r.intervalCap})`);if(r.interval===void 0||!(Number.isFinite(r.interval)&&r.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${(s=(i=r.interval)==null?void 0:i.toString())!=null?s:""}\` (${typeof r.interval})`);w(this,le,r.carryoverConcurrencyCount),w(this,de,r.intervalCap===Number.POSITIVE_INFINITY||r.interval===0),w(this,Ie,r.intervalCap),w(this,pe,r.interval),w(this,P,new r.queueClass),w(this,Ue,r.queueClass),this.concurrency=r.concurrency,this.timeout=r.timeout,w(this,Ne,r.throwOnTimeout===!0),w(this,Z,r.autoStart===!1)}get concurrency(){return d(this,ye)}set concurrency(r){if(!(typeof r=="number"&&r>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${r}\` (${typeof r})`);w(this,ye,r),x(this,y,Ve).call(this)}async add(r,n={}){return n={timeout:this.timeout,throwOnTimeout:d(this,Ne),...n},new Promise((o,i)=>{d(this,P).enqueue(async()=>{var s;ze(this,W)._++,ze(this,te)._++;try{(s=n.signal)==null||s.throwIfAborted();let c=r({signal:n.signal});n.timeout&&(c=wt(Promise.resolve(c),{milliseconds:n.timeout})),n.signal&&(c=Promise.race([c,x(this,y,vr).call(this,n.signal)]));let u=await c;o(u),this.emit("completed",u)}catch(c){if(c instanceof Pe&&!n.throwOnTimeout){o();return}i(c),this.emit("error",c)}finally{x(this,y,pr).call(this)}},n),this.emit("add"),x(this,y,Ye).call(this)})}async addAll(r,n){return Promise.all(r.map(async o=>this.add(o,n)))}start(){return d(this,Z)?(w(this,Z,!1),x(this,y,Ve).call(this),this):this}pause(){w(this,Z,!0)}clear(){w(this,P,new(d(this,Ue)))}async onEmpty(){d(this,P).size!==0&&await x(this,y,Ke).call(this,"empty")}async onSizeLessThan(r){d(this,P).sized(this,P).size{x(this,y,mr).call(this)},n)),!0}return!1},Ye=function(){if(d(this,P).size===0)return d(this,j)&&clearInterval(d(this,j)),w(this,j,void 0),this.emit("empty"),d(this,W)===0&&this.emit("idle"),!1;if(!d(this,Z)){let r=!d(this,y,yr);if(d(this,y,lr)&&d(this,y,dr)){let n=d(this,P).dequeue();return n?(this.emit("active"),n(),r&&x(this,y,At).call(this),!0):!1}}return!1},At=function(){d(this,de)||d(this,j)!==void 0||(w(this,j,setInterval(()=>{x(this,y,Ot).call(this)},d(this,pe))),w(this,Me,Date.now()+d(this,pe)))},Ot=function(){d(this,te)===0&&d(this,W)===0&&d(this,j)&&(clearInterval(d(this,j)),w(this,j,void 0)),w(this,te,d(this,le)?d(this,W):0),x(this,y,Ve).call(this)},Ve=function(){for(;x(this,y,Ye).call(this););},vr=async function(r){return new Promise((n,o)=>{r.addEventListener("abort",()=>{o(r.reason)},{once:!0})})},Ke=async function(r,n){return new Promise(o=>{let i=()=>{n&&!n()||(this.off(r,i),o())};this.on(r,i)})};var xt=navigator.hardwareConcurrency||4,Qe=new Re({concurrency:xt,autoStart:!1}),Ze=0,gr=!1,et=!1;self.onmessage=t=>{gr||(qt(),gr=!0);let e=t.data;switch(e.action){case 5:et=!0,self.postMessage({event:"JOB_PAUSED"});break;case 8:et=!1,self.postMessage({event:"JOB_RESUMED"});break;default:v.once("DOWNLOAD_COMPLETE",()=>{self.postMessage({event:"DOWNLOAD_COMPLETE"})}),v.on("FILE_UPDATED",K),v.on("CHUNK_DOWNLOADED",(r,n)=>{self.postMessage({event:"CHUNK_DOWNLOADED",chunk:{buffer:r,index:n}},[r])}),dn(e).mapErr(r=>{Gt(e.args.lufiFile,r)})}};var dn=t=>{let{lufiFile:e}=t.args;return v.on("CHUNK_DOWNLOADED",()=>{Ze--,!et&&Ze{for(let r=1;r{await pt(e,r),Ze++,(et||Ze===xt)&&Qe.pause()});Qe.start()}),pt(e,0)}; diff --git a/themes/default/public/js/worker/encrypt.js b/themes/default/public/js/worker/encrypt.js index 2211401..677fbf3 100644 --- a/themes/default/public/js/worker/encrypt.js +++ b/themes/default/public/js/worker/encrypt.js @@ -1 +1 @@ -var lt=Object.create;var Le=Object.defineProperty;var pt=Object.getOwnPropertyDescriptor;var dt=Object.getOwnPropertyNames;var mt=Object.getPrototypeOf,yt=Object.prototype.hasOwnProperty;var vt=(t,e,r)=>e in t?Le(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var gt=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var Me=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var wt=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of dt(e))!yt.call(t,o)&&o!==r&&Le(t,o,{get:()=>e[o],enumerable:!(n=pt(e,o))||n.enumerable});return t};var je=(t,e,r)=>(r=t!=null?lt(mt(t)):{},wt(e||!t||!t.__esModule?Le(r,"default",{value:t,enumerable:!0}):r,t));var D=(t,e,r)=>vt(t,typeof e!="symbol"?e+"":e,r);var ze=Me((or,z)=>{"use strict";var c={cipher:{},hash:{},keyexchange:{},mode:{},misc:{},codec:{},exception:{corrupt:function(t){this.toString=function(){return"CORRUPT: "+this.message},this.message=t},invalid:function(t){this.toString=function(){return"INVALID: "+this.message},this.message=t},bug:function(t){this.toString=function(){return"BUG: "+this.message},this.message=t},notReady:function(t){this.toString=function(){return"NOT READY: "+this.message},this.message=t}}};c.cipher.aes=function(t){this.w[0][0][0]||this.C();var e,r,n,o,i=this.w[0][4],s=this.w[1];e=t.length;var a=1;if(e!==4&&e!==6&&e!==8)throw new c.exception.invalid("invalid aes key size");for(this.b=[n=t.slice(0),o=[]],t=e;t<4*e+28;t++)r=n[t-1],(t%e===0||e===8&&t%e===4)&&(r=i[r>>>24]<<24^i[r>>16&255]<<16^i[r>>8&255]<<8^i[r&255],t%e===0&&(r=r<<8^r>>>24^a<<24,a=a<<1^283*(a>>7))),n[t]=n[t-e]^r;for(e=0;t;e++,t--)r=n[e&3?t:t-4],o[e]=4>=t||4>e?r:s[0][i[r>>>24]]^s[1][i[r>>16&255]]^s[2][i[r>>8&255]]^s[3][i[r&255]]};c.cipher.aes.prototype={encrypt:function(t){return We(this,t,0)},decrypt:function(t){return We(this,t,1)},w:[[[],[],[],[],[]],[[],[],[],[],[]]],C:function(){var t=this.w[0],e=this.w[1],r=t[4],n=e[4],o,i,s,a=[],f=[],u,h,l,m;for(o=0;256>o;o++)f[(a[o]=o<<1^283*(o>>7))^o]=o;for(i=s=0;!r[i];i^=u||1,s=f[s]||1)for(l=s^s<<1^s<<2^s<<3^s<<4,l=l>>8^l&255^99,r[i]=l,n[l]=i,h=a[o=a[u=a[i]]],m=16843009*h^65537*o^257*u^16843008*i,h=257*a[l]^16843008*l,o=0;4>o;o++)t[o][i]=h=h<<24^h>>>8,e[o][l]=m=m<<24^m>>>8;for(o=0;5>o;o++)t[o]=t[o].slice(0),e[o]=e[o].slice(0)}};function We(t,e,r){if(e.length!==4)throw new c.exception.invalid("invalid aes block size");var n=t.b[r],o=e[0]^n[0],i=e[r?3:1]^n[1],s=e[2]^n[2];e=e[r?1:3]^n[3];var a,f,u,h=n.length/4-2,l,m=4,p=[0,0,0,0];a=t.w[r],t=a[0];var v=a[1],b=a[2],O=a[3],j=a[4];for(l=0;l>>24]^v[i>>16&255]^b[s>>8&255]^O[e&255]^n[m],f=t[i>>>24]^v[s>>16&255]^b[e>>8&255]^O[o&255]^n[m+1],u=t[s>>>24]^v[e>>16&255]^b[o>>8&255]^O[i&255]^n[m+2],e=t[e>>>24]^v[o>>16&255]^b[i>>8&255]^O[s&255]^n[m+3],m+=4,o=a,i=f,s=u;for(l=0;4>l;l++)p[r?3&-l:l]=j[o>>>24]<<24^j[i>>16&255]<<16^j[s>>8&255]<<8^j[e&255]^n[m++],a=o,o=i,i=s,s=e,e=a;return p}c.bitArray={bitSlice:function(t,e,r){return t=c.bitArray.Y(t.slice(e/32),32-(e&31)).slice(1),r===void 0?t:c.bitArray.clamp(t,r-e)},extract:function(t,e,r){var n=Math.floor(-e-r&31);return((e+r-1^e)&-32?t[e/32|0]<<32-n^t[e/32+1|0]>>>n:t[e/32|0]>>>n)&(1<>e-1,1)),t},partial:function(t,e,r){return t===32?e:(r?e|0:e<<32-t)+1099511627776*t},getPartial:function(t){return Math.round(t/1099511627776)||32},equal:function(t,e){if(c.bitArray.bitLength(t)!==c.bitArray.bitLength(e))return!1;var r=0,n;for(n=0;n>>e),r=t[o]<<32-e;return o=t.length?t[t.length-1]:0,t=c.bitArray.getPartial(o),n.push(c.bitArray.partial(e+t&31,32>>24|r>>>8&65280|(r&65280)<<8|r<<24;return t}};c.codec.utf8String={fromBits:function(t){var e="",r=c.bitArray.bitLength(t),n,o;for(n=0;n>>8>>>8>>>8),o<<=8;return decodeURIComponent(escape(e))},toBits:function(t){t=unescape(encodeURIComponent(t));var e=[],r,n=0;for(r=0;r>>o)>>>26),6>o?(s=t[r]<<6-o,o+=26,r++):(s<<=6,o-=6);for(;n.length&3&&!e;)n+="=";return n},toBits:function(t,e){t=t.replace(/\s|=/g,"");var r=[],n,o=0,i=c.codec.base64.S,s=0,a;for(e&&(i=i.substr(0,62)+"-_"),n=0;na)throw new c.exception.invalid("this isn't base64!");26>>o),s=a<<32-o):(o+=6,s^=a<<32-o)}return o&56&&r.push(c.bitArray.partial(o&56,s,1)),r}};c.codec.base64url={fromBits:function(t){return c.codec.base64.fromBits(t,1,1)},toBits:function(t){return c.codec.base64.toBits(t,1)}};c.hash.sha256=function(t){this.b[0]||this.C(),t?(this.g=t.g.slice(0),this.f=t.f.slice(0),this.c=t.c):this.reset()};c.hash.sha256.hash=function(t){return new c.hash.sha256().update(t).finalize()};c.hash.sha256.prototype={blockSize:512,reset:function(){return this.g=this.o.slice(0),this.f=[],this.c=0,this},update:function(t){typeof t=="string"&&(t=c.codec.utf8String.toBits(t));var e,r=this.f=c.bitArray.concat(this.f,t);if(e=this.c,t=this.c=e+c.bitArray.bitLength(t),9007199254740991e;r++){for(o=!0,n=2;n*n<=r;n++)if(r%n===0){o=!1;break}o&&(8>e&&(this.o[e]=t(Math.pow(r,.5))),this.b[e]=t(Math.pow(r,1/3)),e++)}},l:function(t){var e,r,n,o=this.g,i=this.b,s=o[0],a=o[1],f=o[2],u=o[3],h=o[4],l=o[5],m=o[6],p=o[7];for(e=0;64>e;e++)16>e?r=t[e]:(r=t[e+1&15],n=t[e+14&15],r=t[e&15]=(r>>>7^r>>>18^r>>>3^r<<25^r<<14)+(n>>>17^n>>>19^n>>>10^n<<15^n<<13)+t[e&15]+t[e+9&15]|0),r=r+p+(h>>>6^h>>>11^h>>>25^h<<26^h<<21^h<<7)+(m^h&(l^m))+i[e],p=m,m=l,l=h,h=u+r|0,u=f,f=a,a=s,s=r+(a&f^u&(a^f))+(a>>>2^a>>>13^a>>>22^a<<30^a<<19^a<<10)|0;o[0]=o[0]+s|0,o[1]=o[1]+a|0,o[2]=o[2]+f|0,o[3]=o[3]+u|0,o[4]=o[4]+h|0,o[5]=o[5]+l|0,o[6]=o[6]+m|0,o[7]=o[7]+p|0}};c.hash.sha512=function(t){this.b[0]||this.C(),t?(this.g=t.g.slice(0),this.f=t.f.slice(0),this.c=t.c):this.reset()};c.hash.sha512.hash=function(t){return new c.hash.sha512().update(t).finalize()};c.hash.sha512.prototype={blockSize:1024,reset:function(){return this.g=this.o.slice(0),this.f=[],this.c=0,this},update:function(t){typeof t=="string"&&(t=c.codec.utf8String.toBits(t));var e,r=this.f=c.bitArray.concat(this.f,t);if(e=this.c,t=this.c=e+c.bitArray.bitLength(t),9007199254740991r;n++){for(i=!0,o=2;o*o<=n;o++)if(n%o===0){i=!1;break}i&&(8>r&&(this.o[2*r]=t(Math.pow(n,.5)),this.o[2*r+1]=e(Math.pow(n,.5))<<24|this.ia[r]),this.b[2*r]=t(Math.pow(n,1/3)),this.b[2*r+1]=e(Math.pow(n,1/3))<<24|this.ka[r],r++)}},l:function(t){var e,r,n=this.g,o=this.b,i=n[0],s=n[1],a=n[2],f=n[3],u=n[4],h=n[5],l=n[6],m=n[7],p=n[8],v=n[9],b=n[10],O=n[11],j=n[12],ae=n[13],Ce=n[14],fe=n[15],E;if(typeof Uint32Array<"u"){E=Array(160);for(var w=0;32>w;w++)E[w]=t[w]}else E=t;var w=i,x=s,$=a,F=f,X=u,W=h,we=l,V=m,C=p,L=v,ue=b,q=O,he=j,Q=ae,Ee=Ce,Z=fe;for(t=0;80>t;t++){if(16>t)e=E[2*t],r=E[2*t+1];else{r=E[2*(t-15)];var y=E[2*(t-15)+1];e=(y<<31|r>>>1)^(y<<24|r>>>8)^r>>>7;var S=(r<<31|y>>>1)^(r<<24|y>>>8)^(r<<25|y>>>7);r=E[2*(t-2)];var P=E[2*(t-2)+1],y=(P<<13|r>>>19)^(r<<3|P>>>29)^r>>>6,P=(r<<13|P>>>19)^(P<<3|r>>>29)^(r<<26|P>>>6),Ae=E[2*(t-7)],xe=E[2*(t-16)],ee=E[2*(t-16)+1];r=S+E[2*(t-7)+1],e=e+Ae+(r>>>0>>0?1:0),r+=P,e+=y+(r>>>0

>>0?1:0),r+=ee,e+=xe+(r>>>0>>0?1:0)}E[2*t]=e|=0,E[2*t+1]=r|=0;var Ae=C&ue^~C&he,Se=L&q^~L&Q,P=w&$^w&X^$&X,ut=x&F^x&W^F&W,xe=(x<<4|w>>>28)^(w<<30|x>>>2)^(w<<25|x>>>7),ee=(w<<4|x>>>28)^(x<<30|w>>>2)^(x<<25|w>>>7),ht=o[2*t],Pe=o[2*t+1],y=Z+((C<<18|L>>>14)^(C<<14|L>>>18)^(L<<23|C>>>9)),S=Ee+((L<<18|C>>>14)^(L<<14|C>>>18)^(C<<23|L>>>9))+(y>>>0>>0?1:0),y=y+Se,S=S+(Ae+(y>>>0>>0?1:0)),y=y+Pe,S=S+(ht+(y>>>0>>0?1:0)),y=y+r|0,S=S+(e+(y>>>0>>0?1:0));r=ee+ut,e=xe+P+(r>>>0>>0?1:0),Ee=he,Z=Q,he=ue,Q=q,ue=C,q=L,L=V+y|0,C=we+S+(L>>>0>>0?1:0)|0,we=X,V=W,X=$,W=F,$=w,F=x,x=y+r|0,w=S+e+(x>>>0>>0?1:0)|0}s=n[1]=s+x|0,n[0]=i+w+(s>>>0>>0?1:0)|0,f=n[3]=f+F|0,n[2]=a+$+(f>>>0>>0?1:0)|0,h=n[5]=h+W|0,n[4]=u+X+(h>>>0>>0?1:0)|0,m=n[7]=m+V|0,n[6]=l+we+(m>>>0>>0?1:0)|0,v=n[9]=v+L|0,n[8]=p+C+(v>>>0>>0?1:0)|0,O=n[11]=O+q|0,n[10]=b+ue+(O>>>0>>0?1:0)|0,ae=n[13]=ae+Q|0,n[12]=j+he+(ae>>>0>>0?1:0)|0,fe=n[15]=fe+Z|0,n[14]=Ce+Ee+(fe>>>0>>0?1:0)|0}};c.mode.ccm={name:"ccm",F:[],listenProgress:function(t){c.mode.ccm.F.push(t)},unListenProgress:function(t){t=c.mode.ccm.F.indexOf(t),-1f)throw new c.exception.invalid("ccm: iv must be at least 7 bytes");for(i=2;4>i&&u>>>8*i;i++);return i<15-f&&(i=15-f),r=a.clamp(r,8*(15-i)),e=c.mode.ccm.U(t,e,r,n,o,i),s=c.mode.ccm.V(t,s,r,e,o,i),a.concat(s.data,s.tag)},decrypt:function(t,e,r,n,o){o=o||64,n=n||[];var i=c.bitArray,s=i.bitLength(r)/8,u=i.bitLength(e),a=i.clamp(e,u-o),f=i.bitSlice(e,u-o),u=(u-o)/8;if(7>s)throw new c.exception.invalid("ccm: iv must be at least 7 bytes");for(e=2;4>e&&u>>>8*e;e++);if(e<15-s&&(e=15-s),r=i.clamp(r,8*(15-e)),a=c.mode.ccm.V(t,a,r,f,o,e),t=c.mode.ccm.U(t,a.data,r,n,o,e),!i.equal(a.tag,t))throw new c.exception.corrupt("ccm: tag doesn't match");return a.data},ma:function(t,e,r,n,o,i){var s=[],a=c.bitArray,f=a.P;if(n=[a.partial(8,(e.length?64:0)|n-2<<2|i-1)],n=a.concat(n,r),n[3]|=o,n=t.encrypt(n),e.length)for(r=a.bitLength(e)/8,65279>=r?s=[a.partial(16,r)]:4294967295>=r&&(s=a.concat([a.partial(16,65534)],[r])),s=a.concat(s,e),e=0;eo||16h&&(c.mode.ccm.da(s/f),h+=l),r[3]++,o=t.encrypt(r),e[s]^=o[0],e[s+1]^=o[1],e[s+2]^=o[2],e[s+3]^=o[3];return{tag:n,data:a.clamp(e,u)}}};c.misc.hmac=function(t,e){this.W=e=e||c.hash.sha256;var r=[[],[]],n,o=e.prototype.blockSize/32;for(this.B=[new e,new e],t.length>o&&(t=e.hash(t)),n=0;nn||0>r)throw new c.exception.invalid("invalid params to pbkdf2");typeof t=="string"&&(t=c.codec.utf8String.toBits(t)),typeof e=="string"&&(e=c.codec.utf8String.toBits(e)),o=o||c.misc.hmac,t=new o(t);var i,s,a,f,u=[],h=c.bitArray;for(f=1;32*u.length<(n||1);f++){for(o=i=t.encrypt(h.concat(e,[f])),s=1;ss;s++)o.push(4294967296*Math.random()|0);for(s=0;s=1<this.u&&(this.u=i),this.N++,this.b=c.hash.sha256.hash(this.b.concat(o)),this.K=new c.cipher.aes(this.b),n=0;4>n&&(this.m[n]=this.m[n]+1|0,!this.m[n]);n++);}for(n=0;n>>1;this.h[s].update([n,this.M++,2,e,i,t.length].concat(t))}break;case"string":e===void 0&&(e=t.length),this.h[s].update([n,this.M++,3,e,i,t.length]),this.h[s].update(t);break;default:f=1}if(f)throw new c.exception.bug("random: addEntropy only supports number, array of numbers or string");this.s[s]+=e,this.i+=e,a===this.A&&(this.isReady()!==this.A&&Ne("seeded",Math.max(this.u,this.i)),Ne("progress",this.getProgress()))},isReady:function(t){return t=this.R[t!==void 0?t:this.L],this.u&&this.u>=t?this.s[0]>this.$&&new Date().valueOf()>this.X?this.I|this.H:this.H:this.i>=t?this.I|this.A:this.A},getProgress:function(t){return t=this.R[t||this.L],this.u>=t||this.i>t?1:this.i/t},startCollectors:function(){if(!this.D){if(this.a={loadTimeCollector:ne(this,this.la),mouseCollector:ne(this,this.na),keyboardCollector:ne(this,this.ja),accelerometerCollector:ne(this,this.ca),touchCollector:ne(this,this.pa)},window.addEventListener)window.addEventListener("load",this.a.loadTimeCollector,!1),window.addEventListener("mousemove",this.a.mouseCollector,!1),window.addEventListener("keypress",this.a.keyboardCollector,!1),window.addEventListener("devicemotion",this.a.accelerometerCollector,!1),window.addEventListener("touchmove",this.a.touchCollector,!1);else if(document.attachEvent)document.attachEvent("onload",this.a.loadTimeCollector),document.attachEvent("onmousemove",this.a.mouseCollector),document.attachEvent("keypress",this.a.keyboardCollector);else throw new c.exception.bug("can't attach event");this.D=!0}},stopCollectors:function(){this.D&&(window.removeEventListener?(window.removeEventListener("load",this.a.loadTimeCollector,!1),window.removeEventListener("mousemove",this.a.mouseCollector,!1),window.removeEventListener("keypress",this.a.keyboardCollector,!1),window.removeEventListener("devicemotion",this.a.accelerometerCollector,!1),window.removeEventListener("touchmove",this.a.touchCollector,!1)):document.detachEvent&&(document.detachEvent("onload",this.a.loadTimeCollector),document.detachEvent("onmousemove",this.a.mouseCollector),document.detachEvent("keypress",this.a.keyboardCollector)),this.D=!1)},addEventListener:function(t,e){this.J[t][this.ea++]=e},removeEventListener:function(t,e){var r,n,o=this.J[t],i=[];for(n in o)o.hasOwnProperty(n)&&o[n]===e&&i.push(n);for(r=0;re&&(t.m[e]=t.m[e]+1|0,!t.m[e]);e++);return t.K.encrypt(t.m)}function ne(t,e){return function(){e.apply(t,arguments)}}c.random=new c.prng(6);e:try{if(de=typeof z<"u"&&z.exports){try{me=gt("crypto")}catch{me=null}de=pe=me}if(de&&pe.randomBytes)oe=pe.randomBytes(128),oe=new Uint32Array(new Uint8Array(oe).buffer),c.random.addEntropy(oe,1024,"crypto['randomBytes']");else if(typeof window<"u"&&typeof Uint32Array<"u"){if(ie=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(ie);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(ie);else break e;c.random.addEntropy(ie,1024,"crypto['getRandomValues']")}}catch(t){typeof window<"u"&&window.console&&(console.log("There was an error collecting entropy from the browser:"),console.log(t))}var oe,pe,ie,de,me;c.json={defaults:{v:1,iter:1e4,ks:128,ts:64,mode:"ccm",adata:"",cipher:"aes"},ha:function(t,e,r,n){r=r||{},n=n||{};var o=c.json,i=o.j({iv:c.random.randomWords(4,0)},o.defaults),s;if(o.j(i,r),r=i.adata,typeof i.salt=="string"&&(i.salt=c.codec.base64.toBits(i.salt)),typeof i.iv=="string"&&(i.iv=c.codec.base64.toBits(i.iv)),!c.mode[i.mode]||!c.cipher[i.cipher]||typeof t=="string"&&100>=i.iter||i.ts!==64&&i.ts!==96&&i.ts!==128||i.ks!==128&&i.ks!==192&&i.ks!==256||2>i.iv.length||4=e.iter||e.ts!==64&&e.ts!==96&&e.ts!==128||e.ks!==128&&e.ks!==192&&e.ks!==256||!e.iv||2>e.iv.length||4{"use strict";var K=typeof Reflect=="object"?Reflect:null,Xe=K&&typeof K.apply=="function"?K.apply:function(e,r,n){return Function.prototype.apply.call(e,r,n)},ye;K&&typeof K.ownKeys=="function"?ye=K.ownKeys:Object.getOwnPropertySymbols?ye=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:ye=function(e){return Object.getOwnPropertyNames(e)};function Bt(t){console&&console.warn&&console.warn(t)}var qe=Number.isNaN||function(e){return e!==e};function d(){d.init.call(this)}_e.exports=d;_e.exports.once=Ft;d.EventEmitter=d;d.prototype._events=void 0;d.prototype._eventsCount=0;d.prototype._maxListeners=void 0;var Ve=10;function ve(t){if(typeof t!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t)}Object.defineProperty(d,"defaultMaxListeners",{enumerable:!0,get:function(){return Ve},set:function(t){if(typeof t!="number"||t<0||qe(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");Ve=t}});d.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0};d.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||qe(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this};function Qe(t){return t._maxListeners===void 0?d.defaultMaxListeners:t._maxListeners}d.prototype.getMaxListeners=function(){return Qe(this)};d.prototype.emit=function(e){for(var r=[],n=1;n0&&(s=r[0]),s instanceof Error)throw s;var a=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw a.context=s,a}var f=i[e];if(f===void 0)return!1;if(typeof f=="function")Xe(f,this,r);else for(var u=f.length,h=nt(f,u),n=0;n0&&s.length>o&&!s.warned){s.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning",a.emitter=t,a.type=e,a.count=s.length,Bt(a)}return t}d.prototype.addListener=function(e,r){return Ze(this,e,r,!1)};d.prototype.on=d.prototype.addListener;d.prototype.prependListener=function(e,r){return Ze(this,e,r,!0)};function It(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function et(t,e,r){var n={fired:!1,wrapFn:void 0,target:t,type:e,listener:r},o=It.bind(n);return o.listener=r,n.wrapFn=o,o}d.prototype.once=function(e,r){return ve(r),this.on(e,et(this,e,r)),this};d.prototype.prependOnceListener=function(e,r){return ve(r),this.prependListener(e,et(this,e,r)),this};d.prototype.removeListener=function(e,r){var n,o,i,s,a;if(ve(r),o=this._events,o===void 0)return this;if(n=o[e],n===void 0)return this;if(n===r||n.listener===r)--this._eventsCount===0?this._events=Object.create(null):(delete o[e],o.removeListener&&this.emit("removeListener",e,n.listener||r));else if(typeof n!="function"){for(i=-1,s=n.length-1;s>=0;s--)if(n[s]===r||n[s].listener===r){a=n[s].listener,i=s;break}if(i<0)return this;i===0?n.shift():Ut(n,i),n.length===1&&(o[e]=n[0]),o.removeListener!==void 0&&this.emit("removeListener",e,a||r)}return this};d.prototype.off=d.prototype.removeListener;d.prototype.removeAllListeners=function(e){var r,n,o;if(n=this._events,n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[e]),this;if(arguments.length===0){var i=Object.keys(n),s;for(o=0;o=0;o--)this.removeListener(e,r[o]);return this};function tt(t,e,r){var n=t._events;if(n===void 0)return[];var o=n[e];return o===void 0?[]:typeof o=="function"?r?[o.listener||o]:[o]:r?Tt(o):nt(o,o.length)}d.prototype.listeners=function(e){return tt(this,e,!0)};d.prototype.rawListeners=function(e){return tt(this,e,!1)};d.listenerCount=function(t,e){return typeof t.listenerCount=="function"?t.listenerCount(e):rt.call(t,e)};d.prototype.listenerCount=rt;function rt(t){var e=this._events;if(e!==void 0){var r=e[t];if(typeof r=="function")return 1;if(r!==void 0)return r.length}return 0}d.prototype.eventNames=function(){return this._eventsCount>0?ye(this._events):[]};function nt(t,e){for(var r=new Array(e),n=0;n>2]+this._charset[(n[i]&3)<<4|n[i+1]>>4]+this._charset[(n[i+1]&15)<<2|n[i+2]>>6]+this._charset[n[i+2]&63];return r%3==2?(o=o.substring(0,o.length-1),this._noPadding||(o+="=")):r%3==1&&(o=o.substring(0,o.length-2),this._noPadding||(o+="==")),o}Decode(e){if(e=(e||"").replace(/[\s]/g,""),!e)return new ArrayBuffer(0);if(!this._valid.test(e))throw Error("Invalid base64 input sequence");let r=Math.floor(e.length*.75);e[e.length-2]=="="?r-=2:e[e.length-1]=="="&&r--;let n=new Uint8Array(r),o,i,s,a,f=0,u=0;for(;f>4,n[f++]=(i&15)<<4|s>>2,n[f++]=(s&3)<<6|a;return n.buffer}};var Et=new N("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");function te(t){return Et.Encode(t)}var At=new N("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",!0);function be(t){return At.Decode(t)}var Lt={withStackTrace:!1},Ue=(t,e,r=Lt)=>{let n=e.isOk()?{type:"Ok",value:e.value}:{type:"Err",value:e.error},o=r.withStackTrace?new Error().stack:void 0;return{data:n,message:t,stack:o}};function H(t,e,r,n){function o(i){return i instanceof r?i:new r(function(s){s(i)})}return new(r||(r=Promise))(function(i,s){function a(h){try{u(n.next(h))}catch(l){s(l)}}function f(h){try{u(n.throw(h))}catch(l){s(l)}}function u(h){h.done?i(h.value):o(h.value).then(a,f)}u((n=n.apply(t,e||[])).next())})}function Be(t){var e=typeof Symbol=="function"&&Symbol.iterator,r=e&&t[e],n=0;if(r)return r.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function M(t){return this instanceof M?(this.v=t,this):new M(t)}function Ie(t,e,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=r.apply(t,e||[]),o,i=[];return o=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),a("next"),a("throw"),a("return",s),o[Symbol.asyncIterator]=function(){return this},o;function s(p){return function(v){return Promise.resolve(v).then(p,l)}}function a(p,v){n[p]&&(o[p]=function(b){return new Promise(function(O,j){i.push([p,b,O,j])>1||f(p,b)})},v&&(o[p]=v(o[p])))}function f(p,v){try{u(n[p](v))}catch(b){m(i[0][3],b)}}function u(p){p.value instanceof M?Promise.resolve(p.value.v).then(h,l):m(i[0][2],p)}function h(p){f("next",p)}function l(p){f("throw",p)}function m(p,v){p(v),i.shift(),i.length&&f(i[0][0],i[0][1])}}function bt(t){var e,r;return e={},n("next"),n("throw",function(o){throw o}),n("return"),e[Symbol.iterator]=function(){return this},e;function n(o,i){e[o]=t[o]?function(s){return(r=!r)?{value:M(t[o](s)),done:!1}:i?i(s):s}:i}}function Dt(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e=t[Symbol.asyncIterator],r;return e?e.call(t):(t=typeof Be=="function"?Be(t):t[Symbol.iterator](),r={},n("next"),n("throw"),n("return"),r[Symbol.asyncIterator]=function(){return this},r);function n(i){r[i]=t[i]&&function(s){return new Promise(function(a,f){s=t[i](s),o(a,f,s.done,s.value)})}}function o(i,s,a,f){Promise.resolve(f).then(function(u){i({value:u,done:a})},s)}}var A=class t{constructor(e){this._promise=e}static fromSafePromise(e){let r=e.then(n=>new k(n));return new t(r)}static fromPromise(e,r){let n=e.then(o=>new k(o)).catch(o=>new _(r(o)));return new t(n)}static fromThrowable(e,r){return(...n)=>new t(H(this,void 0,void 0,function*(){try{return new k(yield e(...n))}catch(o){return new _(r?r(o):o)}}))}static combine(e){return kt(e)}static combineWithAllErrors(e){return _t(e)}map(e){return new t(this._promise.then(r=>H(this,void 0,void 0,function*(){return r.isErr()?new _(r.error):new k(yield e(r.value))})))}andThrough(e){return new t(this._promise.then(r=>H(this,void 0,void 0,function*(){if(r.isErr())return new _(r.error);let n=yield e(r.value);return n.isErr()?new _(n.error):new k(r.value)})))}andTee(e){return new t(this._promise.then(r=>H(this,void 0,void 0,function*(){if(r.isErr())return new _(r.error);try{yield e(r.value)}catch{}return new k(r.value)})))}mapErr(e){return new t(this._promise.then(r=>H(this,void 0,void 0,function*(){return r.isOk()?new k(r.value):new _(yield e(r.error))})))}andThen(e){return new t(this._promise.then(r=>{if(r.isErr())return new _(r.error);let n=e(r.value);return n instanceof t?n._promise:n}))}orElse(e){return new t(this._promise.then(r=>H(this,void 0,void 0,function*(){return r.isErr()?e(r.error):new k(r.value)})))}match(e,r){return this._promise.then(n=>n.match(e,r))}unwrapOr(e){return this._promise.then(r=>r.unwrapOr(e))}safeUnwrap(){return Ie(this,arguments,function*(){return yield M(yield M(yield*bt(Dt(yield M(this._promise.then(r=>r.safeUnwrap()))))))})}then(e,r){return this._promise.then(e,r)}[Symbol.asyncIterator](){return Ie(this,arguments,function*(){let r=yield M(this._promise);return r.isErr()&&(yield yield M(T(r.error))),yield M(r.value)})}},le=t=>new A(Promise.resolve(new k(t))),T=t=>new A(Promise.resolve(new _(t))),Zt=A.fromPromise,er=A.fromSafePromise,tr=A.fromThrowable,Te=t=>{let e=U([]);for(let r of t)if(r.isErr()){e=R(r.error);break}else e.map(n=>n.push(r.value));return e},kt=t=>A.fromSafePromise(Promise.all(t)).andThen(Te),Fe=t=>{let e=U([]);for(let r of t)r.isErr()&&e.isErr()?e.error.push(r.error):r.isErr()&&e.isOk()?e=R([r.error]):r.isOk()&&e.isOk()&&e.value.push(r.value);return e},_t=t=>A.fromSafePromise(Promise.all(t)).andThen(Fe),De;(function(t){function e(o,i){return(...s)=>{try{let a=o(...s);return U(a)}catch(a){return R(i?i(a):a)}}}t.fromThrowable=e;function r(o){return Te(o)}t.combine=r;function n(o){return Fe(o)}t.combineWithAllErrors=n})(De||(De={}));var U=t=>new k(t);function R(t){return new _(t)}var k=class{constructor(e){this.value=e}isOk(){return!0}isErr(){return!this.isOk()}map(e){return U(e(this.value))}mapErr(e){return U(this.value)}andThen(e){return e(this.value)}andThrough(e){return e(this.value).map(r=>this.value)}andTee(e){try{e(this.value)}catch{}return U(this.value)}orElse(e){return U(this.value)}asyncAndThen(e){return e(this.value)}asyncAndThrough(e){return e(this.value).map(()=>this.value)}asyncMap(e){return A.fromSafePromise(e(this.value))}unwrapOr(e){return this.value}match(e,r){return e(this.value)}safeUnwrap(){let e=this.value;return function*(){return e}()}_unsafeUnwrap(e){return this.value}_unsafeUnwrapErr(e){throw Ue("Called `_unsafeUnwrapErr` on an Ok",this,e)}*[Symbol.iterator](){return this.value}},_=class{constructor(e){this.error=e}isOk(){return!1}isErr(){return!this.isOk()}map(e){return R(this.error)}mapErr(e){return R(e(this.error))}andThrough(e){return R(this.error)}andTee(e){return R(this.error)}andThen(e){return R(this.error)}orElse(e){return e(this.error)}asyncAndThen(e){return T(this.error)}asyncAndThrough(e){return T(this.error)}asyncMap(e){return T(this.error)}unwrapOr(e){return e}match(e,r){return r(this.error)}safeUnwrap(){let e=this.error;return function*(){throw yield R(e),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(e){throw Ue("Called `_unsafeUnwrap` on an Err",this,e)}_unsafeUnwrapErr(e){return this.error}*[Symbol.iterator](){let e=this;return yield e,e}},rr=De.fromThrowable;var Ge=je(ze());var I=class extends Error{constructor(r,n={}){let{cause:o,context:i}=n;super(r,{cause:o});D(this,"context");this.name=this.constructor.name,this.context=i}};var B=class extends I{};var J=class extends B{constructor(){super(...arguments);D(this,"message","Unable to encrypt the provided data")}};var se=t=>{if(t instanceof Error)return t;let e="[Unable to stringify the thrown value]";try{e=JSON.stringify(t)}catch{}return new Error(e)};var Ot=()=>typeof Deno<"u";var G=t=>Ot()?new URL(`./worker/${t}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${t==="main"?`worker/${t}`:t}.js`));var Ke=(t,e)=>{try{let r=Ge.default.encrypt(t,te(e));return le({algo:0,data:r,iv:JSON.parse(r).iv})}catch(r){return T(new J(void 0,{cause:se(r)}))}};var Ye=(t,e)=>Mt(t).andThen(r=>{let n=crypto.getRandomValues(new Uint8Array(12));return A.fromPromise(crypto.subtle.encrypt({name:"AES-GCM",iv:n},r,e),o=>new J(void 0,{cause:se(o)})).andThen(o=>le({algo:1,data:te(o),iv:n}))}),Mt=t=>A.fromPromise(crypto.subtle.importKey("raw",be(t),{name:"AES-GCM"},!1,["encrypt","decrypt"]),e=>new B("Unable to import cryptography key",{cause:se(e)}));var $e=(t,e,r)=>{let n;return r===0?n=Ke(t,e):(typeof e=="string"&&(e=new TextEncoder().encode(e).buffer),n=Ye(t,e)),n};var ct=je(it());var Oe=new ct.default,g,st=!1;self.onmessage=t=>{Ht(t),st||(st=!0,Oe.once("OPERATION_FAILED",()=>{g&&g.terminate()}))};var Ht=(t,e)=>{let{action:r}=t.data;if(r===5||r===8)g.postMessage(t.data);else{switch(r){case 2:g=new Worker(G("cancel"),{type:"module"}),g.postMessage(t.data);break;case 3:g=new Worker(G("download"),{type:"module"}),g.postMessage(t.data);break;case 4:g=new Worker(G("infos"),{type:"module"}),g.postMessage(t.data);break;case 7:g=g||new Worker(G("remove"),{type:"module"}),g.postMessage(t.data);break;case 9:g=g||new Worker(G("upload"),{type:"module"}),g.postMessage(t.data);break;default:console.error("Action not found")}g.onmessage=n=>{e&&e(n),self.postMessage(n.data)},g.onerror=n=>{console.error(`Error: ${n.message}`)}}},at=()=>{Oe.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),Oe.once("OPERATION_FAILED",t=>{self.postMessage({event:"OPERATION_FAILED",error:t})})};var Y=class extends I{};var ce=class extends Y{constructor(){super(...arguments);D(this,"message","Parameter cannot be undefined")}};var ge=class extends Y{constructor(){super(...arguments);D(this,"message","File upload already failed")}};var ft=!1;self.onmessage=t=>{ft||(at(),ft=!0);let{lufiFile:e,chunk:r,algo:n}=t.data.args;r&&typeof n<"u"?e.uploadStatus!==2?$e(e.keys.client,r.buffer,n).map(o=>{self.postMessage({encryptedData:o,chunkIndex:r.index})}).mapErr(o=>{self.postMessage({error:o})}):self.postMessage({error:new ge("File upload already failed")}):(r||self.postMessage({error:new ce("chunk buffer cannot be undefined")}),typeof n>"u"&&self.postMessage({error:new ce("algo cannot be undefined")}))}; +var lt=Object.create;var Le=Object.defineProperty;var pt=Object.getOwnPropertyDescriptor;var dt=Object.getOwnPropertyNames;var mt=Object.getPrototypeOf,yt=Object.prototype.hasOwnProperty;var gt=(t,e,r)=>e in t?Le(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var vt=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var Me=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var wt=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of dt(e))!yt.call(t,o)&&o!==r&&Le(t,o,{get:()=>e[o],enumerable:!(n=pt(e,o))||n.enumerable});return t};var je=(t,e,r)=>(r=t!=null?lt(mt(t)):{},wt(e||!t||!t.__esModule?Le(r,"default",{value:t,enumerable:!0}):r,t));var D=(t,e,r)=>gt(t,typeof e!="symbol"?e+"":e,r);var ze=Me((or,z)=>{"use strict";var c={cipher:{},hash:{},keyexchange:{},mode:{},misc:{},codec:{},exception:{corrupt:function(t){this.toString=function(){return"CORRUPT: "+this.message},this.message=t},invalid:function(t){this.toString=function(){return"INVALID: "+this.message},this.message=t},bug:function(t){this.toString=function(){return"BUG: "+this.message},this.message=t},notReady:function(t){this.toString=function(){return"NOT READY: "+this.message},this.message=t}}};c.cipher.aes=function(t){this.w[0][0][0]||this.C();var e,r,n,o,i=this.w[0][4],s=this.w[1];e=t.length;var a=1;if(e!==4&&e!==6&&e!==8)throw new c.exception.invalid("invalid aes key size");for(this.b=[n=t.slice(0),o=[]],t=e;t<4*e+28;t++)r=n[t-1],(t%e===0||e===8&&t%e===4)&&(r=i[r>>>24]<<24^i[r>>16&255]<<16^i[r>>8&255]<<8^i[r&255],t%e===0&&(r=r<<8^r>>>24^a<<24,a=a<<1^283*(a>>7))),n[t]=n[t-e]^r;for(e=0;t;e++,t--)r=n[e&3?t:t-4],o[e]=4>=t||4>e?r:s[0][i[r>>>24]]^s[1][i[r>>16&255]]^s[2][i[r>>8&255]]^s[3][i[r&255]]};c.cipher.aes.prototype={encrypt:function(t){return We(this,t,0)},decrypt:function(t){return We(this,t,1)},w:[[[],[],[],[],[]],[[],[],[],[],[]]],C:function(){var t=this.w[0],e=this.w[1],r=t[4],n=e[4],o,i,s,a=[],f=[],u,h,l,m;for(o=0;256>o;o++)f[(a[o]=o<<1^283*(o>>7))^o]=o;for(i=s=0;!r[i];i^=u||1,s=f[s]||1)for(l=s^s<<1^s<<2^s<<3^s<<4,l=l>>8^l&255^99,r[i]=l,n[l]=i,h=a[o=a[u=a[i]]],m=16843009*h^65537*o^257*u^16843008*i,h=257*a[l]^16843008*l,o=0;4>o;o++)t[o][i]=h=h<<24^h>>>8,e[o][l]=m=m<<24^m>>>8;for(o=0;5>o;o++)t[o]=t[o].slice(0),e[o]=e[o].slice(0)}};function We(t,e,r){if(e.length!==4)throw new c.exception.invalid("invalid aes block size");var n=t.b[r],o=e[0]^n[0],i=e[r?3:1]^n[1],s=e[2]^n[2];e=e[r?1:3]^n[3];var a,f,u,h=n.length/4-2,l,m=4,p=[0,0,0,0];a=t.w[r],t=a[0];var g=a[1],b=a[2],O=a[3],j=a[4];for(l=0;l>>24]^g[i>>16&255]^b[s>>8&255]^O[e&255]^n[m],f=t[i>>>24]^g[s>>16&255]^b[e>>8&255]^O[o&255]^n[m+1],u=t[s>>>24]^g[e>>16&255]^b[o>>8&255]^O[i&255]^n[m+2],e=t[e>>>24]^g[o>>16&255]^b[i>>8&255]^O[s&255]^n[m+3],m+=4,o=a,i=f,s=u;for(l=0;4>l;l++)p[r?3&-l:l]=j[o>>>24]<<24^j[i>>16&255]<<16^j[s>>8&255]<<8^j[e&255]^n[m++],a=o,o=i,i=s,s=e,e=a;return p}c.bitArray={bitSlice:function(t,e,r){return t=c.bitArray.Y(t.slice(e/32),32-(e&31)).slice(1),r===void 0?t:c.bitArray.clamp(t,r-e)},extract:function(t,e,r){var n=Math.floor(-e-r&31);return((e+r-1^e)&-32?t[e/32|0]<<32-n^t[e/32+1|0]>>>n:t[e/32|0]>>>n)&(1<>e-1,1)),t},partial:function(t,e,r){return t===32?e:(r?e|0:e<<32-t)+1099511627776*t},getPartial:function(t){return Math.round(t/1099511627776)||32},equal:function(t,e){if(c.bitArray.bitLength(t)!==c.bitArray.bitLength(e))return!1;var r=0,n;for(n=0;n>>e),r=t[o]<<32-e;return o=t.length?t[t.length-1]:0,t=c.bitArray.getPartial(o),n.push(c.bitArray.partial(e+t&31,32>>24|r>>>8&65280|(r&65280)<<8|r<<24;return t}};c.codec.utf8String={fromBits:function(t){var e="",r=c.bitArray.bitLength(t),n,o;for(n=0;n>>8>>>8>>>8),o<<=8;return decodeURIComponent(escape(e))},toBits:function(t){t=unescape(encodeURIComponent(t));var e=[],r,n=0;for(r=0;r>>o)>>>26),6>o?(s=t[r]<<6-o,o+=26,r++):(s<<=6,o-=6);for(;n.length&3&&!e;)n+="=";return n},toBits:function(t,e){t=t.replace(/\s|=/g,"");var r=[],n,o=0,i=c.codec.base64.S,s=0,a;for(e&&(i=i.substr(0,62)+"-_"),n=0;na)throw new c.exception.invalid("this isn't base64!");26>>o),s=a<<32-o):(o+=6,s^=a<<32-o)}return o&56&&r.push(c.bitArray.partial(o&56,s,1)),r}};c.codec.base64url={fromBits:function(t){return c.codec.base64.fromBits(t,1,1)},toBits:function(t){return c.codec.base64.toBits(t,1)}};c.hash.sha256=function(t){this.b[0]||this.C(),t?(this.g=t.g.slice(0),this.f=t.f.slice(0),this.c=t.c):this.reset()};c.hash.sha256.hash=function(t){return new c.hash.sha256().update(t).finalize()};c.hash.sha256.prototype={blockSize:512,reset:function(){return this.g=this.o.slice(0),this.f=[],this.c=0,this},update:function(t){typeof t=="string"&&(t=c.codec.utf8String.toBits(t));var e,r=this.f=c.bitArray.concat(this.f,t);if(e=this.c,t=this.c=e+c.bitArray.bitLength(t),9007199254740991e;r++){for(o=!0,n=2;n*n<=r;n++)if(r%n===0){o=!1;break}o&&(8>e&&(this.o[e]=t(Math.pow(r,.5))),this.b[e]=t(Math.pow(r,1/3)),e++)}},l:function(t){var e,r,n,o=this.g,i=this.b,s=o[0],a=o[1],f=o[2],u=o[3],h=o[4],l=o[5],m=o[6],p=o[7];for(e=0;64>e;e++)16>e?r=t[e]:(r=t[e+1&15],n=t[e+14&15],r=t[e&15]=(r>>>7^r>>>18^r>>>3^r<<25^r<<14)+(n>>>17^n>>>19^n>>>10^n<<15^n<<13)+t[e&15]+t[e+9&15]|0),r=r+p+(h>>>6^h>>>11^h>>>25^h<<26^h<<21^h<<7)+(m^h&(l^m))+i[e],p=m,m=l,l=h,h=u+r|0,u=f,f=a,a=s,s=r+(a&f^u&(a^f))+(a>>>2^a>>>13^a>>>22^a<<30^a<<19^a<<10)|0;o[0]=o[0]+s|0,o[1]=o[1]+a|0,o[2]=o[2]+f|0,o[3]=o[3]+u|0,o[4]=o[4]+h|0,o[5]=o[5]+l|0,o[6]=o[6]+m|0,o[7]=o[7]+p|0}};c.hash.sha512=function(t){this.b[0]||this.C(),t?(this.g=t.g.slice(0),this.f=t.f.slice(0),this.c=t.c):this.reset()};c.hash.sha512.hash=function(t){return new c.hash.sha512().update(t).finalize()};c.hash.sha512.prototype={blockSize:1024,reset:function(){return this.g=this.o.slice(0),this.f=[],this.c=0,this},update:function(t){typeof t=="string"&&(t=c.codec.utf8String.toBits(t));var e,r=this.f=c.bitArray.concat(this.f,t);if(e=this.c,t=this.c=e+c.bitArray.bitLength(t),9007199254740991r;n++){for(i=!0,o=2;o*o<=n;o++)if(n%o===0){i=!1;break}i&&(8>r&&(this.o[2*r]=t(Math.pow(n,.5)),this.o[2*r+1]=e(Math.pow(n,.5))<<24|this.ia[r]),this.b[2*r]=t(Math.pow(n,1/3)),this.b[2*r+1]=e(Math.pow(n,1/3))<<24|this.ka[r],r++)}},l:function(t){var e,r,n=this.g,o=this.b,i=n[0],s=n[1],a=n[2],f=n[3],u=n[4],h=n[5],l=n[6],m=n[7],p=n[8],g=n[9],b=n[10],O=n[11],j=n[12],ae=n[13],Ce=n[14],fe=n[15],E;if(typeof Uint32Array<"u"){E=Array(160);for(var w=0;32>w;w++)E[w]=t[w]}else E=t;var w=i,x=s,$=a,F=f,X=u,W=h,we=l,V=m,C=p,L=g,ue=b,q=O,he=j,Q=ae,Ee=Ce,Z=fe;for(t=0;80>t;t++){if(16>t)e=E[2*t],r=E[2*t+1];else{r=E[2*(t-15)];var y=E[2*(t-15)+1];e=(y<<31|r>>>1)^(y<<24|r>>>8)^r>>>7;var S=(r<<31|y>>>1)^(r<<24|y>>>8)^(r<<25|y>>>7);r=E[2*(t-2)];var P=E[2*(t-2)+1],y=(P<<13|r>>>19)^(r<<3|P>>>29)^r>>>6,P=(r<<13|P>>>19)^(P<<3|r>>>29)^(r<<26|P>>>6),Ae=E[2*(t-7)],xe=E[2*(t-16)],ee=E[2*(t-16)+1];r=S+E[2*(t-7)+1],e=e+Ae+(r>>>0>>0?1:0),r+=P,e+=y+(r>>>0

>>0?1:0),r+=ee,e+=xe+(r>>>0>>0?1:0)}E[2*t]=e|=0,E[2*t+1]=r|=0;var Ae=C&ue^~C&he,Se=L&q^~L&Q,P=w&$^w&X^$&X,ut=x&F^x&W^F&W,xe=(x<<4|w>>>28)^(w<<30|x>>>2)^(w<<25|x>>>7),ee=(w<<4|x>>>28)^(x<<30|w>>>2)^(x<<25|w>>>7),ht=o[2*t],Pe=o[2*t+1],y=Z+((C<<18|L>>>14)^(C<<14|L>>>18)^(L<<23|C>>>9)),S=Ee+((L<<18|C>>>14)^(L<<14|C>>>18)^(C<<23|L>>>9))+(y>>>0>>0?1:0),y=y+Se,S=S+(Ae+(y>>>0>>0?1:0)),y=y+Pe,S=S+(ht+(y>>>0>>0?1:0)),y=y+r|0,S=S+(e+(y>>>0>>0?1:0));r=ee+ut,e=xe+P+(r>>>0>>0?1:0),Ee=he,Z=Q,he=ue,Q=q,ue=C,q=L,L=V+y|0,C=we+S+(L>>>0>>0?1:0)|0,we=X,V=W,X=$,W=F,$=w,F=x,x=y+r|0,w=S+e+(x>>>0>>0?1:0)|0}s=n[1]=s+x|0,n[0]=i+w+(s>>>0>>0?1:0)|0,f=n[3]=f+F|0,n[2]=a+$+(f>>>0>>0?1:0)|0,h=n[5]=h+W|0,n[4]=u+X+(h>>>0>>0?1:0)|0,m=n[7]=m+V|0,n[6]=l+we+(m>>>0>>0?1:0)|0,g=n[9]=g+L|0,n[8]=p+C+(g>>>0>>0?1:0)|0,O=n[11]=O+q|0,n[10]=b+ue+(O>>>0>>0?1:0)|0,ae=n[13]=ae+Q|0,n[12]=j+he+(ae>>>0>>0?1:0)|0,fe=n[15]=fe+Z|0,n[14]=Ce+Ee+(fe>>>0>>0?1:0)|0}};c.mode.ccm={name:"ccm",F:[],listenProgress:function(t){c.mode.ccm.F.push(t)},unListenProgress:function(t){t=c.mode.ccm.F.indexOf(t),-1f)throw new c.exception.invalid("ccm: iv must be at least 7 bytes");for(i=2;4>i&&u>>>8*i;i++);return i<15-f&&(i=15-f),r=a.clamp(r,8*(15-i)),e=c.mode.ccm.U(t,e,r,n,o,i),s=c.mode.ccm.V(t,s,r,e,o,i),a.concat(s.data,s.tag)},decrypt:function(t,e,r,n,o){o=o||64,n=n||[];var i=c.bitArray,s=i.bitLength(r)/8,u=i.bitLength(e),a=i.clamp(e,u-o),f=i.bitSlice(e,u-o),u=(u-o)/8;if(7>s)throw new c.exception.invalid("ccm: iv must be at least 7 bytes");for(e=2;4>e&&u>>>8*e;e++);if(e<15-s&&(e=15-s),r=i.clamp(r,8*(15-e)),a=c.mode.ccm.V(t,a,r,f,o,e),t=c.mode.ccm.U(t,a.data,r,n,o,e),!i.equal(a.tag,t))throw new c.exception.corrupt("ccm: tag doesn't match");return a.data},ma:function(t,e,r,n,o,i){var s=[],a=c.bitArray,f=a.P;if(n=[a.partial(8,(e.length?64:0)|n-2<<2|i-1)],n=a.concat(n,r),n[3]|=o,n=t.encrypt(n),e.length)for(r=a.bitLength(e)/8,65279>=r?s=[a.partial(16,r)]:4294967295>=r&&(s=a.concat([a.partial(16,65534)],[r])),s=a.concat(s,e),e=0;eo||16h&&(c.mode.ccm.da(s/f),h+=l),r[3]++,o=t.encrypt(r),e[s]^=o[0],e[s+1]^=o[1],e[s+2]^=o[2],e[s+3]^=o[3];return{tag:n,data:a.clamp(e,u)}}};c.misc.hmac=function(t,e){this.W=e=e||c.hash.sha256;var r=[[],[]],n,o=e.prototype.blockSize/32;for(this.B=[new e,new e],t.length>o&&(t=e.hash(t)),n=0;nn||0>r)throw new c.exception.invalid("invalid params to pbkdf2");typeof t=="string"&&(t=c.codec.utf8String.toBits(t)),typeof e=="string"&&(e=c.codec.utf8String.toBits(e)),o=o||c.misc.hmac,t=new o(t);var i,s,a,f,u=[],h=c.bitArray;for(f=1;32*u.length<(n||1);f++){for(o=i=t.encrypt(h.concat(e,[f])),s=1;ss;s++)o.push(4294967296*Math.random()|0);for(s=0;s=1<this.u&&(this.u=i),this.N++,this.b=c.hash.sha256.hash(this.b.concat(o)),this.K=new c.cipher.aes(this.b),n=0;4>n&&(this.m[n]=this.m[n]+1|0,!this.m[n]);n++);}for(n=0;n>>1;this.h[s].update([n,this.M++,2,e,i,t.length].concat(t))}break;case"string":e===void 0&&(e=t.length),this.h[s].update([n,this.M++,3,e,i,t.length]),this.h[s].update(t);break;default:f=1}if(f)throw new c.exception.bug("random: addEntropy only supports number, array of numbers or string");this.s[s]+=e,this.i+=e,a===this.A&&(this.isReady()!==this.A&&Ne("seeded",Math.max(this.u,this.i)),Ne("progress",this.getProgress()))},isReady:function(t){return t=this.R[t!==void 0?t:this.L],this.u&&this.u>=t?this.s[0]>this.$&&new Date().valueOf()>this.X?this.I|this.H:this.H:this.i>=t?this.I|this.A:this.A},getProgress:function(t){return t=this.R[t||this.L],this.u>=t||this.i>t?1:this.i/t},startCollectors:function(){if(!this.D){if(this.a={loadTimeCollector:ne(this,this.la),mouseCollector:ne(this,this.na),keyboardCollector:ne(this,this.ja),accelerometerCollector:ne(this,this.ca),touchCollector:ne(this,this.pa)},window.addEventListener)window.addEventListener("load",this.a.loadTimeCollector,!1),window.addEventListener("mousemove",this.a.mouseCollector,!1),window.addEventListener("keypress",this.a.keyboardCollector,!1),window.addEventListener("devicemotion",this.a.accelerometerCollector,!1),window.addEventListener("touchmove",this.a.touchCollector,!1);else if(document.attachEvent)document.attachEvent("onload",this.a.loadTimeCollector),document.attachEvent("onmousemove",this.a.mouseCollector),document.attachEvent("keypress",this.a.keyboardCollector);else throw new c.exception.bug("can't attach event");this.D=!0}},stopCollectors:function(){this.D&&(window.removeEventListener?(window.removeEventListener("load",this.a.loadTimeCollector,!1),window.removeEventListener("mousemove",this.a.mouseCollector,!1),window.removeEventListener("keypress",this.a.keyboardCollector,!1),window.removeEventListener("devicemotion",this.a.accelerometerCollector,!1),window.removeEventListener("touchmove",this.a.touchCollector,!1)):document.detachEvent&&(document.detachEvent("onload",this.a.loadTimeCollector),document.detachEvent("onmousemove",this.a.mouseCollector),document.detachEvent("keypress",this.a.keyboardCollector)),this.D=!1)},addEventListener:function(t,e){this.J[t][this.ea++]=e},removeEventListener:function(t,e){var r,n,o=this.J[t],i=[];for(n in o)o.hasOwnProperty(n)&&o[n]===e&&i.push(n);for(r=0;re&&(t.m[e]=t.m[e]+1|0,!t.m[e]);e++);return t.K.encrypt(t.m)}function ne(t,e){return function(){e.apply(t,arguments)}}c.random=new c.prng(6);e:try{if(de=typeof z<"u"&&z.exports){try{me=vt("crypto")}catch{me=null}de=pe=me}if(de&&pe.randomBytes)oe=pe.randomBytes(128),oe=new Uint32Array(new Uint8Array(oe).buffer),c.random.addEntropy(oe,1024,"crypto['randomBytes']");else if(typeof window<"u"&&typeof Uint32Array<"u"){if(ie=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(ie);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(ie);else break e;c.random.addEntropy(ie,1024,"crypto['getRandomValues']")}}catch(t){typeof window<"u"&&window.console&&(console.log("There was an error collecting entropy from the browser:"),console.log(t))}var oe,pe,ie,de,me;c.json={defaults:{v:1,iter:1e4,ks:128,ts:64,mode:"ccm",adata:"",cipher:"aes"},ha:function(t,e,r,n){r=r||{},n=n||{};var o=c.json,i=o.j({iv:c.random.randomWords(4,0)},o.defaults),s;if(o.j(i,r),r=i.adata,typeof i.salt=="string"&&(i.salt=c.codec.base64.toBits(i.salt)),typeof i.iv=="string"&&(i.iv=c.codec.base64.toBits(i.iv)),!c.mode[i.mode]||!c.cipher[i.cipher]||typeof t=="string"&&100>=i.iter||i.ts!==64&&i.ts!==96&&i.ts!==128||i.ks!==128&&i.ks!==192&&i.ks!==256||2>i.iv.length||4=e.iter||e.ts!==64&&e.ts!==96&&e.ts!==128||e.ks!==128&&e.ks!==192&&e.ks!==256||!e.iv||2>e.iv.length||4{"use strict";var K=typeof Reflect=="object"?Reflect:null,Xe=K&&typeof K.apply=="function"?K.apply:function(e,r,n){return Function.prototype.apply.call(e,r,n)},ye;K&&typeof K.ownKeys=="function"?ye=K.ownKeys:Object.getOwnPropertySymbols?ye=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:ye=function(e){return Object.getOwnPropertyNames(e)};function Bt(t){console&&console.warn&&console.warn(t)}var qe=Number.isNaN||function(e){return e!==e};function d(){d.init.call(this)}_e.exports=d;_e.exports.once=Ft;d.EventEmitter=d;d.prototype._events=void 0;d.prototype._eventsCount=0;d.prototype._maxListeners=void 0;var Ve=10;function ge(t){if(typeof t!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t)}Object.defineProperty(d,"defaultMaxListeners",{enumerable:!0,get:function(){return Ve},set:function(t){if(typeof t!="number"||t<0||qe(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");Ve=t}});d.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0};d.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||qe(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this};function Qe(t){return t._maxListeners===void 0?d.defaultMaxListeners:t._maxListeners}d.prototype.getMaxListeners=function(){return Qe(this)};d.prototype.emit=function(e){for(var r=[],n=1;n0&&(s=r[0]),s instanceof Error)throw s;var a=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw a.context=s,a}var f=i[e];if(f===void 0)return!1;if(typeof f=="function")Xe(f,this,r);else for(var u=f.length,h=nt(f,u),n=0;n0&&s.length>o&&!s.warned){s.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning",a.emitter=t,a.type=e,a.count=s.length,Bt(a)}return t}d.prototype.addListener=function(e,r){return Ze(this,e,r,!1)};d.prototype.on=d.prototype.addListener;d.prototype.prependListener=function(e,r){return Ze(this,e,r,!0)};function It(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function et(t,e,r){var n={fired:!1,wrapFn:void 0,target:t,type:e,listener:r},o=It.bind(n);return o.listener=r,n.wrapFn=o,o}d.prototype.once=function(e,r){return ge(r),this.on(e,et(this,e,r)),this};d.prototype.prependOnceListener=function(e,r){return ge(r),this.prependListener(e,et(this,e,r)),this};d.prototype.removeListener=function(e,r){var n,o,i,s,a;if(ge(r),o=this._events,o===void 0)return this;if(n=o[e],n===void 0)return this;if(n===r||n.listener===r)--this._eventsCount===0?this._events=Object.create(null):(delete o[e],o.removeListener&&this.emit("removeListener",e,n.listener||r));else if(typeof n!="function"){for(i=-1,s=n.length-1;s>=0;s--)if(n[s]===r||n[s].listener===r){a=n[s].listener,i=s;break}if(i<0)return this;i===0?n.shift():Ut(n,i),n.length===1&&(o[e]=n[0]),o.removeListener!==void 0&&this.emit("removeListener",e,a||r)}return this};d.prototype.off=d.prototype.removeListener;d.prototype.removeAllListeners=function(e){var r,n,o;if(n=this._events,n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[e]),this;if(arguments.length===0){var i=Object.keys(n),s;for(o=0;o=0;o--)this.removeListener(e,r[o]);return this};function tt(t,e,r){var n=t._events;if(n===void 0)return[];var o=n[e];return o===void 0?[]:typeof o=="function"?r?[o.listener||o]:[o]:r?Tt(o):nt(o,o.length)}d.prototype.listeners=function(e){return tt(this,e,!0)};d.prototype.rawListeners=function(e){return tt(this,e,!1)};d.listenerCount=function(t,e){return typeof t.listenerCount=="function"?t.listenerCount(e):rt.call(t,e)};d.prototype.listenerCount=rt;function rt(t){var e=this._events;if(e!==void 0){var r=e[t];if(typeof r=="function")return 1;if(r!==void 0)return r.length}return 0}d.prototype.eventNames=function(){return this._eventsCount>0?ye(this._events):[]};function nt(t,e){for(var r=new Array(e),n=0;n>2]+this._charset[(n[i]&3)<<4|n[i+1]>>4]+this._charset[(n[i+1]&15)<<2|n[i+2]>>6]+this._charset[n[i+2]&63];return r%3==2?(o=o.substring(0,o.length-1),this._noPadding||(o+="=")):r%3==1&&(o=o.substring(0,o.length-2),this._noPadding||(o+="==")),o}Decode(e){if(e=(e||"").replace(/[\s]/g,""),!e)return new ArrayBuffer(0);if(!this._valid.test(e))throw Error("Invalid base64 input sequence");let r=Math.floor(e.length*.75);e[e.length-2]=="="?r-=2:e[e.length-1]=="="&&r--;let n=new Uint8Array(r),o,i,s,a,f=0,u=0;for(;f>4,n[f++]=(i&15)<<4|s>>2,n[f++]=(s&3)<<6|a;return n.buffer}};var Et=new N("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");function te(t){return Et.Encode(t)}var At=new N("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",!0);function be(t){return At.Decode(t)}var Lt={withStackTrace:!1},Ue=(t,e,r=Lt)=>{let n=e.isOk()?{type:"Ok",value:e.value}:{type:"Err",value:e.error},o=r.withStackTrace?new Error().stack:void 0;return{data:n,message:t,stack:o}};function H(t,e,r,n){function o(i){return i instanceof r?i:new r(function(s){s(i)})}return new(r||(r=Promise))(function(i,s){function a(h){try{u(n.next(h))}catch(l){s(l)}}function f(h){try{u(n.throw(h))}catch(l){s(l)}}function u(h){h.done?i(h.value):o(h.value).then(a,f)}u((n=n.apply(t,e||[])).next())})}function Be(t){var e=typeof Symbol=="function"&&Symbol.iterator,r=e&&t[e],n=0;if(r)return r.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function M(t){return this instanceof M?(this.v=t,this):new M(t)}function Ie(t,e,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=r.apply(t,e||[]),o,i=[];return o=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),a("next"),a("throw"),a("return",s),o[Symbol.asyncIterator]=function(){return this},o;function s(p){return function(g){return Promise.resolve(g).then(p,l)}}function a(p,g){n[p]&&(o[p]=function(b){return new Promise(function(O,j){i.push([p,b,O,j])>1||f(p,b)})},g&&(o[p]=g(o[p])))}function f(p,g){try{u(n[p](g))}catch(b){m(i[0][3],b)}}function u(p){p.value instanceof M?Promise.resolve(p.value.v).then(h,l):m(i[0][2],p)}function h(p){f("next",p)}function l(p){f("throw",p)}function m(p,g){p(g),i.shift(),i.length&&f(i[0][0],i[0][1])}}function bt(t){var e,r;return e={},n("next"),n("throw",function(o){throw o}),n("return"),e[Symbol.iterator]=function(){return this},e;function n(o,i){e[o]=t[o]?function(s){return(r=!r)?{value:M(t[o](s)),done:!1}:i?i(s):s}:i}}function Dt(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e=t[Symbol.asyncIterator],r;return e?e.call(t):(t=typeof Be=="function"?Be(t):t[Symbol.iterator](),r={},n("next"),n("throw"),n("return"),r[Symbol.asyncIterator]=function(){return this},r);function n(i){r[i]=t[i]&&function(s){return new Promise(function(a,f){s=t[i](s),o(a,f,s.done,s.value)})}}function o(i,s,a,f){Promise.resolve(f).then(function(u){i({value:u,done:a})},s)}}var A=class t{constructor(e){this._promise=e}static fromSafePromise(e){let r=e.then(n=>new k(n));return new t(r)}static fromPromise(e,r){let n=e.then(o=>new k(o)).catch(o=>new _(r(o)));return new t(n)}static fromThrowable(e,r){return(...n)=>new t(H(this,void 0,void 0,function*(){try{return new k(yield e(...n))}catch(o){return new _(r?r(o):o)}}))}static combine(e){return kt(e)}static combineWithAllErrors(e){return _t(e)}map(e){return new t(this._promise.then(r=>H(this,void 0,void 0,function*(){return r.isErr()?new _(r.error):new k(yield e(r.value))})))}andThrough(e){return new t(this._promise.then(r=>H(this,void 0,void 0,function*(){if(r.isErr())return new _(r.error);let n=yield e(r.value);return n.isErr()?new _(n.error):new k(r.value)})))}andTee(e){return new t(this._promise.then(r=>H(this,void 0,void 0,function*(){if(r.isErr())return new _(r.error);try{yield e(r.value)}catch{}return new k(r.value)})))}mapErr(e){return new t(this._promise.then(r=>H(this,void 0,void 0,function*(){return r.isOk()?new k(r.value):new _(yield e(r.error))})))}andThen(e){return new t(this._promise.then(r=>{if(r.isErr())return new _(r.error);let n=e(r.value);return n instanceof t?n._promise:n}))}orElse(e){return new t(this._promise.then(r=>H(this,void 0,void 0,function*(){return r.isErr()?e(r.error):new k(r.value)})))}match(e,r){return this._promise.then(n=>n.match(e,r))}unwrapOr(e){return this._promise.then(r=>r.unwrapOr(e))}safeUnwrap(){return Ie(this,arguments,function*(){return yield M(yield M(yield*bt(Dt(yield M(this._promise.then(r=>r.safeUnwrap()))))))})}then(e,r){return this._promise.then(e,r)}[Symbol.asyncIterator](){return Ie(this,arguments,function*(){let r=yield M(this._promise);return r.isErr()&&(yield yield M(T(r.error))),yield M(r.value)})}},le=t=>new A(Promise.resolve(new k(t))),T=t=>new A(Promise.resolve(new _(t))),Zt=A.fromPromise,er=A.fromSafePromise,tr=A.fromThrowable,Te=t=>{let e=U([]);for(let r of t)if(r.isErr()){e=R(r.error);break}else e.map(n=>n.push(r.value));return e},kt=t=>A.fromSafePromise(Promise.all(t)).andThen(Te),Fe=t=>{let e=U([]);for(let r of t)r.isErr()&&e.isErr()?e.error.push(r.error):r.isErr()&&e.isOk()?e=R([r.error]):r.isOk()&&e.isOk()&&e.value.push(r.value);return e},_t=t=>A.fromSafePromise(Promise.all(t)).andThen(Fe),De;(function(t){function e(o,i){return(...s)=>{try{let a=o(...s);return U(a)}catch(a){return R(i?i(a):a)}}}t.fromThrowable=e;function r(o){return Te(o)}t.combine=r;function n(o){return Fe(o)}t.combineWithAllErrors=n})(De||(De={}));var U=t=>new k(t);function R(t){return new _(t)}var k=class{constructor(e){this.value=e}isOk(){return!0}isErr(){return!this.isOk()}map(e){return U(e(this.value))}mapErr(e){return U(this.value)}andThen(e){return e(this.value)}andThrough(e){return e(this.value).map(r=>this.value)}andTee(e){try{e(this.value)}catch{}return U(this.value)}orElse(e){return U(this.value)}asyncAndThen(e){return e(this.value)}asyncAndThrough(e){return e(this.value).map(()=>this.value)}asyncMap(e){return A.fromSafePromise(e(this.value))}unwrapOr(e){return this.value}match(e,r){return e(this.value)}safeUnwrap(){let e=this.value;return function*(){return e}()}_unsafeUnwrap(e){return this.value}_unsafeUnwrapErr(e){throw Ue("Called `_unsafeUnwrapErr` on an Ok",this,e)}*[Symbol.iterator](){return this.value}},_=class{constructor(e){this.error=e}isOk(){return!1}isErr(){return!this.isOk()}map(e){return R(this.error)}mapErr(e){return R(e(this.error))}andThrough(e){return R(this.error)}andTee(e){return R(this.error)}andThen(e){return R(this.error)}orElse(e){return e(this.error)}asyncAndThen(e){return T(this.error)}asyncAndThrough(e){return T(this.error)}asyncMap(e){return T(this.error)}unwrapOr(e){return e}match(e,r){return r(this.error)}safeUnwrap(){let e=this.error;return function*(){throw yield R(e),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(e){throw Ue("Called `_unsafeUnwrap` on an Err",this,e)}_unsafeUnwrapErr(e){return this.error}*[Symbol.iterator](){let e=this;return yield e,e}},rr=De.fromThrowable;var Ge=je(ze());var I=class extends Error{constructor(r,n={}){let{cause:o,context:i}=n;super(r,{cause:o});D(this,"context");this.name=this.constructor.name,this.context=i}};var B=class extends I{};var J=class extends B{constructor(){super(...arguments);D(this,"message","Unable to encrypt the provided data")}};var se=t=>{if(t instanceof Error)return t;let e="[Unable to stringify the thrown value]";try{e=JSON.stringify(t)}catch{}return new Error(e)};var Ot=()=>typeof Deno<"u";var G=t=>Ot()?new URL(`./worker/${t}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${t==="main"?`worker/${t}`:t}.js`));var Ke=(t,e)=>{try{let r=Ge.default.encrypt(t,te(e));return le({algo:0,data:r,iv:JSON.parse(r).iv})}catch(r){return T(new J(void 0,{cause:se(r)}))}};var Ye=(t,e)=>Mt(t).andThen(r=>{let n=crypto.getRandomValues(new Uint8Array(12));return A.fromPromise(crypto.subtle.encrypt({name:"AES-GCM",iv:n},r,e),o=>new J(void 0,{cause:se(o)})).andThen(o=>le({algo:1,data:te(o),iv:n}))}),Mt=t=>A.fromPromise(crypto.subtle.importKey("raw",be(t),{name:"AES-GCM"},!1,["encrypt","decrypt"]),e=>new B("Unable to import cryptography key",{cause:se(e)}));var $e=(t,e,r)=>{let n;return r===0?n=Ke(t,e):(typeof e=="string"&&(e=new TextEncoder().encode(e).buffer),n=Ye(t,e)),n};var ct=je(it());var Oe=new ct.default,v,st=!1;self.onmessage=t=>{Ht(t),st||(st=!0,Oe.once("OPERATION_FAILED",()=>{v&&v.terminate()}))};var Ht=(t,e)=>{let{action:r}=t.data;if(r===5||r===8)v.postMessage(t.data,t.data);else{switch(r){case 2:v=new Worker(G("cancel"),{type:"module"}),v.postMessage(t.data,t.data);break;case 3:v=new Worker(G("download"),{type:"module"}),v.postMessage(t.data,t.data);break;case 4:v=new Worker(G("infos"),{type:"module"}),v.postMessage(t.data,t.data);break;case 7:v=v||new Worker(G("remove"),{type:"module"}),v.postMessage(t.data,t.data);break;case 9:v=v||new Worker(G("upload"),{type:"module"}),v.postMessage(t.data,t.data);break;default:console.error("Action not found")}v.onmessage=n=>{e&&e(n),self.postMessage(n.data,n.data)},v.onerror=n=>{console.error(`Error: ${n.message}`)}}},at=()=>{Oe.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),Oe.once("OPERATION_FAILED",t=>{self.postMessage({event:"OPERATION_FAILED",error:t})})};var Y=class extends I{};var ce=class extends Y{constructor(){super(...arguments);D(this,"message","Parameter cannot be undefined")}};var ve=class extends Y{constructor(){super(...arguments);D(this,"message","File upload already failed")}};var ft=!1;self.onmessage=t=>{ft||(at(),ft=!0);let{lufiFile:e,chunk:r,algo:n}=t.data.args;r&&typeof n<"u"?e.uploadStatus!==2?$e(e.keys.client,r.buffer,n).map(o=>{self.postMessage({encryptedData:o,chunkIndex:r.index})}).mapErr(o=>{self.postMessage({error:o})}):self.postMessage({error:new ve("File upload already failed")}):(r||self.postMessage({error:new ce("chunk buffer cannot be undefined")}),typeof n>"u"&&self.postMessage({error:new ce("algo cannot be undefined")}))}; diff --git a/themes/default/public/js/worker/infos.js b/themes/default/public/js/worker/infos.js index 8f12efc..1573ba2 100644 --- a/themes/default/public/js/worker/infos.js +++ b/themes/default/public/js/worker/infos.js @@ -1 +1 @@ -var Et=Object.create;var be=Object.defineProperty;var At=Object.getOwnPropertyDescriptor;var Lt=Object.getOwnPropertyNames;var Ot=Object.getPrototypeOf,xt=Object.prototype.hasOwnProperty;var Dt=(e,t,r)=>t in e?be(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var bt=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,r)=>(typeof require<"u"?require:t)[r]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var Ue=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var kt=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Lt(t))!xt.call(e,o)&&o!==r&&be(e,o,{get:()=>t[o],enumerable:!(n=At(t,o))||n.enumerable});return e};var je=(e,t,r)=>(r=e!=null?Et(Ot(e)):{},kt(t||!e||!e.__esModule?be(r,"default",{value:e,enumerable:!0}):r,e));var T=(e,t,r)=>Dt(e,typeof t!="symbol"?t+"":t,r);var Ze=Ue((jr,Se)=>{"use strict";var V=typeof Reflect=="object"?Reflect:null,ze=V&&typeof V.apply=="function"?V.apply:function(t,r,n){return Function.prototype.apply.call(t,r,n)},ye;V&&typeof V.ownKeys=="function"?ye=V.ownKeys:Object.getOwnPropertySymbols?ye=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:ye=function(t){return Object.getOwnPropertyNames(t)};function Tt(e){console&&console.warn&&console.warn(e)}var Xe=Number.isNaN||function(t){return t!==t};function p(){p.init.call(this)}Se.exports=p;Se.exports.once=Nt;p.EventEmitter=p;p.prototype._events=void 0;p.prototype._eventsCount=0;p.prototype._maxListeners=void 0;var He=10;function ve(e){if(typeof e!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}Object.defineProperty(p,"defaultMaxListeners",{enumerable:!0,get:function(){return He},set:function(e){if(typeof e!="number"||e<0||Xe(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");He=e}});p.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0};p.prototype.setMaxListeners=function(t){if(typeof t!="number"||t<0||Xe(t))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+t+".");return this._maxListeners=t,this};function Ge(e){return e._maxListeners===void 0?p.defaultMaxListeners:e._maxListeners}p.prototype.getMaxListeners=function(){return Ge(this)};p.prototype.emit=function(t){for(var r=[],n=1;n0&&(s=r[0]),s instanceof Error)throw s;var c=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw c.context=s,c}var u=i[t];if(u===void 0)return!1;if(typeof u=="function")ze(u,this,r);else for(var f=u.length,h=qe(u,f),n=0;n0&&s.length>o&&!s.warned){s.warned=!0;var c=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");c.name="MaxListenersExceededWarning",c.emitter=e,c.type=t,c.count=s.length,Tt(c)}return e}p.prototype.addListener=function(t,r){return $e(this,t,r,!1)};p.prototype.on=p.prototype.addListener;p.prototype.prependListener=function(t,r){return $e(this,t,r,!0)};function It(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function Ve(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},o=It.bind(n);return o.listener=r,n.wrapFn=o,o}p.prototype.once=function(t,r){return ve(r),this.on(t,Ve(this,t,r)),this};p.prototype.prependOnceListener=function(t,r){return ve(r),this.prependListener(t,Ve(this,t,r)),this};p.prototype.removeListener=function(t,r){var n,o,i,s,c;if(ve(r),o=this._events,o===void 0)return this;if(n=o[t],n===void 0)return this;if(n===r||n.listener===r)--this._eventsCount===0?this._events=Object.create(null):(delete o[t],o.removeListener&&this.emit("removeListener",t,n.listener||r));else if(typeof n!="function"){for(i=-1,s=n.length-1;s>=0;s--)if(n[s]===r||n[s].listener===r){c=n[s].listener,i=s;break}if(i<0)return this;i===0?n.shift():Ut(n,i),n.length===1&&(o[t]=n[0]),o.removeListener!==void 0&&this.emit("removeListener",t,c||r)}return this};p.prototype.off=p.prototype.removeListener;p.prototype.removeAllListeners=function(t){var r,n,o;if(n=this._events,n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[t]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[t]),this;if(arguments.length===0){var i=Object.keys(n),s;for(o=0;o=0;o--)this.removeListener(t,r[o]);return this};function Ye(e,t,r){var n=e._events;if(n===void 0)return[];var o=n[t];return o===void 0?[]:typeof o=="function"?r?[o.listener||o]:[o]:r?jt(o):qe(o,o.length)}p.prototype.listeners=function(t){return Ye(this,t,!0)};p.prototype.rawListeners=function(t){return Ye(this,t,!1)};p.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):Ke.call(e,t)};p.prototype.listenerCount=Ke;function Ke(e){var t=this._events;if(t!==void 0){var r=t[e];if(typeof r=="function")return 1;if(r!==void 0)return r.length}return 0}p.prototype.eventNames=function(){return this._eventsCount>0?ye(this._events):[]};function qe(e,t){for(var r=new Array(t),n=0;n{"use strict";var a={cipher:{},hash:{},keyexchange:{},mode:{},misc:{},codec:{},exception:{corrupt:function(e){this.toString=function(){return"CORRUPT: "+this.message},this.message=e},invalid:function(e){this.toString=function(){return"INVALID: "+this.message},this.message=e},bug:function(e){this.toString=function(){return"BUG: "+this.message},this.message=e},notReady:function(e){this.toString=function(){return"NOT READY: "+this.message},this.message=e}}};a.cipher.aes=function(e){this.w[0][0][0]||this.C();var t,r,n,o,i=this.w[0][4],s=this.w[1];t=e.length;var c=1;if(t!==4&&t!==6&&t!==8)throw new a.exception.invalid("invalid aes key size");for(this.b=[n=e.slice(0),o=[]],e=t;e<4*t+28;e++)r=n[e-1],(e%t===0||t===8&&e%t===4)&&(r=i[r>>>24]<<24^i[r>>16&255]<<16^i[r>>8&255]<<8^i[r&255],e%t===0&&(r=r<<8^r>>>24^c<<24,c=c<<1^283*(c>>7))),n[e]=n[e-t]^r;for(t=0;e;t++,e--)r=n[t&3?e:e-4],o[t]=4>=e||4>t?r:s[0][i[r>>>24]]^s[1][i[r>>16&255]]^s[2][i[r>>8&255]]^s[3][i[r&255]]};a.cipher.aes.prototype={encrypt:function(e){return it(this,e,0)},decrypt:function(e){return it(this,e,1)},w:[[[],[],[],[],[]],[[],[],[],[],[]]],C:function(){var e=this.w[0],t=this.w[1],r=e[4],n=t[4],o,i,s,c=[],u=[],f,h,l,y;for(o=0;256>o;o++)u[(c[o]=o<<1^283*(o>>7))^o]=o;for(i=s=0;!r[i];i^=f||1,s=u[s]||1)for(l=s^s<<1^s<<2^s<<3^s<<4,l=l>>8^l&255^99,r[i]=l,n[l]=i,h=c[o=c[f=c[i]]],y=16843009*h^65537*o^257*f^16843008*i,h=257*c[l]^16843008*l,o=0;4>o;o++)e[o][i]=h=h<<24^h>>>8,t[o][l]=y=y<<24^y>>>8;for(o=0;5>o;o++)e[o]=e[o].slice(0),t[o]=t[o].slice(0)}};function it(e,t,r){if(t.length!==4)throw new a.exception.invalid("invalid aes block size");var n=e.b[r],o=t[0]^n[0],i=t[r?3:1]^n[1],s=t[2]^n[2];t=t[r?1:3]^n[3];var c,u,f,h=n.length/4-2,l,y=4,d=[0,0,0,0];c=e.w[r],e=c[0];var g=c[1],k=c[2],C=c[3],N=c[4];for(l=0;l>>24]^g[i>>16&255]^k[s>>8&255]^C[t&255]^n[y],u=e[i>>>24]^g[s>>16&255]^k[t>>8&255]^C[o&255]^n[y+1],f=e[s>>>24]^g[t>>16&255]^k[o>>8&255]^C[i&255]^n[y+2],t=e[t>>>24]^g[o>>16&255]^k[i>>8&255]^C[s&255]^n[y+3],y+=4,o=c,i=u,s=f;for(l=0;4>l;l++)d[r?3&-l:l]=N[o>>>24]<<24^N[i>>16&255]<<16^N[s>>8&255]<<8^N[t&255]^n[y++],c=o,o=i,i=s,s=t,t=c;return d}a.bitArray={bitSlice:function(e,t,r){return e=a.bitArray.Y(e.slice(t/32),32-(t&31)).slice(1),r===void 0?e:a.bitArray.clamp(e,r-t)},extract:function(e,t,r){var n=Math.floor(-t-r&31);return((t+r-1^t)&-32?e[t/32|0]<<32-n^e[t/32+1|0]>>>n:e[t/32|0]>>>n)&(1<>t-1,1)),e},partial:function(e,t,r){return e===32?t:(r?t|0:t<<32-e)+1099511627776*e},getPartial:function(e){return Math.round(e/1099511627776)||32},equal:function(e,t){if(a.bitArray.bitLength(e)!==a.bitArray.bitLength(t))return!1;var r=0,n;for(n=0;n>>t),r=e[o]<<32-t;return o=e.length?e[e.length-1]:0,e=a.bitArray.getPartial(o),n.push(a.bitArray.partial(t+e&31,32>>24|r>>>8&65280|(r&65280)<<8|r<<24;return e}};a.codec.utf8String={fromBits:function(e){var t="",r=a.bitArray.bitLength(e),n,o;for(n=0;n>>8>>>8>>>8),o<<=8;return decodeURIComponent(escape(t))},toBits:function(e){e=unescape(encodeURIComponent(e));var t=[],r,n=0;for(r=0;r>>o)>>>26),6>o?(s=e[r]<<6-o,o+=26,r++):(s<<=6,o-=6);for(;n.length&3&&!t;)n+="=";return n},toBits:function(e,t){e=e.replace(/\s|=/g,"");var r=[],n,o=0,i=a.codec.base64.S,s=0,c;for(t&&(i=i.substr(0,62)+"-_"),n=0;nc)throw new a.exception.invalid("this isn't base64!");26>>o),s=c<<32-o):(o+=6,s^=c<<32-o)}return o&56&&r.push(a.bitArray.partial(o&56,s,1)),r}};a.codec.base64url={fromBits:function(e){return a.codec.base64.fromBits(e,1,1)},toBits:function(e){return a.codec.base64.toBits(e,1)}};a.hash.sha256=function(e){this.b[0]||this.C(),e?(this.g=e.g.slice(0),this.f=e.f.slice(0),this.c=e.c):this.reset()};a.hash.sha256.hash=function(e){return new a.hash.sha256().update(e).finalize()};a.hash.sha256.prototype={blockSize:512,reset:function(){return this.g=this.o.slice(0),this.f=[],this.c=0,this},update:function(e){typeof e=="string"&&(e=a.codec.utf8String.toBits(e));var t,r=this.f=a.bitArray.concat(this.f,e);if(t=this.c,e=this.c=t+a.bitArray.bitLength(e),9007199254740991t;r++){for(o=!0,n=2;n*n<=r;n++)if(r%n===0){o=!1;break}o&&(8>t&&(this.o[t]=e(Math.pow(r,.5))),this.b[t]=e(Math.pow(r,1/3)),t++)}},l:function(e){var t,r,n,o=this.g,i=this.b,s=o[0],c=o[1],u=o[2],f=o[3],h=o[4],l=o[5],y=o[6],d=o[7];for(t=0;64>t;t++)16>t?r=e[t]:(r=e[t+1&15],n=e[t+14&15],r=e[t&15]=(r>>>7^r>>>18^r>>>3^r<<25^r<<14)+(n>>>17^n>>>19^n>>>10^n<<15^n<<13)+e[t&15]+e[t+9&15]|0),r=r+d+(h>>>6^h>>>11^h>>>25^h<<26^h<<21^h<<7)+(y^h&(l^y))+i[t],d=y,y=l,l=h,h=f+r|0,f=u,u=c,c=s,s=r+(c&u^f&(c^u))+(c>>>2^c>>>13^c>>>22^c<<30^c<<19^c<<10)|0;o[0]=o[0]+s|0,o[1]=o[1]+c|0,o[2]=o[2]+u|0,o[3]=o[3]+f|0,o[4]=o[4]+h|0,o[5]=o[5]+l|0,o[6]=o[6]+y|0,o[7]=o[7]+d|0}};a.hash.sha512=function(e){this.b[0]||this.C(),e?(this.g=e.g.slice(0),this.f=e.f.slice(0),this.c=e.c):this.reset()};a.hash.sha512.hash=function(e){return new a.hash.sha512().update(e).finalize()};a.hash.sha512.prototype={blockSize:1024,reset:function(){return this.g=this.o.slice(0),this.f=[],this.c=0,this},update:function(e){typeof e=="string"&&(e=a.codec.utf8String.toBits(e));var t,r=this.f=a.bitArray.concat(this.f,e);if(t=this.c,e=this.c=t+a.bitArray.bitLength(e),9007199254740991r;n++){for(i=!0,o=2;o*o<=n;o++)if(n%o===0){i=!1;break}i&&(8>r&&(this.o[2*r]=e(Math.pow(n,.5)),this.o[2*r+1]=t(Math.pow(n,.5))<<24|this.ia[r]),this.b[2*r]=e(Math.pow(n,1/3)),this.b[2*r+1]=t(Math.pow(n,1/3))<<24|this.ka[r],r++)}},l:function(e){var t,r,n=this.g,o=this.b,i=n[0],s=n[1],c=n[2],u=n[3],f=n[4],h=n[5],l=n[6],y=n[7],d=n[8],g=n[9],k=n[10],C=n[11],N=n[12],le=n[13],Me=n[14],de=n[15],L;if(typeof Uint32Array<"u"){L=Array(160);for(var E=0;32>E;E++)L[E]=e[E]}else L=e;var E=i,D=s,Z=c,H=u,ee=f,X=h,Le=l,te=y,R=d,b=g,pe=k,re=C,me=N,ne=le,Oe=Me,oe=de;for(e=0;80>e;e++){if(16>e)t=L[2*e],r=L[2*e+1];else{r=L[2*(e-15)];var v=L[2*(e-15)+1];t=(v<<31|r>>>1)^(v<<24|r>>>8)^r>>>7;var P=(r<<31|v>>>1)^(r<<24|v>>>8)^(r<<25|v>>>7);r=L[2*(e-2)];var M=L[2*(e-2)+1],v=(M<<13|r>>>19)^(r<<3|M>>>29)^r>>>6,M=(r<<13|M>>>19)^(M<<3|r>>>29)^(r<<26|M>>>6),xe=L[2*(e-7)],De=L[2*(e-16)],ie=L[2*(e-16)+1];r=P+L[2*(e-7)+1],t=t+xe+(r>>>0

>>0?1:0),r+=M,t+=v+(r>>>0>>0?1:0),r+=ie,t+=De+(r>>>0>>0?1:0)}L[2*e]=t|=0,L[2*e+1]=r|=0;var xe=R&pe^~R&me,Te=b&re^~b&ne,M=E&Z^E&ee^Z&ee,gt=D&H^D&X^H&X,De=(D<<4|E>>>28)^(E<<30|D>>>2)^(E<<25|D>>>7),ie=(E<<4|D>>>28)^(D<<30|E>>>2)^(D<<25|E>>>7),wt=o[2*e],Ie=o[2*e+1],v=oe+((R<<18|b>>>14)^(R<<14|b>>>18)^(b<<23|R>>>9)),P=Oe+((b<<18|R>>>14)^(b<<14|R>>>18)^(R<<23|b>>>9))+(v>>>0>>0?1:0),v=v+Te,P=P+(xe+(v>>>0>>0?1:0)),v=v+Ie,P=P+(wt+(v>>>0>>0?1:0)),v=v+r|0,P=P+(t+(v>>>0>>0?1:0));r=ie+gt,t=De+M+(r>>>0>>0?1:0),Oe=me,oe=ne,me=pe,ne=re,pe=R,re=b,b=te+v|0,R=Le+P+(b>>>0>>0?1:0)|0,Le=ee,te=X,ee=Z,X=H,Z=E,H=D,D=v+r|0,E=P+t+(D>>>0>>0?1:0)|0}s=n[1]=s+D|0,n[0]=i+E+(s>>>0>>0?1:0)|0,u=n[3]=u+H|0,n[2]=c+Z+(u>>>0>>0?1:0)|0,h=n[5]=h+X|0,n[4]=f+ee+(h>>>0>>0?1:0)|0,y=n[7]=y+te|0,n[6]=l+Le+(y>>>0>>0?1:0)|0,g=n[9]=g+b|0,n[8]=d+R+(g>>>0>>0?1:0)|0,C=n[11]=C+re|0,n[10]=k+pe+(C>>>0>>0?1:0)|0,le=n[13]=le+ne|0,n[12]=N+me+(le>>>0>>0?1:0)|0,de=n[15]=de+oe|0,n[14]=Me+Oe+(de>>>0>>0?1:0)|0}};a.mode.ccm={name:"ccm",F:[],listenProgress:function(e){a.mode.ccm.F.push(e)},unListenProgress:function(e){e=a.mode.ccm.F.indexOf(e),-1u)throw new a.exception.invalid("ccm: iv must be at least 7 bytes");for(i=2;4>i&&f>>>8*i;i++);return i<15-u&&(i=15-u),r=c.clamp(r,8*(15-i)),t=a.mode.ccm.U(e,t,r,n,o,i),s=a.mode.ccm.V(e,s,r,t,o,i),c.concat(s.data,s.tag)},decrypt:function(e,t,r,n,o){o=o||64,n=n||[];var i=a.bitArray,s=i.bitLength(r)/8,f=i.bitLength(t),c=i.clamp(t,f-o),u=i.bitSlice(t,f-o),f=(f-o)/8;if(7>s)throw new a.exception.invalid("ccm: iv must be at least 7 bytes");for(t=2;4>t&&f>>>8*t;t++);if(t<15-s&&(t=15-s),r=i.clamp(r,8*(15-t)),c=a.mode.ccm.V(e,c,r,u,o,t),e=a.mode.ccm.U(e,c.data,r,n,o,t),!i.equal(c.tag,e))throw new a.exception.corrupt("ccm: tag doesn't match");return c.data},ma:function(e,t,r,n,o,i){var s=[],c=a.bitArray,u=c.P;if(n=[c.partial(8,(t.length?64:0)|n-2<<2|i-1)],n=c.concat(n,r),n[3]|=o,n=e.encrypt(n),t.length)for(r=c.bitLength(t)/8,65279>=r?s=[c.partial(16,r)]:4294967295>=r&&(s=c.concat([c.partial(16,65534)],[r])),s=c.concat(s,t),t=0;to||16h&&(a.mode.ccm.da(s/u),h+=l),r[3]++,o=e.encrypt(r),t[s]^=o[0],t[s+1]^=o[1],t[s+2]^=o[2],t[s+3]^=o[3];return{tag:n,data:c.clamp(t,f)}}};a.misc.hmac=function(e,t){this.W=t=t||a.hash.sha256;var r=[[],[]],n,o=t.prototype.blockSize/32;for(this.B=[new t,new t],e.length>o&&(e=t.hash(e)),n=0;nn||0>r)throw new a.exception.invalid("invalid params to pbkdf2");typeof e=="string"&&(e=a.codec.utf8String.toBits(e)),typeof t=="string"&&(t=a.codec.utf8String.toBits(t)),o=o||a.misc.hmac,e=new o(e);var i,s,c,u,f=[],h=a.bitArray;for(u=1;32*f.length<(n||1);u++){for(o=i=e.encrypt(h.concat(t,[u])),s=1;ss;s++)o.push(4294967296*Math.random()|0);for(s=0;s=1<this.u&&(this.u=i),this.N++,this.b=a.hash.sha256.hash(this.b.concat(o)),this.K=new a.cipher.aes(this.b),n=0;4>n&&(this.m[n]=this.m[n]+1|0,!this.m[n]);n++);}for(n=0;n>>1;this.h[s].update([n,this.M++,2,t,i,e.length].concat(e))}break;case"string":t===void 0&&(t=e.length),this.h[s].update([n,this.M++,3,t,i,e.length]),this.h[s].update(e);break;default:u=1}if(u)throw new a.exception.bug("random: addEntropy only supports number, array of numbers or string");this.s[s]+=t,this.i+=t,c===this.A&&(this.isReady()!==this.A&&st("seeded",Math.max(this.u,this.i)),st("progress",this.getProgress()))},isReady:function(e){return e=this.R[e!==void 0?e:this.L],this.u&&this.u>=e?this.s[0]>this.$&&new Date().valueOf()>this.X?this.I|this.H:this.H:this.i>=e?this.I|this.A:this.A},getProgress:function(e){return e=this.R[e||this.L],this.u>=e||this.i>e?1:this.i/e},startCollectors:function(){if(!this.D){if(this.a={loadTimeCollector:ue(this,this.la),mouseCollector:ue(this,this.na),keyboardCollector:ue(this,this.ja),accelerometerCollector:ue(this,this.ca),touchCollector:ue(this,this.pa)},window.addEventListener)window.addEventListener("load",this.a.loadTimeCollector,!1),window.addEventListener("mousemove",this.a.mouseCollector,!1),window.addEventListener("keypress",this.a.keyboardCollector,!1),window.addEventListener("devicemotion",this.a.accelerometerCollector,!1),window.addEventListener("touchmove",this.a.touchCollector,!1);else if(document.attachEvent)document.attachEvent("onload",this.a.loadTimeCollector),document.attachEvent("onmousemove",this.a.mouseCollector),document.attachEvent("keypress",this.a.keyboardCollector);else throw new a.exception.bug("can't attach event");this.D=!0}},stopCollectors:function(){this.D&&(window.removeEventListener?(window.removeEventListener("load",this.a.loadTimeCollector,!1),window.removeEventListener("mousemove",this.a.mouseCollector,!1),window.removeEventListener("keypress",this.a.keyboardCollector,!1),window.removeEventListener("devicemotion",this.a.accelerometerCollector,!1),window.removeEventListener("touchmove",this.a.touchCollector,!1)):document.detachEvent&&(document.detachEvent("onload",this.a.loadTimeCollector),document.detachEvent("onmousemove",this.a.mouseCollector),document.detachEvent("keypress",this.a.keyboardCollector)),this.D=!1)},addEventListener:function(e,t){this.J[e][this.ea++]=t},removeEventListener:function(e,t){var r,n,o=this.J[e],i=[];for(n in o)o.hasOwnProperty(n)&&o[n]===t&&i.push(n);for(r=0;rt&&(e.m[t]=e.m[t]+1|0,!e.m[t]);t++);return e.K.encrypt(e.m)}function ue(e,t){return function(){t.apply(e,arguments)}}a.random=new a.prng(6);e:try{if(we=typeof q<"u"&&q.exports){try{Ee=bt("crypto")}catch{Ee=null}we=ge=Ee}if(we&&ge.randomBytes)fe=ge.randomBytes(128),fe=new Uint32Array(new Uint8Array(fe).buffer),a.random.addEntropy(fe,1024,"crypto['randomBytes']");else if(typeof window<"u"&&typeof Uint32Array<"u"){if(he=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(he);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(he);else break e;a.random.addEntropy(he,1024,"crypto['getRandomValues']")}}catch(e){typeof window<"u"&&window.console&&(console.log("There was an error collecting entropy from the browser:"),console.log(e))}var fe,ge,he,we,Ee;a.json={defaults:{v:1,iter:1e4,ks:128,ts:64,mode:"ccm",adata:"",cipher:"aes"},ha:function(e,t,r,n){r=r||{},n=n||{};var o=a.json,i=o.j({iv:a.random.randomWords(4,0)},o.defaults),s;if(o.j(i,r),r=i.adata,typeof i.salt=="string"&&(i.salt=a.codec.base64.toBits(i.salt)),typeof i.iv=="string"&&(i.iv=a.codec.base64.toBits(i.iv)),!a.mode[i.mode]||!a.cipher[i.cipher]||typeof e=="string"&&100>=i.iter||i.ts!==64&&i.ts!==96&&i.ts!==128||i.ks!==128&&i.ks!==192&&i.ks!==256||2>i.iv.length||4=t.iter||t.ts!==64&&t.ts!==96&&t.ts!==128||t.ks!==128&&t.ks!==192&&t.ks!==256||!t.iv||2>t.iv.length||4{let n=t.isOk()?{type:"Ok",value:t.value}:{type:"Err",value:t.error},o=r.withStackTrace?new Error().stack:void 0;return{data:n,message:e,stack:o}};function G(e,t,r,n){function o(i){return i instanceof r?i:new r(function(s){s(i)})}return new(r||(r=Promise))(function(i,s){function c(h){try{f(n.next(h))}catch(l){s(l)}}function u(h){try{f(n.throw(h))}catch(l){s(l)}}function f(h){h.done?i(h.value):o(h.value).then(c,u)}f((n=n.apply(e,t||[])).next())})}function Ne(e){var t=typeof Symbol=="function"&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&typeof e.length=="number")return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function I(e){return this instanceof I?(this.v=e,this):new I(e)}function Be(e,t,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=r.apply(e,t||[]),o,i=[];return o=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),c("next"),c("throw"),c("return",s),o[Symbol.asyncIterator]=function(){return this},o;function s(d){return function(g){return Promise.resolve(g).then(d,l)}}function c(d,g){n[d]&&(o[d]=function(k){return new Promise(function(C,N){i.push([d,k,C,N])>1||u(d,k)})},g&&(o[d]=g(o[d])))}function u(d,g){try{f(n[d](g))}catch(k){y(i[0][3],k)}}function f(d){d.value instanceof I?Promise.resolve(d.value.v).then(h,l):y(i[0][2],d)}function h(d){u("next",d)}function l(d){u("throw",d)}function y(d,g){d(g),i.shift(),i.length&&u(i[0][0],i[0][1])}}function _t(e){var t,r;return t={},n("next"),n("throw",function(o){throw o}),n("return"),t[Symbol.iterator]=function(){return this},t;function n(o,i){t[o]=e[o]?function(s){return(r=!r)?{value:I(e[o](s)),done:!1}:i?i(s):s}:i}}function Ct(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=e[Symbol.asyncIterator],r;return t?t.call(e):(e=typeof Ne=="function"?Ne(e):e[Symbol.iterator](),r={},n("next"),n("throw"),n("return"),r[Symbol.asyncIterator]=function(){return this},r);function n(i){r[i]=e[i]&&function(s){return new Promise(function(c,u){s=e[i](s),o(c,u,s.done,s.value)})}}function o(i,s,c,u){Promise.resolve(u).then(function(f){i({value:f,done:c})},s)}}var A=class e{constructor(t){this._promise=t}static fromSafePromise(t){let r=t.then(n=>new S(n));return new e(r)}static fromPromise(t,r){let n=t.then(o=>new S(o)).catch(o=>new _(r(o)));return new e(n)}static fromThrowable(t,r){return(...n)=>new e(G(this,void 0,void 0,function*(){try{return new S(yield t(...n))}catch(o){return new _(r?r(o):o)}}))}static combine(t){return Rt(t)}static combineWithAllErrors(t){return Pt(t)}map(t){return new e(this._promise.then(r=>G(this,void 0,void 0,function*(){return r.isErr()?new _(r.error):new S(yield t(r.value))})))}andThrough(t){return new e(this._promise.then(r=>G(this,void 0,void 0,function*(){if(r.isErr())return new _(r.error);let n=yield t(r.value);return n.isErr()?new _(n.error):new S(r.value)})))}andTee(t){return new e(this._promise.then(r=>G(this,void 0,void 0,function*(){if(r.isErr())return new _(r.error);try{yield t(r.value)}catch{}return new S(r.value)})))}mapErr(t){return new e(this._promise.then(r=>G(this,void 0,void 0,function*(){return r.isOk()?new S(r.value):new _(yield t(r.error))})))}andThen(t){return new e(this._promise.then(r=>{if(r.isErr())return new _(r.error);let n=t(r.value);return n instanceof e?n._promise:n}))}orElse(t){return new e(this._promise.then(r=>G(this,void 0,void 0,function*(){return r.isErr()?t(r.error):new S(r.value)})))}match(t,r){return this._promise.then(n=>n.match(t,r))}unwrapOr(t){return this._promise.then(r=>r.unwrapOr(t))}safeUnwrap(){return Be(this,arguments,function*(){return yield I(yield I(yield*_t(Ct(yield I(this._promise.then(r=>r.safeUnwrap()))))))})}then(t,r){return this._promise.then(t,r)}[Symbol.asyncIterator](){return Be(this,arguments,function*(){let r=yield I(this._promise);return r.isErr()&&(yield yield I(O(r.error))),yield I(r.value)})}},U=e=>new A(Promise.resolve(new S(e))),O=e=>new A(Promise.resolve(new _(e))),fr=A.fromPromise,hr=A.fromSafePromise,lr=A.fromThrowable,Fe=e=>{let t=J([]);for(let r of e)if(r.isErr()){t=B(r.error);break}else t.map(n=>n.push(r.value));return t},Rt=e=>A.fromSafePromise(Promise.all(e)).andThen(Fe),Je=e=>{let t=J([]);for(let r of e)r.isErr()&&t.isErr()?t.error.push(r.error):r.isErr()&&t.isOk()?t=B([r.error]):r.isOk()&&t.isOk()&&t.value.push(r.value);return t},Pt=e=>A.fromSafePromise(Promise.all(e)).andThen(Je),ke;(function(e){function t(o,i){return(...s)=>{try{let c=o(...s);return J(c)}catch(c){return B(i?i(c):c)}}}e.fromThrowable=t;function r(o){return Fe(o)}e.combine=r;function n(o){return Je(o)}e.combineWithAllErrors=n})(ke||(ke={}));var J=e=>new S(e);function B(e){return new _(e)}var S=class{constructor(t){this.value=t}isOk(){return!0}isErr(){return!this.isOk()}map(t){return J(t(this.value))}mapErr(t){return J(this.value)}andThen(t){return t(this.value)}andThrough(t){return t(this.value).map(r=>this.value)}andTee(t){try{t(this.value)}catch{}return J(this.value)}orElse(t){return J(this.value)}asyncAndThen(t){return t(this.value)}asyncAndThrough(t){return t(this.value).map(()=>this.value)}asyncMap(t){return A.fromSafePromise(t(this.value))}unwrapOr(t){return this.value}match(t,r){return t(this.value)}safeUnwrap(){let t=this.value;return function*(){return t}()}_unsafeUnwrap(t){return this.value}_unsafeUnwrapErr(t){throw We("Called `_unsafeUnwrapErr` on an Ok",this,t)}*[Symbol.iterator](){return this.value}},_=class{constructor(t){this.error=t}isOk(){return!1}isErr(){return!this.isOk()}map(t){return B(this.error)}mapErr(t){return B(t(this.error))}andThrough(t){return B(this.error)}andTee(t){return B(this.error)}andThen(t){return B(this.error)}orElse(t){return t(this.error)}asyncAndThen(t){return O(this.error)}asyncAndThrough(t){return O(this.error)}asyncMap(t){return O(this.error)}unwrapOr(t){return t}match(t,r){return r(this.error)}safeUnwrap(){let t=this.error;return function*(){throw yield B(t),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(t){throw We("Called `_unsafeUnwrap` on an Err",this,t)}_unsafeUnwrapErr(t){return this.error}*[Symbol.iterator](){let t=this;return yield t,t}},dr=ke.fromThrowable;var F=class extends Error{constructor(r,n={}){let{cause:o,context:i}=n;super(r,{cause:o});T(this,"context");this.name=this.constructor.name,this.context=i}};var j=class extends F{};var se=class extends j{constructor(){super(...arguments);T(this,"message","An error occured while trying to connect to WebSocket")}};var z=e=>{if(e instanceof Error)return e;let t="[Unable to stringify the thrown value]";try{t=JSON.stringify(e)}catch{}return new Error(t)};var Mt=()=>typeof Deno<"u";var $=e=>Mt()?new URL(`./worker/${e}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${e==="main"?`worker/${e}`:e}.js`));var rt=je(Ze());var m=new rt.default,w,et=!1;self.onmessage=e=>{Ft(e),et||(et=!0,m.once("OPERATION_FAILED",()=>{w&&w.terminate()}))};var Y=(e,t)=>(Object.assign(e,t),typeof WorkerGlobalScope<"u"&&self.postMessage({event:"FILE_UPDATED",lufiFile:e}),e);var Ft=(e,t)=>{let{action:r}=e.data;if(r===5||r===8)w.postMessage(e.data);else{switch(r){case 2:w=new Worker($("cancel"),{type:"module"}),w.postMessage(e.data);break;case 3:w=new Worker($("download"),{type:"module"}),w.postMessage(e.data);break;case 4:w=new Worker($("infos"),{type:"module"}),w.postMessage(e.data);break;case 7:w=w||new Worker($("remove"),{type:"module"}),w.postMessage(e.data);break;case 9:w=w||new Worker($("upload"),{type:"module"}),w.postMessage(e.data);break;default:console.error("Action not found")}w.onmessage=n=>{t&&t(n),self.postMessage(n.data)},w.onerror=n=>{console.error(`Error: ${n.message}`)}}},nt=()=>{m.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),m.once("OPERATION_FAILED",e=>{self.postMessage({event:"OPERATION_FAILED",error:e})})};var K=class{constructor(t,r){if(!t||t.length!=64)throw Error("Charset must contain 64 characters");this._charset=t,this._noPadding=!!r,this._valid=new RegExp("^["+this._charset.replace("-","\\-")+"]+={0,2}$")}Encode(t){let r=t.byteLength;if(!r)return"";let n=new Uint8Array(t),o="";for(let i=0;i>2]+this._charset[(n[i]&3)<<4|n[i+1]>>4]+this._charset[(n[i+1]&15)<<2|n[i+2]>>6]+this._charset[n[i+2]&63];return r%3==2?(o=o.substring(0,o.length-1),this._noPadding||(o+="=")):r%3==1&&(o=o.substring(0,o.length-2),this._noPadding||(o+="==")),o}Decode(t){if(t=(t||"").replace(/[\s]/g,""),!t)return new ArrayBuffer(0);if(!this._valid.test(t))throw Error("Invalid base64 input sequence");let r=Math.floor(t.length*.75);t[t.length-2]=="="?r-=2:t[t.length-1]=="="&&r--;let n=new Uint8Array(r),o,i,s,c,u=0,f=0;for(;u>4,n[u++]=(i&15)<<4|s>>2,n[u++]=(s&3)<<6|c;return n.buffer}};var Jt=new K("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");function ae(e){return Jt.Decode(e)}var zt=new K("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",!0);function _e(e){return zt.Decode(e)}var ft=je(ct());var W=class extends F{};var Q=class extends W{constructor(){super(...arguments);T(this,"message","Unable to decrypt the provided data")}};var ht=(e,t)=>{try{let r=typeof t=="string"?t:t.data;return U(ae(ft.default.decrypt(e,r)))}catch(r){return O(new Q(void 0,{cause:z(r)}))}};var lt=(e,t)=>Vt(e).andThen(r=>A.fromPromise(crypto.subtle.decrypt({name:"AES-GCM",iv:t.iv},r,ae(t.data)),n=>new Q(void 0,{cause:z(n)})));var Vt=e=>A.fromPromise(crypto.subtle.importKey("raw",_e(e),{name:"AES-GCM"},!1,["encrypt","decrypt"]),t=>new W("Unable to import cryptography key",{cause:z(t)}));var dt=(e,t)=>t.algo===void 0||t.algo===0?ht(e,t):lt(e,t);var x={},pt=5,qt=e=>(m.emit("UPLOAD_CANCELLED",e.success),U(void 0)),Qt=(e,t)=>{let r=e.split("XXMOJOXX"),n=r.shift();if(n!==void 0){let o=JSON.parse(n);if(sr(o)){let i=r.shift();if(i){let s=JSON.parse(i);return s.iv&&(s.iv=new Uint8Array(Object.values(s.iv))),dt(t.keys.client,s).andThen(c=>{let u=typeof c=="string"?new TextEncoder().encode(c).buffer:c;return o.part===0?(Y(t,{chunksReady:t.chunksReady+1,delAtFirstView:o.del_at_first_view,delay:o.delay,name:o.name,size:o.size,totalChunks:o.total,type:o.type,zipped:o.zipped}),m.emit("DOWNLOAD_STARTED")):Y(t,{chunksReady:t.chunksReady+1}),m.emit("CHUNK_DOWNLOADED",u,o.part),++o.part===o.total?rr(t).andThen(()=>(m.emit("DOWNLOAD_COMPLETE"),m.emit("SOCKET_OPERATION_TERMINATED"),U(void 0))):U(void 0)})}else{let s=new j("Cannot retrieve metadata from data received by the server");return m.emit("OPERATION_FAILED",s),O(s)}}else{let i=new j(o.msg);return m.emit("OPERATION_FAILED",i),O(i)}}else{let o=new j("Cannot retrieve metadata from data received by the server");return m.emit("OPERATION_FAILED",o),O(o)}},Zt=(e,t)=>{if(e.success)return e.j===0&&(Y(t,{keys:{client:t.keys.client,server:e.short},actionToken:e.token,queueIndex:e.i}),m.emit("UPLOAD_STARTED")),Y(t,{chunksReady:t.chunksReady+1,createdAt:e.created_at}),m.emit("CHUNK_UPLOADED"),t.chunksReady===t.totalChunks&&(Y(t,{uploadStatus:1}),m.emit("UPLOAD_COMPLETE"),m.emit("SOCKET_OPERATION_TERMINATED")),U(void 0);{let r=new j(e.msg);return m.emit("OPERATION_FAILED",r),O(r)}},er=(e,t)=>{let r=ir(e.data),n;if(r)if(!r.action&&r.msg){let o=new j(r.msg);return m.emit("OPERATION_FAILED",o),O(o)}else"delay"in r?n=Zt(r,t):n=qt(r);else n=Qt(e.data,t);return n},tr=e=>x!==void 0&&x[e]!==void 0&&x[e].readyState===WebSocket.CONNECTING,Re=e=>x!==void 0&&x[e]!==void 0&&x[e].readyState===WebSocket.OPEN;var mt=(e,t)=>{let r;return e.password?r={part:t,file_pwd:e.password}:r={part:t},Pe(Ae(e),e,JSON.stringify(r))},rr=e=>{let t;return e.password?t={ended:!0,file_pwd:e.password}:t={ended:!0},Pe(Ae(e),e,JSON.stringify(t))};var Pe=(e,t,r)=>Re(e)?(x[e].onmessage=n=>er(n,t),x[e].send(r),U(void 0)):yt(e).andThen(()=>Pe(e,t,r)),yt=(e,t=0)=>(!Re(e)&&!tr(e)&&(x[e]=new WebSocket(e),m.once("SOCKET_OPERATION_TERMINATED",()=>{x[e].close()}),m.once("OPERATION_FAILED",()=>{m.emit("SOCKET_OPERATION_TERMINATED")}),x[e].onopen=()=>{m.emit("SOCKET_OPENED")},x[e].onclose=()=>{},x[e].onerror=()=>++t<=pt?(console.error(`An error happened while trying to connect to WebSocket ${e}. Trying again. ${t} / ${pt}`),yt(e,t)):(m.emit("SOCKET_ONERROR"),O(new se(`Unable to connect to WebSocket ${e}.`)))),nr(e).andThen(()=>U(e)).orElse(r=>O(r))),nr=e=>A.fromPromise(new Promise((t,r)=>{Re(e)?t(void 0):(m.once("SOCKET_OPENED",()=>{t(void 0)}),m.on("SOCKET_ONERROR",()=>{r(new se)}))}),t=>z(t));var or=(e,t)=>{let r=new URL(e);return r.protocol=r.protocol==="http:"?"ws:":"wss:",r.pathname+=t,new URL(r.origin+r.pathname)},Ae=e=>or(new URL(e.serverUrl),"download"+`/${e.keys.server}`).toString();var ir=e=>{try{let t=JSON.parse(e);if(t&&typeof t=="object")return t}catch{}return!1},sr=e=>typeof e=="object"&&e!==null&&!("msg"in e);var vt=!1;self.onmessage=e=>{vt||(nt(),vt=!0),m.on("DOWNLOAD_STARTED",()=>{x[Ae(e.data.args.lufiFile)].close(),self.postMessage({event:"INFOS_RETRIEVED"})}),cr(e.data).mapErr(t=>{self.postMessage({event:"OPERATION_FAILED",error:t})})};var cr=e=>mt(e.args.lufiFile,0); +var Et=Object.create;var be=Object.defineProperty;var At=Object.getOwnPropertyDescriptor;var Lt=Object.getOwnPropertyNames;var Ot=Object.getPrototypeOf,xt=Object.prototype.hasOwnProperty;var Dt=(e,t,r)=>t in e?be(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var bt=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,r)=>(typeof require<"u"?require:t)[r]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var Ue=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var kt=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Lt(t))!xt.call(e,o)&&o!==r&&be(e,o,{get:()=>t[o],enumerable:!(n=At(t,o))||n.enumerable});return e};var je=(e,t,r)=>(r=e!=null?Et(Ot(e)):{},kt(t||!e||!e.__esModule?be(r,"default",{value:e,enumerable:!0}):r,e));var T=(e,t,r)=>Dt(e,typeof t!="symbol"?t+"":t,r);var Ze=Ue((jr,Se)=>{"use strict";var V=typeof Reflect=="object"?Reflect:null,ze=V&&typeof V.apply=="function"?V.apply:function(t,r,n){return Function.prototype.apply.call(t,r,n)},ye;V&&typeof V.ownKeys=="function"?ye=V.ownKeys:Object.getOwnPropertySymbols?ye=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:ye=function(t){return Object.getOwnPropertyNames(t)};function Tt(e){console&&console.warn&&console.warn(e)}var Xe=Number.isNaN||function(t){return t!==t};function p(){p.init.call(this)}Se.exports=p;Se.exports.once=Nt;p.EventEmitter=p;p.prototype._events=void 0;p.prototype._eventsCount=0;p.prototype._maxListeners=void 0;var He=10;function ve(e){if(typeof e!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}Object.defineProperty(p,"defaultMaxListeners",{enumerable:!0,get:function(){return He},set:function(e){if(typeof e!="number"||e<0||Xe(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");He=e}});p.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0};p.prototype.setMaxListeners=function(t){if(typeof t!="number"||t<0||Xe(t))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+t+".");return this._maxListeners=t,this};function Ge(e){return e._maxListeners===void 0?p.defaultMaxListeners:e._maxListeners}p.prototype.getMaxListeners=function(){return Ge(this)};p.prototype.emit=function(t){for(var r=[],n=1;n0&&(s=r[0]),s instanceof Error)throw s;var c=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw c.context=s,c}var u=i[t];if(u===void 0)return!1;if(typeof u=="function")ze(u,this,r);else for(var f=u.length,h=qe(u,f),n=0;n0&&s.length>o&&!s.warned){s.warned=!0;var c=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");c.name="MaxListenersExceededWarning",c.emitter=e,c.type=t,c.count=s.length,Tt(c)}return e}p.prototype.addListener=function(t,r){return $e(this,t,r,!1)};p.prototype.on=p.prototype.addListener;p.prototype.prependListener=function(t,r){return $e(this,t,r,!0)};function It(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function Ve(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},o=It.bind(n);return o.listener=r,n.wrapFn=o,o}p.prototype.once=function(t,r){return ve(r),this.on(t,Ve(this,t,r)),this};p.prototype.prependOnceListener=function(t,r){return ve(r),this.prependListener(t,Ve(this,t,r)),this};p.prototype.removeListener=function(t,r){var n,o,i,s,c;if(ve(r),o=this._events,o===void 0)return this;if(n=o[t],n===void 0)return this;if(n===r||n.listener===r)--this._eventsCount===0?this._events=Object.create(null):(delete o[t],o.removeListener&&this.emit("removeListener",t,n.listener||r));else if(typeof n!="function"){for(i=-1,s=n.length-1;s>=0;s--)if(n[s]===r||n[s].listener===r){c=n[s].listener,i=s;break}if(i<0)return this;i===0?n.shift():Ut(n,i),n.length===1&&(o[t]=n[0]),o.removeListener!==void 0&&this.emit("removeListener",t,c||r)}return this};p.prototype.off=p.prototype.removeListener;p.prototype.removeAllListeners=function(t){var r,n,o;if(n=this._events,n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[t]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[t]),this;if(arguments.length===0){var i=Object.keys(n),s;for(o=0;o=0;o--)this.removeListener(t,r[o]);return this};function Ye(e,t,r){var n=e._events;if(n===void 0)return[];var o=n[t];return o===void 0?[]:typeof o=="function"?r?[o.listener||o]:[o]:r?jt(o):qe(o,o.length)}p.prototype.listeners=function(t){return Ye(this,t,!0)};p.prototype.rawListeners=function(t){return Ye(this,t,!1)};p.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):Ke.call(e,t)};p.prototype.listenerCount=Ke;function Ke(e){var t=this._events;if(t!==void 0){var r=t[e];if(typeof r=="function")return 1;if(r!==void 0)return r.length}return 0}p.prototype.eventNames=function(){return this._eventsCount>0?ye(this._events):[]};function qe(e,t){for(var r=new Array(t),n=0;n{"use strict";var a={cipher:{},hash:{},keyexchange:{},mode:{},misc:{},codec:{},exception:{corrupt:function(e){this.toString=function(){return"CORRUPT: "+this.message},this.message=e},invalid:function(e){this.toString=function(){return"INVALID: "+this.message},this.message=e},bug:function(e){this.toString=function(){return"BUG: "+this.message},this.message=e},notReady:function(e){this.toString=function(){return"NOT READY: "+this.message},this.message=e}}};a.cipher.aes=function(e){this.w[0][0][0]||this.C();var t,r,n,o,i=this.w[0][4],s=this.w[1];t=e.length;var c=1;if(t!==4&&t!==6&&t!==8)throw new a.exception.invalid("invalid aes key size");for(this.b=[n=e.slice(0),o=[]],e=t;e<4*t+28;e++)r=n[e-1],(e%t===0||t===8&&e%t===4)&&(r=i[r>>>24]<<24^i[r>>16&255]<<16^i[r>>8&255]<<8^i[r&255],e%t===0&&(r=r<<8^r>>>24^c<<24,c=c<<1^283*(c>>7))),n[e]=n[e-t]^r;for(t=0;e;t++,e--)r=n[t&3?e:e-4],o[t]=4>=e||4>t?r:s[0][i[r>>>24]]^s[1][i[r>>16&255]]^s[2][i[r>>8&255]]^s[3][i[r&255]]};a.cipher.aes.prototype={encrypt:function(e){return it(this,e,0)},decrypt:function(e){return it(this,e,1)},w:[[[],[],[],[],[]],[[],[],[],[],[]]],C:function(){var e=this.w[0],t=this.w[1],r=e[4],n=t[4],o,i,s,c=[],u=[],f,h,l,y;for(o=0;256>o;o++)u[(c[o]=o<<1^283*(o>>7))^o]=o;for(i=s=0;!r[i];i^=f||1,s=u[s]||1)for(l=s^s<<1^s<<2^s<<3^s<<4,l=l>>8^l&255^99,r[i]=l,n[l]=i,h=c[o=c[f=c[i]]],y=16843009*h^65537*o^257*f^16843008*i,h=257*c[l]^16843008*l,o=0;4>o;o++)e[o][i]=h=h<<24^h>>>8,t[o][l]=y=y<<24^y>>>8;for(o=0;5>o;o++)e[o]=e[o].slice(0),t[o]=t[o].slice(0)}};function it(e,t,r){if(t.length!==4)throw new a.exception.invalid("invalid aes block size");var n=e.b[r],o=t[0]^n[0],i=t[r?3:1]^n[1],s=t[2]^n[2];t=t[r?1:3]^n[3];var c,u,f,h=n.length/4-2,l,y=4,d=[0,0,0,0];c=e.w[r],e=c[0];var g=c[1],k=c[2],C=c[3],N=c[4];for(l=0;l>>24]^g[i>>16&255]^k[s>>8&255]^C[t&255]^n[y],u=e[i>>>24]^g[s>>16&255]^k[t>>8&255]^C[o&255]^n[y+1],f=e[s>>>24]^g[t>>16&255]^k[o>>8&255]^C[i&255]^n[y+2],t=e[t>>>24]^g[o>>16&255]^k[i>>8&255]^C[s&255]^n[y+3],y+=4,o=c,i=u,s=f;for(l=0;4>l;l++)d[r?3&-l:l]=N[o>>>24]<<24^N[i>>16&255]<<16^N[s>>8&255]<<8^N[t&255]^n[y++],c=o,o=i,i=s,s=t,t=c;return d}a.bitArray={bitSlice:function(e,t,r){return e=a.bitArray.Y(e.slice(t/32),32-(t&31)).slice(1),r===void 0?e:a.bitArray.clamp(e,r-t)},extract:function(e,t,r){var n=Math.floor(-t-r&31);return((t+r-1^t)&-32?e[t/32|0]<<32-n^e[t/32+1|0]>>>n:e[t/32|0]>>>n)&(1<>t-1,1)),e},partial:function(e,t,r){return e===32?t:(r?t|0:t<<32-e)+1099511627776*e},getPartial:function(e){return Math.round(e/1099511627776)||32},equal:function(e,t){if(a.bitArray.bitLength(e)!==a.bitArray.bitLength(t))return!1;var r=0,n;for(n=0;n>>t),r=e[o]<<32-t;return o=e.length?e[e.length-1]:0,e=a.bitArray.getPartial(o),n.push(a.bitArray.partial(t+e&31,32>>24|r>>>8&65280|(r&65280)<<8|r<<24;return e}};a.codec.utf8String={fromBits:function(e){var t="",r=a.bitArray.bitLength(e),n,o;for(n=0;n>>8>>>8>>>8),o<<=8;return decodeURIComponent(escape(t))},toBits:function(e){e=unescape(encodeURIComponent(e));var t=[],r,n=0;for(r=0;r>>o)>>>26),6>o?(s=e[r]<<6-o,o+=26,r++):(s<<=6,o-=6);for(;n.length&3&&!t;)n+="=";return n},toBits:function(e,t){e=e.replace(/\s|=/g,"");var r=[],n,o=0,i=a.codec.base64.S,s=0,c;for(t&&(i=i.substr(0,62)+"-_"),n=0;nc)throw new a.exception.invalid("this isn't base64!");26>>o),s=c<<32-o):(o+=6,s^=c<<32-o)}return o&56&&r.push(a.bitArray.partial(o&56,s,1)),r}};a.codec.base64url={fromBits:function(e){return a.codec.base64.fromBits(e,1,1)},toBits:function(e){return a.codec.base64.toBits(e,1)}};a.hash.sha256=function(e){this.b[0]||this.C(),e?(this.g=e.g.slice(0),this.f=e.f.slice(0),this.c=e.c):this.reset()};a.hash.sha256.hash=function(e){return new a.hash.sha256().update(e).finalize()};a.hash.sha256.prototype={blockSize:512,reset:function(){return this.g=this.o.slice(0),this.f=[],this.c=0,this},update:function(e){typeof e=="string"&&(e=a.codec.utf8String.toBits(e));var t,r=this.f=a.bitArray.concat(this.f,e);if(t=this.c,e=this.c=t+a.bitArray.bitLength(e),9007199254740991t;r++){for(o=!0,n=2;n*n<=r;n++)if(r%n===0){o=!1;break}o&&(8>t&&(this.o[t]=e(Math.pow(r,.5))),this.b[t]=e(Math.pow(r,1/3)),t++)}},l:function(e){var t,r,n,o=this.g,i=this.b,s=o[0],c=o[1],u=o[2],f=o[3],h=o[4],l=o[5],y=o[6],d=o[7];for(t=0;64>t;t++)16>t?r=e[t]:(r=e[t+1&15],n=e[t+14&15],r=e[t&15]=(r>>>7^r>>>18^r>>>3^r<<25^r<<14)+(n>>>17^n>>>19^n>>>10^n<<15^n<<13)+e[t&15]+e[t+9&15]|0),r=r+d+(h>>>6^h>>>11^h>>>25^h<<26^h<<21^h<<7)+(y^h&(l^y))+i[t],d=y,y=l,l=h,h=f+r|0,f=u,u=c,c=s,s=r+(c&u^f&(c^u))+(c>>>2^c>>>13^c>>>22^c<<30^c<<19^c<<10)|0;o[0]=o[0]+s|0,o[1]=o[1]+c|0,o[2]=o[2]+u|0,o[3]=o[3]+f|0,o[4]=o[4]+h|0,o[5]=o[5]+l|0,o[6]=o[6]+y|0,o[7]=o[7]+d|0}};a.hash.sha512=function(e){this.b[0]||this.C(),e?(this.g=e.g.slice(0),this.f=e.f.slice(0),this.c=e.c):this.reset()};a.hash.sha512.hash=function(e){return new a.hash.sha512().update(e).finalize()};a.hash.sha512.prototype={blockSize:1024,reset:function(){return this.g=this.o.slice(0),this.f=[],this.c=0,this},update:function(e){typeof e=="string"&&(e=a.codec.utf8String.toBits(e));var t,r=this.f=a.bitArray.concat(this.f,e);if(t=this.c,e=this.c=t+a.bitArray.bitLength(e),9007199254740991r;n++){for(i=!0,o=2;o*o<=n;o++)if(n%o===0){i=!1;break}i&&(8>r&&(this.o[2*r]=e(Math.pow(n,.5)),this.o[2*r+1]=t(Math.pow(n,.5))<<24|this.ia[r]),this.b[2*r]=e(Math.pow(n,1/3)),this.b[2*r+1]=t(Math.pow(n,1/3))<<24|this.ka[r],r++)}},l:function(e){var t,r,n=this.g,o=this.b,i=n[0],s=n[1],c=n[2],u=n[3],f=n[4],h=n[5],l=n[6],y=n[7],d=n[8],g=n[9],k=n[10],C=n[11],N=n[12],le=n[13],Me=n[14],de=n[15],L;if(typeof Uint32Array<"u"){L=Array(160);for(var E=0;32>E;E++)L[E]=e[E]}else L=e;var E=i,D=s,Z=c,H=u,ee=f,X=h,Le=l,te=y,R=d,b=g,pe=k,re=C,me=N,ne=le,Oe=Me,oe=de;for(e=0;80>e;e++){if(16>e)t=L[2*e],r=L[2*e+1];else{r=L[2*(e-15)];var v=L[2*(e-15)+1];t=(v<<31|r>>>1)^(v<<24|r>>>8)^r>>>7;var P=(r<<31|v>>>1)^(r<<24|v>>>8)^(r<<25|v>>>7);r=L[2*(e-2)];var M=L[2*(e-2)+1],v=(M<<13|r>>>19)^(r<<3|M>>>29)^r>>>6,M=(r<<13|M>>>19)^(M<<3|r>>>29)^(r<<26|M>>>6),xe=L[2*(e-7)],De=L[2*(e-16)],ie=L[2*(e-16)+1];r=P+L[2*(e-7)+1],t=t+xe+(r>>>0

>>0?1:0),r+=M,t+=v+(r>>>0>>0?1:0),r+=ie,t+=De+(r>>>0>>0?1:0)}L[2*e]=t|=0,L[2*e+1]=r|=0;var xe=R&pe^~R&me,Te=b&re^~b&ne,M=E&Z^E&ee^Z&ee,gt=D&H^D&X^H&X,De=(D<<4|E>>>28)^(E<<30|D>>>2)^(E<<25|D>>>7),ie=(E<<4|D>>>28)^(D<<30|E>>>2)^(D<<25|E>>>7),wt=o[2*e],Ie=o[2*e+1],v=oe+((R<<18|b>>>14)^(R<<14|b>>>18)^(b<<23|R>>>9)),P=Oe+((b<<18|R>>>14)^(b<<14|R>>>18)^(R<<23|b>>>9))+(v>>>0>>0?1:0),v=v+Te,P=P+(xe+(v>>>0>>0?1:0)),v=v+Ie,P=P+(wt+(v>>>0>>0?1:0)),v=v+r|0,P=P+(t+(v>>>0>>0?1:0));r=ie+gt,t=De+M+(r>>>0>>0?1:0),Oe=me,oe=ne,me=pe,ne=re,pe=R,re=b,b=te+v|0,R=Le+P+(b>>>0>>0?1:0)|0,Le=ee,te=X,ee=Z,X=H,Z=E,H=D,D=v+r|0,E=P+t+(D>>>0>>0?1:0)|0}s=n[1]=s+D|0,n[0]=i+E+(s>>>0>>0?1:0)|0,u=n[3]=u+H|0,n[2]=c+Z+(u>>>0>>0?1:0)|0,h=n[5]=h+X|0,n[4]=f+ee+(h>>>0>>0?1:0)|0,y=n[7]=y+te|0,n[6]=l+Le+(y>>>0>>0?1:0)|0,g=n[9]=g+b|0,n[8]=d+R+(g>>>0>>0?1:0)|0,C=n[11]=C+re|0,n[10]=k+pe+(C>>>0>>0?1:0)|0,le=n[13]=le+ne|0,n[12]=N+me+(le>>>0>>0?1:0)|0,de=n[15]=de+oe|0,n[14]=Me+Oe+(de>>>0>>0?1:0)|0}};a.mode.ccm={name:"ccm",F:[],listenProgress:function(e){a.mode.ccm.F.push(e)},unListenProgress:function(e){e=a.mode.ccm.F.indexOf(e),-1u)throw new a.exception.invalid("ccm: iv must be at least 7 bytes");for(i=2;4>i&&f>>>8*i;i++);return i<15-u&&(i=15-u),r=c.clamp(r,8*(15-i)),t=a.mode.ccm.U(e,t,r,n,o,i),s=a.mode.ccm.V(e,s,r,t,o,i),c.concat(s.data,s.tag)},decrypt:function(e,t,r,n,o){o=o||64,n=n||[];var i=a.bitArray,s=i.bitLength(r)/8,f=i.bitLength(t),c=i.clamp(t,f-o),u=i.bitSlice(t,f-o),f=(f-o)/8;if(7>s)throw new a.exception.invalid("ccm: iv must be at least 7 bytes");for(t=2;4>t&&f>>>8*t;t++);if(t<15-s&&(t=15-s),r=i.clamp(r,8*(15-t)),c=a.mode.ccm.V(e,c,r,u,o,t),e=a.mode.ccm.U(e,c.data,r,n,o,t),!i.equal(c.tag,e))throw new a.exception.corrupt("ccm: tag doesn't match");return c.data},ma:function(e,t,r,n,o,i){var s=[],c=a.bitArray,u=c.P;if(n=[c.partial(8,(t.length?64:0)|n-2<<2|i-1)],n=c.concat(n,r),n[3]|=o,n=e.encrypt(n),t.length)for(r=c.bitLength(t)/8,65279>=r?s=[c.partial(16,r)]:4294967295>=r&&(s=c.concat([c.partial(16,65534)],[r])),s=c.concat(s,t),t=0;to||16h&&(a.mode.ccm.da(s/u),h+=l),r[3]++,o=e.encrypt(r),t[s]^=o[0],t[s+1]^=o[1],t[s+2]^=o[2],t[s+3]^=o[3];return{tag:n,data:c.clamp(t,f)}}};a.misc.hmac=function(e,t){this.W=t=t||a.hash.sha256;var r=[[],[]],n,o=t.prototype.blockSize/32;for(this.B=[new t,new t],e.length>o&&(e=t.hash(e)),n=0;nn||0>r)throw new a.exception.invalid("invalid params to pbkdf2");typeof e=="string"&&(e=a.codec.utf8String.toBits(e)),typeof t=="string"&&(t=a.codec.utf8String.toBits(t)),o=o||a.misc.hmac,e=new o(e);var i,s,c,u,f=[],h=a.bitArray;for(u=1;32*f.length<(n||1);u++){for(o=i=e.encrypt(h.concat(t,[u])),s=1;ss;s++)o.push(4294967296*Math.random()|0);for(s=0;s=1<this.u&&(this.u=i),this.N++,this.b=a.hash.sha256.hash(this.b.concat(o)),this.K=new a.cipher.aes(this.b),n=0;4>n&&(this.m[n]=this.m[n]+1|0,!this.m[n]);n++);}for(n=0;n>>1;this.h[s].update([n,this.M++,2,t,i,e.length].concat(e))}break;case"string":t===void 0&&(t=e.length),this.h[s].update([n,this.M++,3,t,i,e.length]),this.h[s].update(e);break;default:u=1}if(u)throw new a.exception.bug("random: addEntropy only supports number, array of numbers or string");this.s[s]+=t,this.i+=t,c===this.A&&(this.isReady()!==this.A&&st("seeded",Math.max(this.u,this.i)),st("progress",this.getProgress()))},isReady:function(e){return e=this.R[e!==void 0?e:this.L],this.u&&this.u>=e?this.s[0]>this.$&&new Date().valueOf()>this.X?this.I|this.H:this.H:this.i>=e?this.I|this.A:this.A},getProgress:function(e){return e=this.R[e||this.L],this.u>=e||this.i>e?1:this.i/e},startCollectors:function(){if(!this.D){if(this.a={loadTimeCollector:ue(this,this.la),mouseCollector:ue(this,this.na),keyboardCollector:ue(this,this.ja),accelerometerCollector:ue(this,this.ca),touchCollector:ue(this,this.pa)},window.addEventListener)window.addEventListener("load",this.a.loadTimeCollector,!1),window.addEventListener("mousemove",this.a.mouseCollector,!1),window.addEventListener("keypress",this.a.keyboardCollector,!1),window.addEventListener("devicemotion",this.a.accelerometerCollector,!1),window.addEventListener("touchmove",this.a.touchCollector,!1);else if(document.attachEvent)document.attachEvent("onload",this.a.loadTimeCollector),document.attachEvent("onmousemove",this.a.mouseCollector),document.attachEvent("keypress",this.a.keyboardCollector);else throw new a.exception.bug("can't attach event");this.D=!0}},stopCollectors:function(){this.D&&(window.removeEventListener?(window.removeEventListener("load",this.a.loadTimeCollector,!1),window.removeEventListener("mousemove",this.a.mouseCollector,!1),window.removeEventListener("keypress",this.a.keyboardCollector,!1),window.removeEventListener("devicemotion",this.a.accelerometerCollector,!1),window.removeEventListener("touchmove",this.a.touchCollector,!1)):document.detachEvent&&(document.detachEvent("onload",this.a.loadTimeCollector),document.detachEvent("onmousemove",this.a.mouseCollector),document.detachEvent("keypress",this.a.keyboardCollector)),this.D=!1)},addEventListener:function(e,t){this.J[e][this.ea++]=t},removeEventListener:function(e,t){var r,n,o=this.J[e],i=[];for(n in o)o.hasOwnProperty(n)&&o[n]===t&&i.push(n);for(r=0;rt&&(e.m[t]=e.m[t]+1|0,!e.m[t]);t++);return e.K.encrypt(e.m)}function ue(e,t){return function(){t.apply(e,arguments)}}a.random=new a.prng(6);e:try{if(we=typeof q<"u"&&q.exports){try{Ee=bt("crypto")}catch{Ee=null}we=ge=Ee}if(we&&ge.randomBytes)fe=ge.randomBytes(128),fe=new Uint32Array(new Uint8Array(fe).buffer),a.random.addEntropy(fe,1024,"crypto['randomBytes']");else if(typeof window<"u"&&typeof Uint32Array<"u"){if(he=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(he);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(he);else break e;a.random.addEntropy(he,1024,"crypto['getRandomValues']")}}catch(e){typeof window<"u"&&window.console&&(console.log("There was an error collecting entropy from the browser:"),console.log(e))}var fe,ge,he,we,Ee;a.json={defaults:{v:1,iter:1e4,ks:128,ts:64,mode:"ccm",adata:"",cipher:"aes"},ha:function(e,t,r,n){r=r||{},n=n||{};var o=a.json,i=o.j({iv:a.random.randomWords(4,0)},o.defaults),s;if(o.j(i,r),r=i.adata,typeof i.salt=="string"&&(i.salt=a.codec.base64.toBits(i.salt)),typeof i.iv=="string"&&(i.iv=a.codec.base64.toBits(i.iv)),!a.mode[i.mode]||!a.cipher[i.cipher]||typeof e=="string"&&100>=i.iter||i.ts!==64&&i.ts!==96&&i.ts!==128||i.ks!==128&&i.ks!==192&&i.ks!==256||2>i.iv.length||4=t.iter||t.ts!==64&&t.ts!==96&&t.ts!==128||t.ks!==128&&t.ks!==192&&t.ks!==256||!t.iv||2>t.iv.length||4{let n=t.isOk()?{type:"Ok",value:t.value}:{type:"Err",value:t.error},o=r.withStackTrace?new Error().stack:void 0;return{data:n,message:e,stack:o}};function G(e,t,r,n){function o(i){return i instanceof r?i:new r(function(s){s(i)})}return new(r||(r=Promise))(function(i,s){function c(h){try{f(n.next(h))}catch(l){s(l)}}function u(h){try{f(n.throw(h))}catch(l){s(l)}}function f(h){h.done?i(h.value):o(h.value).then(c,u)}f((n=n.apply(e,t||[])).next())})}function Ne(e){var t=typeof Symbol=="function"&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&typeof e.length=="number")return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function I(e){return this instanceof I?(this.v=e,this):new I(e)}function Be(e,t,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=r.apply(e,t||[]),o,i=[];return o=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),c("next"),c("throw"),c("return",s),o[Symbol.asyncIterator]=function(){return this},o;function s(d){return function(g){return Promise.resolve(g).then(d,l)}}function c(d,g){n[d]&&(o[d]=function(k){return new Promise(function(C,N){i.push([d,k,C,N])>1||u(d,k)})},g&&(o[d]=g(o[d])))}function u(d,g){try{f(n[d](g))}catch(k){y(i[0][3],k)}}function f(d){d.value instanceof I?Promise.resolve(d.value.v).then(h,l):y(i[0][2],d)}function h(d){u("next",d)}function l(d){u("throw",d)}function y(d,g){d(g),i.shift(),i.length&&u(i[0][0],i[0][1])}}function _t(e){var t,r;return t={},n("next"),n("throw",function(o){throw o}),n("return"),t[Symbol.iterator]=function(){return this},t;function n(o,i){t[o]=e[o]?function(s){return(r=!r)?{value:I(e[o](s)),done:!1}:i?i(s):s}:i}}function Ct(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=e[Symbol.asyncIterator],r;return t?t.call(e):(e=typeof Ne=="function"?Ne(e):e[Symbol.iterator](),r={},n("next"),n("throw"),n("return"),r[Symbol.asyncIterator]=function(){return this},r);function n(i){r[i]=e[i]&&function(s){return new Promise(function(c,u){s=e[i](s),o(c,u,s.done,s.value)})}}function o(i,s,c,u){Promise.resolve(u).then(function(f){i({value:f,done:c})},s)}}var A=class e{constructor(t){this._promise=t}static fromSafePromise(t){let r=t.then(n=>new S(n));return new e(r)}static fromPromise(t,r){let n=t.then(o=>new S(o)).catch(o=>new _(r(o)));return new e(n)}static fromThrowable(t,r){return(...n)=>new e(G(this,void 0,void 0,function*(){try{return new S(yield t(...n))}catch(o){return new _(r?r(o):o)}}))}static combine(t){return Rt(t)}static combineWithAllErrors(t){return Pt(t)}map(t){return new e(this._promise.then(r=>G(this,void 0,void 0,function*(){return r.isErr()?new _(r.error):new S(yield t(r.value))})))}andThrough(t){return new e(this._promise.then(r=>G(this,void 0,void 0,function*(){if(r.isErr())return new _(r.error);let n=yield t(r.value);return n.isErr()?new _(n.error):new S(r.value)})))}andTee(t){return new e(this._promise.then(r=>G(this,void 0,void 0,function*(){if(r.isErr())return new _(r.error);try{yield t(r.value)}catch{}return new S(r.value)})))}mapErr(t){return new e(this._promise.then(r=>G(this,void 0,void 0,function*(){return r.isOk()?new S(r.value):new _(yield t(r.error))})))}andThen(t){return new e(this._promise.then(r=>{if(r.isErr())return new _(r.error);let n=t(r.value);return n instanceof e?n._promise:n}))}orElse(t){return new e(this._promise.then(r=>G(this,void 0,void 0,function*(){return r.isErr()?t(r.error):new S(r.value)})))}match(t,r){return this._promise.then(n=>n.match(t,r))}unwrapOr(t){return this._promise.then(r=>r.unwrapOr(t))}safeUnwrap(){return Be(this,arguments,function*(){return yield I(yield I(yield*_t(Ct(yield I(this._promise.then(r=>r.safeUnwrap()))))))})}then(t,r){return this._promise.then(t,r)}[Symbol.asyncIterator](){return Be(this,arguments,function*(){let r=yield I(this._promise);return r.isErr()&&(yield yield I(O(r.error))),yield I(r.value)})}},U=e=>new A(Promise.resolve(new S(e))),O=e=>new A(Promise.resolve(new _(e))),fr=A.fromPromise,hr=A.fromSafePromise,lr=A.fromThrowable,Fe=e=>{let t=J([]);for(let r of e)if(r.isErr()){t=B(r.error);break}else t.map(n=>n.push(r.value));return t},Rt=e=>A.fromSafePromise(Promise.all(e)).andThen(Fe),Je=e=>{let t=J([]);for(let r of e)r.isErr()&&t.isErr()?t.error.push(r.error):r.isErr()&&t.isOk()?t=B([r.error]):r.isOk()&&t.isOk()&&t.value.push(r.value);return t},Pt=e=>A.fromSafePromise(Promise.all(e)).andThen(Je),ke;(function(e){function t(o,i){return(...s)=>{try{let c=o(...s);return J(c)}catch(c){return B(i?i(c):c)}}}e.fromThrowable=t;function r(o){return Fe(o)}e.combine=r;function n(o){return Je(o)}e.combineWithAllErrors=n})(ke||(ke={}));var J=e=>new S(e);function B(e){return new _(e)}var S=class{constructor(t){this.value=t}isOk(){return!0}isErr(){return!this.isOk()}map(t){return J(t(this.value))}mapErr(t){return J(this.value)}andThen(t){return t(this.value)}andThrough(t){return t(this.value).map(r=>this.value)}andTee(t){try{t(this.value)}catch{}return J(this.value)}orElse(t){return J(this.value)}asyncAndThen(t){return t(this.value)}asyncAndThrough(t){return t(this.value).map(()=>this.value)}asyncMap(t){return A.fromSafePromise(t(this.value))}unwrapOr(t){return this.value}match(t,r){return t(this.value)}safeUnwrap(){let t=this.value;return function*(){return t}()}_unsafeUnwrap(t){return this.value}_unsafeUnwrapErr(t){throw We("Called `_unsafeUnwrapErr` on an Ok",this,t)}*[Symbol.iterator](){return this.value}},_=class{constructor(t){this.error=t}isOk(){return!1}isErr(){return!this.isOk()}map(t){return B(this.error)}mapErr(t){return B(t(this.error))}andThrough(t){return B(this.error)}andTee(t){return B(this.error)}andThen(t){return B(this.error)}orElse(t){return t(this.error)}asyncAndThen(t){return O(this.error)}asyncAndThrough(t){return O(this.error)}asyncMap(t){return O(this.error)}unwrapOr(t){return t}match(t,r){return r(this.error)}safeUnwrap(){let t=this.error;return function*(){throw yield B(t),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(t){throw We("Called `_unsafeUnwrap` on an Err",this,t)}_unsafeUnwrapErr(t){return this.error}*[Symbol.iterator](){let t=this;return yield t,t}},dr=ke.fromThrowable;var F=class extends Error{constructor(r,n={}){let{cause:o,context:i}=n;super(r,{cause:o});T(this,"context");this.name=this.constructor.name,this.context=i}};var j=class extends F{};var se=class extends j{constructor(){super(...arguments);T(this,"message","An error occured while trying to connect to WebSocket")}};var z=e=>{if(e instanceof Error)return e;let t="[Unable to stringify the thrown value]";try{t=JSON.stringify(e)}catch{}return new Error(t)};var Mt=()=>typeof Deno<"u";var $=e=>Mt()?new URL(`./worker/${e}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${e==="main"?`worker/${e}`:e}.js`));var rt=je(Ze());var m=new rt.default,w,et=!1;self.onmessage=e=>{Ft(e),et||(et=!0,m.once("OPERATION_FAILED",()=>{w&&w.terminate()}))};var Y=(e,t)=>(Object.assign(e,t),typeof WorkerGlobalScope<"u"&&self.postMessage({event:"FILE_UPDATED",lufiFile:e}),e);var Ft=(e,t)=>{let{action:r}=e.data;if(r===5||r===8)w.postMessage(e.data,e.data);else{switch(r){case 2:w=new Worker($("cancel"),{type:"module"}),w.postMessage(e.data,e.data);break;case 3:w=new Worker($("download"),{type:"module"}),w.postMessage(e.data,e.data);break;case 4:w=new Worker($("infos"),{type:"module"}),w.postMessage(e.data,e.data);break;case 7:w=w||new Worker($("remove"),{type:"module"}),w.postMessage(e.data,e.data);break;case 9:w=w||new Worker($("upload"),{type:"module"}),w.postMessage(e.data,e.data);break;default:console.error("Action not found")}w.onmessage=n=>{t&&t(n),self.postMessage(n.data,n.data)},w.onerror=n=>{console.error(`Error: ${n.message}`)}}},nt=()=>{m.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),m.once("OPERATION_FAILED",e=>{self.postMessage({event:"OPERATION_FAILED",error:e})})};var K=class{constructor(t,r){if(!t||t.length!=64)throw Error("Charset must contain 64 characters");this._charset=t,this._noPadding=!!r,this._valid=new RegExp("^["+this._charset.replace("-","\\-")+"]+={0,2}$")}Encode(t){let r=t.byteLength;if(!r)return"";let n=new Uint8Array(t),o="";for(let i=0;i>2]+this._charset[(n[i]&3)<<4|n[i+1]>>4]+this._charset[(n[i+1]&15)<<2|n[i+2]>>6]+this._charset[n[i+2]&63];return r%3==2?(o=o.substring(0,o.length-1),this._noPadding||(o+="=")):r%3==1&&(o=o.substring(0,o.length-2),this._noPadding||(o+="==")),o}Decode(t){if(t=(t||"").replace(/[\s]/g,""),!t)return new ArrayBuffer(0);if(!this._valid.test(t))throw Error("Invalid base64 input sequence");let r=Math.floor(t.length*.75);t[t.length-2]=="="?r-=2:t[t.length-1]=="="&&r--;let n=new Uint8Array(r),o,i,s,c,u=0,f=0;for(;u>4,n[u++]=(i&15)<<4|s>>2,n[u++]=(s&3)<<6|c;return n.buffer}};var Jt=new K("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");function ae(e){return Jt.Decode(e)}var zt=new K("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",!0);function _e(e){return zt.Decode(e)}var ft=je(ct());var W=class extends F{};var Q=class extends W{constructor(){super(...arguments);T(this,"message","Unable to decrypt the provided data")}};var ht=(e,t)=>{try{let r=typeof t=="string"?t:t.data;return U(ae(ft.default.decrypt(e,r)))}catch(r){return O(new Q(void 0,{cause:z(r)}))}};var lt=(e,t)=>Vt(e).andThen(r=>A.fromPromise(crypto.subtle.decrypt({name:"AES-GCM",iv:t.iv},r,ae(t.data)),n=>new Q(void 0,{cause:z(n)})));var Vt=e=>A.fromPromise(crypto.subtle.importKey("raw",_e(e),{name:"AES-GCM"},!1,["encrypt","decrypt"]),t=>new W("Unable to import cryptography key",{cause:z(t)}));var dt=(e,t)=>t.algo===void 0||t.algo===0?ht(e,t):lt(e,t);var x={},pt=5,qt=e=>(m.emit("UPLOAD_CANCELLED",e.success),U(void 0)),Qt=(e,t)=>{let r=e.split("XXMOJOXX"),n=r.shift();if(n!==void 0){let o=JSON.parse(n);if(sr(o)){let i=r.shift();if(i){let s=JSON.parse(i);return s.iv&&(s.iv=new Uint8Array(Object.values(s.iv))),dt(t.keys.client,s).andThen(c=>{let u=typeof c=="string"?new TextEncoder().encode(c).buffer:c;return o.part===0?(Y(t,{chunksReady:t.chunksReady+1,delAtFirstView:o.del_at_first_view,delay:o.delay,name:o.name,size:o.size,totalChunks:o.total,type:o.type,zipped:o.zipped}),m.emit("DOWNLOAD_STARTED")):Y(t,{chunksReady:t.chunksReady+1}),m.emit("CHUNK_DOWNLOADED",u,o.part),++o.part===o.total?rr(t).andThen(()=>(m.emit("DOWNLOAD_COMPLETE"),m.emit("SOCKET_OPERATION_TERMINATED"),U(void 0))):U(void 0)})}else{let s=new j("Cannot retrieve metadata from data received by the server");return m.emit("OPERATION_FAILED",s),O(s)}}else{let i=new j(o.msg);return m.emit("OPERATION_FAILED",i),O(i)}}else{let o=new j("Cannot retrieve metadata from data received by the server");return m.emit("OPERATION_FAILED",o),O(o)}},Zt=(e,t)=>{if(e.success)return e.j===0&&(Y(t,{keys:{client:t.keys.client,server:e.short},actionToken:e.token,queueIndex:e.i}),m.emit("UPLOAD_STARTED")),Y(t,{chunksReady:t.chunksReady+1,createdAt:e.created_at}),m.emit("CHUNK_UPLOADED"),t.chunksReady===t.totalChunks&&(Y(t,{uploadStatus:1}),m.emit("UPLOAD_COMPLETE"),m.emit("SOCKET_OPERATION_TERMINATED")),U(void 0);{let r=new j(e.msg);return m.emit("OPERATION_FAILED",r),O(r)}},er=(e,t)=>{let r=ir(e.data),n;if(r)if(!r.action&&r.msg){let o=new j(r.msg);return m.emit("OPERATION_FAILED",o),O(o)}else"delay"in r?n=Zt(r,t):n=qt(r);else n=Qt(e.data,t);return n},tr=e=>x!==void 0&&x[e]!==void 0&&x[e].readyState===WebSocket.CONNECTING,Re=e=>x!==void 0&&x[e]!==void 0&&x[e].readyState===WebSocket.OPEN;var mt=(e,t)=>{let r;return e.password?r={part:t,file_pwd:e.password}:r={part:t},Pe(Ae(e),e,JSON.stringify(r))},rr=e=>{let t;return e.password?t={ended:!0,file_pwd:e.password}:t={ended:!0},Pe(Ae(e),e,JSON.stringify(t))};var Pe=(e,t,r)=>Re(e)?(x[e].onmessage=n=>er(n,t),x[e].send(r),U(void 0)):yt(e).andThen(()=>Pe(e,t,r)),yt=(e,t=0)=>(!Re(e)&&!tr(e)&&(x[e]=new WebSocket(e),m.once("SOCKET_OPERATION_TERMINATED",()=>{x[e].close()}),m.once("OPERATION_FAILED",()=>{m.emit("SOCKET_OPERATION_TERMINATED")}),x[e].onopen=()=>{m.emit("SOCKET_OPENED")},x[e].onclose=()=>{},x[e].onerror=()=>++t<=pt?(console.error(`An error happened while trying to connect to WebSocket ${e}. Trying again. ${t} / ${pt}`),yt(e,t)):(m.emit("SOCKET_ONERROR"),O(new se(`Unable to connect to WebSocket ${e}.`)))),nr(e).andThen(()=>U(e)).orElse(r=>O(r))),nr=e=>A.fromPromise(new Promise((t,r)=>{Re(e)?t(void 0):(m.once("SOCKET_OPENED",()=>{t(void 0)}),m.on("SOCKET_ONERROR",()=>{r(new se)}))}),t=>z(t));var or=(e,t)=>{let r=new URL(e);return r.protocol=r.protocol==="http:"?"ws:":"wss:",r.pathname+=t,new URL(r.origin+r.pathname)},Ae=e=>or(new URL(e.serverUrl),"download"+`/${e.keys.server}`).toString();var ir=e=>{try{let t=JSON.parse(e);if(t&&typeof t=="object")return t}catch{}return!1},sr=e=>typeof e=="object"&&e!==null&&!("msg"in e);var vt=!1;self.onmessage=e=>{vt||(nt(),vt=!0),m.on("DOWNLOAD_STARTED",()=>{x[Ae(e.data.args.lufiFile)].close(),self.postMessage({event:"INFOS_RETRIEVED"})}),cr(e.data).mapErr(t=>{self.postMessage({event:"OPERATION_FAILED",error:t})})};var cr=e=>mt(e.args.lufiFile,0); diff --git a/themes/default/public/js/worker/main.js b/themes/default/public/js/worker/main.js index 8b3268e..6cc715f 100644 --- a/themes/default/public/js/worker/main.js +++ b/themes/default/public/js/worker/main.js @@ -1 +1 @@ -var te=Object.create;var R=Object.defineProperty;var ne=Object.getOwnPropertyDescriptor;var oe=Object.getOwnPropertyNames;var se=Object.getPrototypeOf,ie=Object.prototype.hasOwnProperty;var ue=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var ae=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of oe(e))!ie.call(r,o)&&o!==t&&R(r,o,{get:()=>e[o],enumerable:!(n=ne(e,o))||n.enumerable});return r};var fe=(r,e,t)=>(t=r!=null?te(se(r)):{},ae(e||!r||!r.__esModule?R(t,"default",{value:r,enumerable:!0}):t,r));var G=ue((Ae,M)=>{"use strict";var b=typeof Reflect=="object"?Reflect:null,U=b&&typeof b.apply=="function"?b.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)},P;b&&typeof b.ownKeys=="function"?P=b.ownKeys:Object.getOwnPropertySymbols?P=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:P=function(e){return Object.getOwnPropertyNames(e)};function ce(r){console&&console.warn&&console.warn(r)}var T=Number.isNaN||function(e){return e!==e};function a(){a.init.call(this)}M.exports=a;M.exports.once=me;a.EventEmitter=a;a.prototype._events=void 0;a.prototype._eventsCount=0;a.prototype._maxListeners=void 0;var F=10;function x(r){if(typeof r!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof r)}Object.defineProperty(a,"defaultMaxListeners",{enumerable:!0,get:function(){return F},set:function(r){if(typeof r!="number"||r<0||T(r))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+r+".");F=r}});a.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0};a.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||T(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this};function j(r){return r._maxListeners===void 0?a.defaultMaxListeners:r._maxListeners}a.prototype.getMaxListeners=function(){return j(this)};a.prototype.emit=function(e){for(var t=[],n=1;n0&&(s=t[0]),s instanceof Error)throw s;var f=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw f.context=s,f}var h=i[e];if(h===void 0)return!1;if(typeof h=="function")U(h,this,t);else for(var d=h.length,u=B(h,d),n=0;n0&&s.length>o&&!s.warned){s.warned=!0;var f=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");f.name="MaxListenersExceededWarning",f.emitter=r,f.type=e,f.count=s.length,ce(f)}return r}a.prototype.addListener=function(e,t){return N(this,e,t,!1)};a.prototype.on=a.prototype.addListener;a.prototype.prependListener=function(e,t){return N(this,e,t,!0)};function le(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function W(r,e,t){var n={fired:!1,wrapFn:void 0,target:r,type:e,listener:t},o=le.bind(n);return o.listener=t,n.wrapFn=o,o}a.prototype.once=function(e,t){return x(t),this.on(e,W(this,e,t)),this};a.prototype.prependOnceListener=function(e,t){return x(t),this.prependListener(e,W(this,e,t)),this};a.prototype.removeListener=function(e,t){var n,o,i,s,f;if(x(t),o=this._events,o===void 0)return this;if(n=o[e],n===void 0)return this;if(n===t||n.listener===t)--this._eventsCount===0?this._events=Object.create(null):(delete o[e],o.removeListener&&this.emit("removeListener",e,n.listener||t));else if(typeof n!="function"){for(i=-1,s=n.length-1;s>=0;s--)if(n[s]===t||n[s].listener===t){f=n[s].listener,i=s;break}if(i<0)return this;i===0?n.shift():he(n,i),n.length===1&&(o[e]=n[0]),o.removeListener!==void 0&&this.emit("removeListener",e,f||t)}return this};a.prototype.off=a.prototype.removeListener;a.prototype.removeAllListeners=function(e){var t,n,o;if(n=this._events,n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[e]),this;if(arguments.length===0){var i=Object.keys(n),s;for(o=0;o=0;o--)this.removeListener(e,t[o]);return this};function J(r,e,t){var n=r._events;if(n===void 0)return[];var o=n[e];return o===void 0?[]:typeof o=="function"?t?[o.listener||o]:[o]:t?pe(o):B(o,o.length)}a.prototype.listeners=function(e){return J(this,e,!0)};a.prototype.rawListeners=function(e){return J(this,e,!1)};a.listenerCount=function(r,e){return typeof r.listenerCount=="function"?r.listenerCount(e):H.call(r,e)};a.prototype.listenerCount=H;function H(r){var e=this._events;if(e!==void 0){var t=e[r];if(typeof t=="function")return 1;if(t!==void 0)return t.length}return 0}a.prototype.eventNames=function(){return this._eventsCount>0?P(this._events):[]};function B(r,e){for(var t=new Array(e),n=0;n(u[u.ARCHIVE_ADD=0]="ARCHIVE_ADD",u[u.ARCHHIVE_COMPRESS=1]="ARCHHIVE_COMPRESS",u[u.CANCEL=2]="CANCEL",u[u.DOWNLOAD=3]="DOWNLOAD",u[u.INFOS=4]="INFOS",u[u.PAUSE=5]="PAUSE",u[u.PROVIDE_FILE=6]="PROVIDE_FILE",u[u.REMOVE=7]="REMOVE",u[u.RESUME=8]="RESUME",u[u.UPLOAD=9]="UPLOAD",u))(k||{});var ve={withStackTrace:!1},Q=(r,e,t=ve)=>{let n=e.isOk()?{type:"Ok",value:e.value}:{type:"Err",value:e.error},o=t.withStackTrace?new Error().stack:void 0;return{data:n,message:r,stack:o}};function g(r,e,t,n){function o(i){return i instanceof t?i:new t(function(s){s(i)})}return new(t||(t=Promise))(function(i,s){function f(u){try{d(n.next(u))}catch(_){s(_)}}function h(u){try{d(n.throw(u))}catch(_){s(_)}}function d(u){u.done?i(u.value):o(u.value).then(f,h)}d((n=n.apply(r,e||[])).next())})}function q(r){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&r[e],n=0;if(t)return t.call(r);if(r&&typeof r.length=="number")return{next:function(){return r&&n>=r.length&&(r=void 0),{value:r&&r[n++],done:!r}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function v(r){return this instanceof v?(this.v=r,this):new v(r)}function z(r,e,t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=t.apply(r,e||[]),o,i=[];return o=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),f("next"),f("throw"),f("return",s),o[Symbol.asyncIterator]=function(){return this},o;function s(c){return function(w){return Promise.resolve(w).then(c,_)}}function f(c,w){n[c]&&(o[c]=function(A){return new Promise(function(ee,re){i.push([c,A,ee,re])>1||h(c,A)})},w&&(o[c]=w(o[c])))}function h(c,w){try{d(n[c](w))}catch(A){C(i[0][3],A)}}function d(c){c.value instanceof v?Promise.resolve(c.value.v).then(u,_):C(i[0][2],c)}function u(c){h("next",c)}function _(c){h("throw",c)}function C(c,w){c(w),i.shift(),i.length&&h(i[0][0],i[0][1])}}function ye(r){var e,t;return e={},n("next"),n("throw",function(o){throw o}),n("return"),e[Symbol.iterator]=function(){return this},e;function n(o,i){e[o]=r[o]?function(s){return(t=!t)?{value:v(r[o](s)),done:!1}:i?i(s):s}:i}}function Ee(r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e=r[Symbol.asyncIterator],t;return e?e.call(r):(r=typeof q=="function"?q(r):r[Symbol.iterator](),t={},n("next"),n("throw"),n("return"),t[Symbol.asyncIterator]=function(){return this},t);function n(i){t[i]=r[i]&&function(s){return new Promise(function(f,h){s=r[i](s),o(f,h,s.done,s.value)})}}function o(i,s,f,h){Promise.resolve(h).then(function(d){i({value:d,done:f})},s)}}var y=class r{constructor(e){this._promise=e}static fromSafePromise(e){let t=e.then(n=>new m(n));return new r(t)}static fromPromise(e,t){let n=e.then(o=>new m(o)).catch(o=>new p(t(o)));return new r(n)}static fromThrowable(e,t){return(...n)=>new r(g(this,void 0,void 0,function*(){try{return new m(yield e(...n))}catch(o){return new p(t?t(o):o)}}))}static combine(e){return we(e)}static combineWithAllErrors(e){return Le(e)}map(e){return new r(this._promise.then(t=>g(this,void 0,void 0,function*(){return t.isErr()?new p(t.error):new m(yield e(t.value))})))}andThrough(e){return new r(this._promise.then(t=>g(this,void 0,void 0,function*(){if(t.isErr())return new p(t.error);let n=yield e(t.value);return n.isErr()?new p(n.error):new m(t.value)})))}andTee(e){return new r(this._promise.then(t=>g(this,void 0,void 0,function*(){if(t.isErr())return new p(t.error);try{yield e(t.value)}catch{}return new m(t.value)})))}mapErr(e){return new r(this._promise.then(t=>g(this,void 0,void 0,function*(){return t.isOk()?new m(t.value):new p(yield e(t.error))})))}andThen(e){return new r(this._promise.then(t=>{if(t.isErr())return new p(t.error);let n=e(t.value);return n instanceof r?n._promise:n}))}orElse(e){return new r(this._promise.then(t=>g(this,void 0,void 0,function*(){return t.isErr()?e(t.error):new m(t.value)})))}match(e,t){return this._promise.then(n=>n.match(e,t))}unwrapOr(e){return this._promise.then(t=>t.unwrapOr(e))}safeUnwrap(){return z(this,arguments,function*(){return yield v(yield v(yield*ye(Ee(yield v(this._promise.then(t=>t.safeUnwrap()))))))})}then(e,t){return this._promise.then(e,t)}[Symbol.asyncIterator](){return z(this,arguments,function*(){let t=yield v(this._promise);return t.isErr()&&(yield yield v(O(t.error))),yield v(t.value)})}};var O=r=>new y(Promise.resolve(new p(r))),ke=y.fromPromise,Ie=y.fromSafePromise,Se=y.fromThrowable,Z=r=>{let e=L([]);for(let t of r)if(t.isErr()){e=E(t.error);break}else e.map(n=>n.push(t.value));return e},we=r=>y.fromSafePromise(Promise.all(r)).andThen(Z),X=r=>{let e=L([]);for(let t of r)t.isErr()&&e.isErr()?e.error.push(t.error):t.isErr()&&e.isOk()?e=E([t.error]):t.isOk()&&e.isOk()&&e.value.push(t.value);return e},Le=r=>y.fromSafePromise(Promise.all(r)).andThen(X),I;(function(r){function e(o,i){return(...s)=>{try{let f=o(...s);return L(f)}catch(f){return E(i?i(f):f)}}}r.fromThrowable=e;function t(o){return Z(o)}r.combine=t;function n(o){return X(o)}r.combineWithAllErrors=n})(I||(I={}));var L=r=>new m(r);function E(r){return new p(r)}var m=class{constructor(e){this.value=e}isOk(){return!0}isErr(){return!this.isOk()}map(e){return L(e(this.value))}mapErr(e){return L(this.value)}andThen(e){return e(this.value)}andThrough(e){return e(this.value).map(t=>this.value)}andTee(e){try{e(this.value)}catch{}return L(this.value)}orElse(e){return L(this.value)}asyncAndThen(e){return e(this.value)}asyncAndThrough(e){return e(this.value).map(()=>this.value)}asyncMap(e){return y.fromSafePromise(e(this.value))}unwrapOr(e){return this.value}match(e,t){return e(this.value)}safeUnwrap(){let e=this.value;return function*(){return e}()}_unsafeUnwrap(e){return this.value}_unsafeUnwrapErr(e){throw Q("Called `_unsafeUnwrapErr` on an Ok",this,e)}*[Symbol.iterator](){return this.value}},p=class{constructor(e){this.error=e}isOk(){return!1}isErr(){return!this.isOk()}map(e){return E(this.error)}mapErr(e){return E(e(this.error))}andThrough(e){return E(this.error)}andTee(e){return E(this.error)}andThen(e){return E(this.error)}orElse(e){return e(this.error)}asyncAndThen(e){return O(this.error)}asyncAndThrough(e){return O(this.error)}asyncMap(e){return O(this.error)}unwrapOr(e){return e}match(e,t){return t(this.error)}safeUnwrap(){let e=this.error;return function*(){throw yield E(e),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(e){throw Q("Called `_unsafeUnwrap` on an Err",this,e)}_unsafeUnwrapErr(e){return this.error}*[Symbol.iterator](){let e=this;return yield e,e}},Ce=I.fromThrowable;var be=()=>typeof Deno<"u";var D=r=>be()?new URL(`./worker/${r}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${r==="main"?`worker/${r}`:r}.js`));var S=new V.default,l,K=!1;self.onmessage=r=>{De(r),K||(K=!0,S.once("OPERATION_FAILED",()=>{l&&l.terminate()}))};var ge=(r,e)=>(Object.assign(r,e),typeof WorkerGlobalScope<"u"&&self.postMessage({event:"FILE_UPDATED",lufiFile:r}),r),rr=(r,e)=>{ge(r,{uploadStatus:2}),self.postMessage({event:"OPERATION_FAILED",error:e})},De=(r,e)=>{let{action:t}=r.data;if(t===5||t===8)l.postMessage(r.data);else{switch(t){case 2:l=new Worker(D("cancel"),{type:"module"}),l.postMessage(r.data);break;case 3:l=new Worker(D("download"),{type:"module"}),l.postMessage(r.data);break;case 4:l=new Worker(D("infos"),{type:"module"}),l.postMessage(r.data);break;case 7:l=l||new Worker(D("remove"),{type:"module"}),l.postMessage(r.data);break;case 9:l=l||new Worker(D("upload"),{type:"module"}),l.postMessage(r.data);break;default:console.error("Action not found")}l.onmessage=n=>{e&&e(n),self.postMessage(n.data)},l.onerror=n=>{console.error(`Error: ${n.message}`)}}},tr=()=>{S.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),S.once("OPERATION_FAILED",r=>{self.postMessage({event:"OPERATION_FAILED",error:r})})},nr=r=>typeof r=="object"&&r!==null&&"action"in r&&Object.values(k).includes(r.action);export{S as events,tr as init,nr as isWorkerActionMessage,rr as sendFileError,ge as updateFile}; +var te=Object.create;var R=Object.defineProperty;var ne=Object.getOwnPropertyDescriptor;var oe=Object.getOwnPropertyNames;var se=Object.getPrototypeOf,ie=Object.prototype.hasOwnProperty;var ue=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var ae=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of oe(e))!ie.call(r,o)&&o!==t&&R(r,o,{get:()=>e[o],enumerable:!(n=ne(e,o))||n.enumerable});return r};var fe=(r,e,t)=>(t=r!=null?te(se(r)):{},ae(e||!r||!r.__esModule?R(t,"default",{value:r,enumerable:!0}):t,r));var G=ue((Ae,M)=>{"use strict";var b=typeof Reflect=="object"?Reflect:null,U=b&&typeof b.apply=="function"?b.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)},P;b&&typeof b.ownKeys=="function"?P=b.ownKeys:Object.getOwnPropertySymbols?P=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:P=function(e){return Object.getOwnPropertyNames(e)};function ce(r){console&&console.warn&&console.warn(r)}var T=Number.isNaN||function(e){return e!==e};function a(){a.init.call(this)}M.exports=a;M.exports.once=de;a.EventEmitter=a;a.prototype._events=void 0;a.prototype._eventsCount=0;a.prototype._maxListeners=void 0;var F=10;function x(r){if(typeof r!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof r)}Object.defineProperty(a,"defaultMaxListeners",{enumerable:!0,get:function(){return F},set:function(r){if(typeof r!="number"||r<0||T(r))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+r+".");F=r}});a.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0};a.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||T(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this};function j(r){return r._maxListeners===void 0?a.defaultMaxListeners:r._maxListeners}a.prototype.getMaxListeners=function(){return j(this)};a.prototype.emit=function(e){for(var t=[],n=1;n0&&(s=t[0]),s instanceof Error)throw s;var f=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw f.context=s,f}var h=i[e];if(h===void 0)return!1;if(typeof h=="function")U(h,this,t);else for(var m=h.length,u=B(h,m),n=0;n0&&s.length>o&&!s.warned){s.warned=!0;var f=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");f.name="MaxListenersExceededWarning",f.emitter=r,f.type=e,f.count=s.length,ce(f)}return r}a.prototype.addListener=function(e,t){return N(this,e,t,!1)};a.prototype.on=a.prototype.addListener;a.prototype.prependListener=function(e,t){return N(this,e,t,!0)};function le(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function W(r,e,t){var n={fired:!1,wrapFn:void 0,target:r,type:e,listener:t},o=le.bind(n);return o.listener=t,n.wrapFn=o,o}a.prototype.once=function(e,t){return x(t),this.on(e,W(this,e,t)),this};a.prototype.prependOnceListener=function(e,t){return x(t),this.prependListener(e,W(this,e,t)),this};a.prototype.removeListener=function(e,t){var n,o,i,s,f;if(x(t),o=this._events,o===void 0)return this;if(n=o[e],n===void 0)return this;if(n===t||n.listener===t)--this._eventsCount===0?this._events=Object.create(null):(delete o[e],o.removeListener&&this.emit("removeListener",e,n.listener||t));else if(typeof n!="function"){for(i=-1,s=n.length-1;s>=0;s--)if(n[s]===t||n[s].listener===t){f=n[s].listener,i=s;break}if(i<0)return this;i===0?n.shift():he(n,i),n.length===1&&(o[e]=n[0]),o.removeListener!==void 0&&this.emit("removeListener",e,f||t)}return this};a.prototype.off=a.prototype.removeListener;a.prototype.removeAllListeners=function(e){var t,n,o;if(n=this._events,n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[e]),this;if(arguments.length===0){var i=Object.keys(n),s;for(o=0;o=0;o--)this.removeListener(e,t[o]);return this};function J(r,e,t){var n=r._events;if(n===void 0)return[];var o=n[e];return o===void 0?[]:typeof o=="function"?t?[o.listener||o]:[o]:t?pe(o):B(o,o.length)}a.prototype.listeners=function(e){return J(this,e,!0)};a.prototype.rawListeners=function(e){return J(this,e,!1)};a.listenerCount=function(r,e){return typeof r.listenerCount=="function"?r.listenerCount(e):H.call(r,e)};a.prototype.listenerCount=H;function H(r){var e=this._events;if(e!==void 0){var t=e[r];if(typeof t=="function")return 1;if(t!==void 0)return t.length}return 0}a.prototype.eventNames=function(){return this._eventsCount>0?P(this._events):[]};function B(r,e){for(var t=new Array(e),n=0;n(u[u.ARCHIVE_ADD=0]="ARCHIVE_ADD",u[u.ARCHHIVE_COMPRESS=1]="ARCHHIVE_COMPRESS",u[u.CANCEL=2]="CANCEL",u[u.DOWNLOAD=3]="DOWNLOAD",u[u.INFOS=4]="INFOS",u[u.PAUSE=5]="PAUSE",u[u.PROVIDE_FILE=6]="PROVIDE_FILE",u[u.REMOVE=7]="REMOVE",u[u.RESUME=8]="RESUME",u[u.UPLOAD=9]="UPLOAD",u))(k||{});var ve={withStackTrace:!1},Q=(r,e,t=ve)=>{let n=e.isOk()?{type:"Ok",value:e.value}:{type:"Err",value:e.error},o=t.withStackTrace?new Error().stack:void 0;return{data:n,message:r,stack:o}};function g(r,e,t,n){function o(i){return i instanceof t?i:new t(function(s){s(i)})}return new(t||(t=Promise))(function(i,s){function f(u){try{m(n.next(u))}catch(_){s(_)}}function h(u){try{m(n.throw(u))}catch(_){s(_)}}function m(u){u.done?i(u.value):o(u.value).then(f,h)}m((n=n.apply(r,e||[])).next())})}function q(r){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&r[e],n=0;if(t)return t.call(r);if(r&&typeof r.length=="number")return{next:function(){return r&&n>=r.length&&(r=void 0),{value:r&&r[n++],done:!r}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function v(r){return this instanceof v?(this.v=r,this):new v(r)}function z(r,e,t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=t.apply(r,e||[]),o,i=[];return o=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),f("next"),f("throw"),f("return",s),o[Symbol.asyncIterator]=function(){return this},o;function s(c){return function(w){return Promise.resolve(w).then(c,_)}}function f(c,w){n[c]&&(o[c]=function(A){return new Promise(function(ee,re){i.push([c,A,ee,re])>1||h(c,A)})},w&&(o[c]=w(o[c])))}function h(c,w){try{m(n[c](w))}catch(A){C(i[0][3],A)}}function m(c){c.value instanceof v?Promise.resolve(c.value.v).then(u,_):C(i[0][2],c)}function u(c){h("next",c)}function _(c){h("throw",c)}function C(c,w){c(w),i.shift(),i.length&&h(i[0][0],i[0][1])}}function ye(r){var e,t;return e={},n("next"),n("throw",function(o){throw o}),n("return"),e[Symbol.iterator]=function(){return this},e;function n(o,i){e[o]=r[o]?function(s){return(t=!t)?{value:v(r[o](s)),done:!1}:i?i(s):s}:i}}function Ee(r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e=r[Symbol.asyncIterator],t;return e?e.call(r):(r=typeof q=="function"?q(r):r[Symbol.iterator](),t={},n("next"),n("throw"),n("return"),t[Symbol.asyncIterator]=function(){return this},t);function n(i){t[i]=r[i]&&function(s){return new Promise(function(f,h){s=r[i](s),o(f,h,s.done,s.value)})}}function o(i,s,f,h){Promise.resolve(h).then(function(m){i({value:m,done:f})},s)}}var y=class r{constructor(e){this._promise=e}static fromSafePromise(e){let t=e.then(n=>new d(n));return new r(t)}static fromPromise(e,t){let n=e.then(o=>new d(o)).catch(o=>new p(t(o)));return new r(n)}static fromThrowable(e,t){return(...n)=>new r(g(this,void 0,void 0,function*(){try{return new d(yield e(...n))}catch(o){return new p(t?t(o):o)}}))}static combine(e){return we(e)}static combineWithAllErrors(e){return Le(e)}map(e){return new r(this._promise.then(t=>g(this,void 0,void 0,function*(){return t.isErr()?new p(t.error):new d(yield e(t.value))})))}andThrough(e){return new r(this._promise.then(t=>g(this,void 0,void 0,function*(){if(t.isErr())return new p(t.error);let n=yield e(t.value);return n.isErr()?new p(n.error):new d(t.value)})))}andTee(e){return new r(this._promise.then(t=>g(this,void 0,void 0,function*(){if(t.isErr())return new p(t.error);try{yield e(t.value)}catch{}return new d(t.value)})))}mapErr(e){return new r(this._promise.then(t=>g(this,void 0,void 0,function*(){return t.isOk()?new d(t.value):new p(yield e(t.error))})))}andThen(e){return new r(this._promise.then(t=>{if(t.isErr())return new p(t.error);let n=e(t.value);return n instanceof r?n._promise:n}))}orElse(e){return new r(this._promise.then(t=>g(this,void 0,void 0,function*(){return t.isErr()?e(t.error):new d(t.value)})))}match(e,t){return this._promise.then(n=>n.match(e,t))}unwrapOr(e){return this._promise.then(t=>t.unwrapOr(e))}safeUnwrap(){return z(this,arguments,function*(){return yield v(yield v(yield*ye(Ee(yield v(this._promise.then(t=>t.safeUnwrap()))))))})}then(e,t){return this._promise.then(e,t)}[Symbol.asyncIterator](){return z(this,arguments,function*(){let t=yield v(this._promise);return t.isErr()&&(yield yield v(O(t.error))),yield v(t.value)})}};var O=r=>new y(Promise.resolve(new p(r))),ke=y.fromPromise,Ie=y.fromSafePromise,Se=y.fromThrowable,Z=r=>{let e=L([]);for(let t of r)if(t.isErr()){e=E(t.error);break}else e.map(n=>n.push(t.value));return e},we=r=>y.fromSafePromise(Promise.all(r)).andThen(Z),X=r=>{let e=L([]);for(let t of r)t.isErr()&&e.isErr()?e.error.push(t.error):t.isErr()&&e.isOk()?e=E([t.error]):t.isOk()&&e.isOk()&&e.value.push(t.value);return e},Le=r=>y.fromSafePromise(Promise.all(r)).andThen(X),I;(function(r){function e(o,i){return(...s)=>{try{let f=o(...s);return L(f)}catch(f){return E(i?i(f):f)}}}r.fromThrowable=e;function t(o){return Z(o)}r.combine=t;function n(o){return X(o)}r.combineWithAllErrors=n})(I||(I={}));var L=r=>new d(r);function E(r){return new p(r)}var d=class{constructor(e){this.value=e}isOk(){return!0}isErr(){return!this.isOk()}map(e){return L(e(this.value))}mapErr(e){return L(this.value)}andThen(e){return e(this.value)}andThrough(e){return e(this.value).map(t=>this.value)}andTee(e){try{e(this.value)}catch{}return L(this.value)}orElse(e){return L(this.value)}asyncAndThen(e){return e(this.value)}asyncAndThrough(e){return e(this.value).map(()=>this.value)}asyncMap(e){return y.fromSafePromise(e(this.value))}unwrapOr(e){return this.value}match(e,t){return e(this.value)}safeUnwrap(){let e=this.value;return function*(){return e}()}_unsafeUnwrap(e){return this.value}_unsafeUnwrapErr(e){throw Q("Called `_unsafeUnwrapErr` on an Ok",this,e)}*[Symbol.iterator](){return this.value}},p=class{constructor(e){this.error=e}isOk(){return!1}isErr(){return!this.isOk()}map(e){return E(this.error)}mapErr(e){return E(e(this.error))}andThrough(e){return E(this.error)}andTee(e){return E(this.error)}andThen(e){return E(this.error)}orElse(e){return e(this.error)}asyncAndThen(e){return O(this.error)}asyncAndThrough(e){return O(this.error)}asyncMap(e){return O(this.error)}unwrapOr(e){return e}match(e,t){return t(this.error)}safeUnwrap(){let e=this.error;return function*(){throw yield E(e),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(e){throw Q("Called `_unsafeUnwrap` on an Err",this,e)}_unsafeUnwrapErr(e){return this.error}*[Symbol.iterator](){let e=this;return yield e,e}},Ce=I.fromThrowable;var be=()=>typeof Deno<"u";var D=r=>be()?new URL(`./worker/${r}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${r==="main"?`worker/${r}`:r}.js`));var S=new V.default,l,K=!1;self.onmessage=r=>{De(r),K||(K=!0,S.once("OPERATION_FAILED",()=>{l&&l.terminate()}))};var ge=(r,e)=>(Object.assign(r,e),typeof WorkerGlobalScope<"u"&&self.postMessage({event:"FILE_UPDATED",lufiFile:r}),r),rr=(r,e)=>{ge(r,{uploadStatus:2}),self.postMessage({event:"OPERATION_FAILED",error:e})},De=(r,e)=>{let{action:t}=r.data;if(t===5||t===8)l.postMessage(r.data,r.data);else{switch(t){case 2:l=new Worker(D("cancel"),{type:"module"}),l.postMessage(r.data,r.data);break;case 3:l=new Worker(D("download"),{type:"module"}),l.postMessage(r.data,r.data);break;case 4:l=new Worker(D("infos"),{type:"module"}),l.postMessage(r.data,r.data);break;case 7:l=l||new Worker(D("remove"),{type:"module"}),l.postMessage(r.data,r.data);break;case 9:l=l||new Worker(D("upload"),{type:"module"}),l.postMessage(r.data,r.data);break;default:console.error("Action not found")}l.onmessage=n=>{e&&e(n),self.postMessage(n.data,n.data)},l.onerror=n=>{console.error(`Error: ${n.message}`)}}},tr=()=>{S.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),S.once("OPERATION_FAILED",r=>{self.postMessage({event:"OPERATION_FAILED",error:r})})},nr=r=>typeof r=="object"&&r!==null&&"action"in r&&Object.values(k).includes(r.action);export{S as events,tr as init,nr as isWorkerActionMessage,rr as sendFileError,ge as updateFile}; diff --git a/themes/default/public/js/worker/remove.js b/themes/default/public/js/worker/remove.js index 0de5de4..233cf5a 100644 --- a/themes/default/public/js/worker/remove.js +++ b/themes/default/public/js/worker/remove.js @@ -1 +1 @@ -var ue=Object.create;var C=Object.defineProperty;var ae=Object.getOwnPropertyDescriptor;var fe=Object.getOwnPropertyNames;var ce=Object.getPrototypeOf,le=Object.prototype.hasOwnProperty;var he=(r,e,t)=>e in r?C(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var pe=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var me=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of fe(e))!le.call(r,o)&&o!==t&&C(r,o,{get:()=>e[o],enumerable:!(n=ae(e,o))||n.enumerable});return r};var de=(r,e,t)=>(t=r!=null?ue(ce(r)):{},me(e||!r||!r.__esModule?C(t,"default",{value:r,enumerable:!0}):t,r));var g=(r,e,t)=>he(r,typeof e!="symbol"?e+"":e,t);var ee=pe((Ke,T)=>{"use strict";var A=typeof Reflect=="object"?Reflect:null,$=A&&typeof A.apply=="function"?A.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)},P;A&&typeof A.ownKeys=="function"?P=A.ownKeys:Object.getOwnPropertySymbols?P=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:P=function(e){return Object.getOwnPropertyNames(e)};function ge(r){console&&console.warn&&console.warn(r)}var q=Number.isNaN||function(e){return e!==e};function u(){u.init.call(this)}T.exports=u;T.exports.once=Ae;u.EventEmitter=u;u.prototype._events=void 0;u.prototype._eventsCount=0;u.prototype._maxListeners=void 0;var G=10;function M(r){if(typeof r!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof r)}Object.defineProperty(u,"defaultMaxListeners",{enumerable:!0,get:function(){return G},set:function(r){if(typeof r!="number"||r<0||q(r))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+r+".");G=r}});u.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0};u.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||q(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this};function z(r){return r._maxListeners===void 0?u.defaultMaxListeners:r._maxListeners}u.prototype.getMaxListeners=function(){return z(this)};u.prototype.emit=function(e){for(var t=[],n=1;n0&&(i=t[0]),i instanceof Error)throw i;var a=new Error("Unhandled error."+(i?" ("+i.message+")":""));throw a.context=i,a}var l=s[e];if(l===void 0)return!1;if(typeof l=="function")$(l,this,t);else for(var v=l.length,m=K(l,v),n=0;n0&&i.length>o&&!i.warned){i.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+i.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning",a.emitter=r,a.type=e,a.count=i.length,ge(a)}return r}u.prototype.addListener=function(e,t){return Q(this,e,t,!1)};u.prototype.on=u.prototype.addListener;u.prototype.prependListener=function(e,t){return Q(this,e,t,!0)};function be(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function Z(r,e,t){var n={fired:!1,wrapFn:void 0,target:r,type:e,listener:t},o=be.bind(n);return o.listener=t,n.wrapFn=o,o}u.prototype.once=function(e,t){return M(t),this.on(e,Z(this,e,t)),this};u.prototype.prependOnceListener=function(e,t){return M(t),this.prependListener(e,Z(this,e,t)),this};u.prototype.removeListener=function(e,t){var n,o,s,i,a;if(M(t),o=this._events,o===void 0)return this;if(n=o[e],n===void 0)return this;if(n===t||n.listener===t)--this._eventsCount===0?this._events=Object.create(null):(delete o[e],o.removeListener&&this.emit("removeListener",e,n.listener||t));else if(typeof n!="function"){for(s=-1,i=n.length-1;i>=0;i--)if(n[i]===t||n[i].listener===t){a=n[i].listener,s=i;break}if(s<0)return this;s===0?n.shift():De(n,s),n.length===1&&(o[e]=n[0]),o.removeListener!==void 0&&this.emit("removeListener",e,a||t)}return this};u.prototype.off=u.prototype.removeListener;u.prototype.removeAllListeners=function(e){var t,n,o;if(n=this._events,n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[e]),this;if(arguments.length===0){var s=Object.keys(n),i;for(o=0;o=0;o--)this.removeListener(e,t[o]);return this};function X(r,e,t){var n=r._events;if(n===void 0)return[];var o=n[e];return o===void 0?[]:typeof o=="function"?t?[o.listener||o]:[o]:t?Oe(o):K(o,o.length)}u.prototype.listeners=function(e){return X(this,e,!0)};u.prototype.rawListeners=function(e){return X(this,e,!1)};u.listenerCount=function(r,e){return typeof r.listenerCount=="function"?r.listenerCount(e):Y.call(r,e)};u.prototype.listenerCount=Y;function Y(r){var e=this._events;if(e!==void 0){var t=e[r];if(typeof t=="function")return 1;if(t!==void 0)return t.length}return 0}u.prototype.eventNames=function(){return this._eventsCount>0?P(this._events):[]};function K(r,e){for(var t=new Array(e),n=0;n{let n=e.isOk()?{type:"Ok",value:e.value}:{type:"Err",value:e.error},o=t.withStackTrace?new Error().stack:void 0;return{data:n,message:r,stack:o}};function b(r,e,t,n){function o(s){return s instanceof t?s:new t(function(i){i(s)})}return new(t||(t=Promise))(function(s,i){function a(m){try{v(n.next(m))}catch(_){i(_)}}function l(m){try{v(n.throw(m))}catch(_){i(_)}}function v(m){m.done?s(m.value):o(m.value).then(a,l)}v((n=n.apply(r,e||[])).next())})}function N(r){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&r[e],n=0;if(t)return t.call(r);if(r&&typeof r.length=="number")return{next:function(){return r&&n>=r.length&&(r=void 0),{value:r&&r[n++],done:!r}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function E(r){return this instanceof E?(this.v=r,this):new E(r)}function W(r,e,t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=t.apply(r,e||[]),o,s=[];return o=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),a("next"),a("throw"),a("return",i),o[Symbol.asyncIterator]=function(){return this},o;function i(f){return function(w){return Promise.resolve(w).then(f,_)}}function a(f,w){n[f]&&(o[f]=function(x){return new Promise(function(se,ie){s.push([f,x,se,ie])>1||l(f,x)})},w&&(o[f]=w(o[f])))}function l(f,w){try{v(n[f](w))}catch(x){j(s[0][3],x)}}function v(f){f.value instanceof E?Promise.resolve(f.value.v).then(m,_):j(s[0][2],f)}function m(f){l("next",f)}function _(f){l("throw",f)}function j(f,w){f(w),s.shift(),s.length&&l(s[0][0],s[0][1])}}function Ee(r){var e,t;return e={},n("next"),n("throw",function(o){throw o}),n("return"),e[Symbol.iterator]=function(){return this},e;function n(o,s){e[o]=r[o]?function(i){return(t=!t)?{value:E(r[o](i)),done:!1}:s?s(i):i}:s}}function ye(r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e=r[Symbol.asyncIterator],t;return e?e.call(r):(r=typeof N=="function"?N(r):r[Symbol.iterator](),t={},n("next"),n("throw"),n("return"),t[Symbol.asyncIterator]=function(){return this},t);function n(s){t[s]=r[s]&&function(i){return new Promise(function(a,l){i=r[s](i),o(a,l,i.done,i.value)})}}function o(s,i,a,l){Promise.resolve(l).then(function(v){s({value:v,done:a})},i)}}var p=class r{constructor(e){this._promise=e}static fromSafePromise(e){let t=e.then(n=>new d(n));return new r(t)}static fromPromise(e,t){let n=e.then(o=>new d(o)).catch(o=>new h(t(o)));return new r(n)}static fromThrowable(e,t){return(...n)=>new r(b(this,void 0,void 0,function*(){try{return new d(yield e(...n))}catch(o){return new h(t?t(o):o)}}))}static combine(e){return we(e)}static combineWithAllErrors(e){return Le(e)}map(e){return new r(this._promise.then(t=>b(this,void 0,void 0,function*(){return t.isErr()?new h(t.error):new d(yield e(t.value))})))}andThrough(e){return new r(this._promise.then(t=>b(this,void 0,void 0,function*(){if(t.isErr())return new h(t.error);let n=yield e(t.value);return n.isErr()?new h(n.error):new d(t.value)})))}andTee(e){return new r(this._promise.then(t=>b(this,void 0,void 0,function*(){if(t.isErr())return new h(t.error);try{yield e(t.value)}catch{}return new d(t.value)})))}mapErr(e){return new r(this._promise.then(t=>b(this,void 0,void 0,function*(){return t.isOk()?new d(t.value):new h(yield e(t.error))})))}andThen(e){return new r(this._promise.then(t=>{if(t.isErr())return new h(t.error);let n=e(t.value);return n instanceof r?n._promise:n}))}orElse(e){return new r(this._promise.then(t=>b(this,void 0,void 0,function*(){return t.isErr()?e(t.error):new d(t.value)})))}match(e,t){return this._promise.then(n=>n.match(e,t))}unwrapOr(e){return this._promise.then(t=>t.unwrapOr(e))}safeUnwrap(){return W(this,arguments,function*(){return yield E(yield E(yield*Ee(ye(yield E(this._promise.then(t=>t.safeUnwrap()))))))})}then(e,t){return this._promise.then(e,t)}[Symbol.asyncIterator](){return W(this,arguments,function*(){let t=yield E(this._promise);return t.isErr()&&(yield yield E(k(t.error))),yield E(t.value)})}};var k=r=>new p(Promise.resolve(new h(r))),Ce=p.fromPromise,Fe=p.fromSafePromise,Re=p.fromThrowable,H=r=>{let e=L([]);for(let t of r)if(t.isErr()){e=y(t.error);break}else e.map(n=>n.push(t.value));return e},we=r=>p.fromSafePromise(Promise.all(r)).andThen(H),B=r=>{let e=L([]);for(let t of r)t.isErr()&&e.isErr()?e.error.push(t.error):t.isErr()&&e.isOk()?e=y([t.error]):t.isOk()&&e.isOk()&&e.value.push(t.value);return e},Le=r=>p.fromSafePromise(Promise.all(r)).andThen(B),F;(function(r){function e(o,s){return(...i)=>{try{let a=o(...i);return L(a)}catch(a){return y(s?s(a):a)}}}r.fromThrowable=e;function t(o){return H(o)}r.combine=t;function n(o){return B(o)}r.combineWithAllErrors=n})(F||(F={}));var L=r=>new d(r);function y(r){return new h(r)}var d=class{constructor(e){this.value=e}isOk(){return!0}isErr(){return!this.isOk()}map(e){return L(e(this.value))}mapErr(e){return L(this.value)}andThen(e){return e(this.value)}andThrough(e){return e(this.value).map(t=>this.value)}andTee(e){try{e(this.value)}catch{}return L(this.value)}orElse(e){return L(this.value)}asyncAndThen(e){return e(this.value)}asyncAndThrough(e){return e(this.value).map(()=>this.value)}asyncMap(e){return p.fromSafePromise(e(this.value))}unwrapOr(e){return this.value}match(e,t){return e(this.value)}safeUnwrap(){let e=this.value;return function*(){return e}()}_unsafeUnwrap(e){return this.value}_unsafeUnwrapErr(e){throw J("Called `_unsafeUnwrapErr` on an Ok",this,e)}*[Symbol.iterator](){return this.value}},h=class{constructor(e){this.error=e}isOk(){return!1}isErr(){return!this.isOk()}map(e){return y(this.error)}mapErr(e){return y(e(this.error))}andThrough(e){return y(this.error)}andTee(e){return y(this.error)}andThen(e){return y(this.error)}orElse(e){return e(this.error)}asyncAndThen(e){return k(this.error)}asyncAndThrough(e){return k(this.error)}asyncMap(e){return k(this.error)}unwrapOr(e){return e}match(e,t){return t(this.error)}safeUnwrap(){let e=this.error;return function*(){throw yield y(e),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(e){throw J("Called `_unsafeUnwrap` on an Err",this,e)}_unsafeUnwrapErr(e){return this.error}*[Symbol.iterator](){let e=this;return yield e,e}},Te=F.fromThrowable;var D=class extends Error{constructor(t,n={}){let{cause:o,context:s}=n;super(t,{cause:o});g(this,"context");this.name=this.constructor.name,this.context=s}};var R=r=>{if(r instanceof Error)return r;let e="[Unable to stringify the thrown value]";try{e=JSON.stringify(r)}catch{}return new Error(e)};var _e=()=>typeof Deno<"u";var O=r=>_e()?new URL(`./worker/${r}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${r==="main"?`worker/${r}`:r}.js`));var te=de(ee());var U=new te.default,c,re=!1;self.onmessage=r=>{Pe(r),re||(re=!0,U.once("OPERATION_FAILED",()=>{c&&c.terminate()}))};var Pe=(r,e)=>{let{action:t}=r.data;if(t===5||t===8)c.postMessage(r.data);else{switch(t){case 2:c=new Worker(O("cancel"),{type:"module"}),c.postMessage(r.data);break;case 3:c=new Worker(O("download"),{type:"module"}),c.postMessage(r.data);break;case 4:c=new Worker(O("infos"),{type:"module"}),c.postMessage(r.data);break;case 7:c=c||new Worker(O("remove"),{type:"module"}),c.postMessage(r.data);break;case 9:c=c||new Worker(O("upload"),{type:"module"}),c.postMessage(r.data);break;default:console.error("Action not found")}c.onmessage=n=>{e&&e(n),self.postMessage(n.data)},c.onerror=n=>{console.error(`Error: ${n.message}`)}}},ne=()=>{U.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),U.once("OPERATION_FAILED",r=>{self.postMessage({event:"OPERATION_FAILED",error:r})})};var I=class extends D{};var S=class extends I{constructor(){super(...arguments);g(this,"message","Failed to remove the file")}};var oe=!1;self.onmessage=r=>{oe||(ne(),oe=!0),Me(r.data).map(()=>{self.postMessage({event:"FILE_REMOVED"})}).mapErr(e=>{self.postMessage({event:"OPERATION_FAILED",error:e})})};var Me=r=>p.fromPromise(new Promise((e,t)=>{let n=r.args.lufiFile;fetch(`${new URL(n.serverUrl).href}d/${n.keys.server}/${n.actionToken}`).then(o=>o.ok?e(void 0):t(new S(void 0,{cause:R(o.statusText)})))}),e=>R(e)); +var ue=Object.create;var C=Object.defineProperty;var ae=Object.getOwnPropertyDescriptor;var fe=Object.getOwnPropertyNames;var ce=Object.getPrototypeOf,le=Object.prototype.hasOwnProperty;var he=(r,e,t)=>e in r?C(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var pe=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var me=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of fe(e))!le.call(r,o)&&o!==t&&C(r,o,{get:()=>e[o],enumerable:!(n=ae(e,o))||n.enumerable});return r};var de=(r,e,t)=>(t=r!=null?ue(ce(r)):{},me(e||!r||!r.__esModule?C(t,"default",{value:r,enumerable:!0}):t,r));var g=(r,e,t)=>he(r,typeof e!="symbol"?e+"":e,t);var ee=pe((Ke,T)=>{"use strict";var A=typeof Reflect=="object"?Reflect:null,$=A&&typeof A.apply=="function"?A.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)},P;A&&typeof A.ownKeys=="function"?P=A.ownKeys:Object.getOwnPropertySymbols?P=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:P=function(e){return Object.getOwnPropertyNames(e)};function ge(r){console&&console.warn&&console.warn(r)}var q=Number.isNaN||function(e){return e!==e};function u(){u.init.call(this)}T.exports=u;T.exports.once=Ae;u.EventEmitter=u;u.prototype._events=void 0;u.prototype._eventsCount=0;u.prototype._maxListeners=void 0;var G=10;function M(r){if(typeof r!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof r)}Object.defineProperty(u,"defaultMaxListeners",{enumerable:!0,get:function(){return G},set:function(r){if(typeof r!="number"||r<0||q(r))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+r+".");G=r}});u.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0};u.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||q(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this};function z(r){return r._maxListeners===void 0?u.defaultMaxListeners:r._maxListeners}u.prototype.getMaxListeners=function(){return z(this)};u.prototype.emit=function(e){for(var t=[],n=1;n0&&(i=t[0]),i instanceof Error)throw i;var a=new Error("Unhandled error."+(i?" ("+i.message+")":""));throw a.context=i,a}var l=s[e];if(l===void 0)return!1;if(typeof l=="function")$(l,this,t);else for(var v=l.length,m=K(l,v),n=0;n0&&i.length>o&&!i.warned){i.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+i.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning",a.emitter=r,a.type=e,a.count=i.length,ge(a)}return r}u.prototype.addListener=function(e,t){return Q(this,e,t,!1)};u.prototype.on=u.prototype.addListener;u.prototype.prependListener=function(e,t){return Q(this,e,t,!0)};function be(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function Z(r,e,t){var n={fired:!1,wrapFn:void 0,target:r,type:e,listener:t},o=be.bind(n);return o.listener=t,n.wrapFn=o,o}u.prototype.once=function(e,t){return M(t),this.on(e,Z(this,e,t)),this};u.prototype.prependOnceListener=function(e,t){return M(t),this.prependListener(e,Z(this,e,t)),this};u.prototype.removeListener=function(e,t){var n,o,s,i,a;if(M(t),o=this._events,o===void 0)return this;if(n=o[e],n===void 0)return this;if(n===t||n.listener===t)--this._eventsCount===0?this._events=Object.create(null):(delete o[e],o.removeListener&&this.emit("removeListener",e,n.listener||t));else if(typeof n!="function"){for(s=-1,i=n.length-1;i>=0;i--)if(n[i]===t||n[i].listener===t){a=n[i].listener,s=i;break}if(s<0)return this;s===0?n.shift():De(n,s),n.length===1&&(o[e]=n[0]),o.removeListener!==void 0&&this.emit("removeListener",e,a||t)}return this};u.prototype.off=u.prototype.removeListener;u.prototype.removeAllListeners=function(e){var t,n,o;if(n=this._events,n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[e]),this;if(arguments.length===0){var s=Object.keys(n),i;for(o=0;o=0;o--)this.removeListener(e,t[o]);return this};function X(r,e,t){var n=r._events;if(n===void 0)return[];var o=n[e];return o===void 0?[]:typeof o=="function"?t?[o.listener||o]:[o]:t?Oe(o):K(o,o.length)}u.prototype.listeners=function(e){return X(this,e,!0)};u.prototype.rawListeners=function(e){return X(this,e,!1)};u.listenerCount=function(r,e){return typeof r.listenerCount=="function"?r.listenerCount(e):Y.call(r,e)};u.prototype.listenerCount=Y;function Y(r){var e=this._events;if(e!==void 0){var t=e[r];if(typeof t=="function")return 1;if(t!==void 0)return t.length}return 0}u.prototype.eventNames=function(){return this._eventsCount>0?P(this._events):[]};function K(r,e){for(var t=new Array(e),n=0;n{let n=e.isOk()?{type:"Ok",value:e.value}:{type:"Err",value:e.error},o=t.withStackTrace?new Error().stack:void 0;return{data:n,message:r,stack:o}};function b(r,e,t,n){function o(s){return s instanceof t?s:new t(function(i){i(s)})}return new(t||(t=Promise))(function(s,i){function a(m){try{v(n.next(m))}catch(_){i(_)}}function l(m){try{v(n.throw(m))}catch(_){i(_)}}function v(m){m.done?s(m.value):o(m.value).then(a,l)}v((n=n.apply(r,e||[])).next())})}function N(r){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&r[e],n=0;if(t)return t.call(r);if(r&&typeof r.length=="number")return{next:function(){return r&&n>=r.length&&(r=void 0),{value:r&&r[n++],done:!r}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function E(r){return this instanceof E?(this.v=r,this):new E(r)}function W(r,e,t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=t.apply(r,e||[]),o,s=[];return o=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),a("next"),a("throw"),a("return",i),o[Symbol.asyncIterator]=function(){return this},o;function i(f){return function(w){return Promise.resolve(w).then(f,_)}}function a(f,w){n[f]&&(o[f]=function(x){return new Promise(function(se,ie){s.push([f,x,se,ie])>1||l(f,x)})},w&&(o[f]=w(o[f])))}function l(f,w){try{v(n[f](w))}catch(x){j(s[0][3],x)}}function v(f){f.value instanceof E?Promise.resolve(f.value.v).then(m,_):j(s[0][2],f)}function m(f){l("next",f)}function _(f){l("throw",f)}function j(f,w){f(w),s.shift(),s.length&&l(s[0][0],s[0][1])}}function Ee(r){var e,t;return e={},n("next"),n("throw",function(o){throw o}),n("return"),e[Symbol.iterator]=function(){return this},e;function n(o,s){e[o]=r[o]?function(i){return(t=!t)?{value:E(r[o](i)),done:!1}:s?s(i):i}:s}}function ye(r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e=r[Symbol.asyncIterator],t;return e?e.call(r):(r=typeof N=="function"?N(r):r[Symbol.iterator](),t={},n("next"),n("throw"),n("return"),t[Symbol.asyncIterator]=function(){return this},t);function n(s){t[s]=r[s]&&function(i){return new Promise(function(a,l){i=r[s](i),o(a,l,i.done,i.value)})}}function o(s,i,a,l){Promise.resolve(l).then(function(v){s({value:v,done:a})},i)}}var p=class r{constructor(e){this._promise=e}static fromSafePromise(e){let t=e.then(n=>new d(n));return new r(t)}static fromPromise(e,t){let n=e.then(o=>new d(o)).catch(o=>new h(t(o)));return new r(n)}static fromThrowable(e,t){return(...n)=>new r(b(this,void 0,void 0,function*(){try{return new d(yield e(...n))}catch(o){return new h(t?t(o):o)}}))}static combine(e){return we(e)}static combineWithAllErrors(e){return Le(e)}map(e){return new r(this._promise.then(t=>b(this,void 0,void 0,function*(){return t.isErr()?new h(t.error):new d(yield e(t.value))})))}andThrough(e){return new r(this._promise.then(t=>b(this,void 0,void 0,function*(){if(t.isErr())return new h(t.error);let n=yield e(t.value);return n.isErr()?new h(n.error):new d(t.value)})))}andTee(e){return new r(this._promise.then(t=>b(this,void 0,void 0,function*(){if(t.isErr())return new h(t.error);try{yield e(t.value)}catch{}return new d(t.value)})))}mapErr(e){return new r(this._promise.then(t=>b(this,void 0,void 0,function*(){return t.isOk()?new d(t.value):new h(yield e(t.error))})))}andThen(e){return new r(this._promise.then(t=>{if(t.isErr())return new h(t.error);let n=e(t.value);return n instanceof r?n._promise:n}))}orElse(e){return new r(this._promise.then(t=>b(this,void 0,void 0,function*(){return t.isErr()?e(t.error):new d(t.value)})))}match(e,t){return this._promise.then(n=>n.match(e,t))}unwrapOr(e){return this._promise.then(t=>t.unwrapOr(e))}safeUnwrap(){return W(this,arguments,function*(){return yield E(yield E(yield*Ee(ye(yield E(this._promise.then(t=>t.safeUnwrap()))))))})}then(e,t){return this._promise.then(e,t)}[Symbol.asyncIterator](){return W(this,arguments,function*(){let t=yield E(this._promise);return t.isErr()&&(yield yield E(k(t.error))),yield E(t.value)})}};var k=r=>new p(Promise.resolve(new h(r))),Ce=p.fromPromise,Fe=p.fromSafePromise,Re=p.fromThrowable,H=r=>{let e=L([]);for(let t of r)if(t.isErr()){e=y(t.error);break}else e.map(n=>n.push(t.value));return e},we=r=>p.fromSafePromise(Promise.all(r)).andThen(H),B=r=>{let e=L([]);for(let t of r)t.isErr()&&e.isErr()?e.error.push(t.error):t.isErr()&&e.isOk()?e=y([t.error]):t.isOk()&&e.isOk()&&e.value.push(t.value);return e},Le=r=>p.fromSafePromise(Promise.all(r)).andThen(B),F;(function(r){function e(o,s){return(...i)=>{try{let a=o(...i);return L(a)}catch(a){return y(s?s(a):a)}}}r.fromThrowable=e;function t(o){return H(o)}r.combine=t;function n(o){return B(o)}r.combineWithAllErrors=n})(F||(F={}));var L=r=>new d(r);function y(r){return new h(r)}var d=class{constructor(e){this.value=e}isOk(){return!0}isErr(){return!this.isOk()}map(e){return L(e(this.value))}mapErr(e){return L(this.value)}andThen(e){return e(this.value)}andThrough(e){return e(this.value).map(t=>this.value)}andTee(e){try{e(this.value)}catch{}return L(this.value)}orElse(e){return L(this.value)}asyncAndThen(e){return e(this.value)}asyncAndThrough(e){return e(this.value).map(()=>this.value)}asyncMap(e){return p.fromSafePromise(e(this.value))}unwrapOr(e){return this.value}match(e,t){return e(this.value)}safeUnwrap(){let e=this.value;return function*(){return e}()}_unsafeUnwrap(e){return this.value}_unsafeUnwrapErr(e){throw J("Called `_unsafeUnwrapErr` on an Ok",this,e)}*[Symbol.iterator](){return this.value}},h=class{constructor(e){this.error=e}isOk(){return!1}isErr(){return!this.isOk()}map(e){return y(this.error)}mapErr(e){return y(e(this.error))}andThrough(e){return y(this.error)}andTee(e){return y(this.error)}andThen(e){return y(this.error)}orElse(e){return e(this.error)}asyncAndThen(e){return k(this.error)}asyncAndThrough(e){return k(this.error)}asyncMap(e){return k(this.error)}unwrapOr(e){return e}match(e,t){return t(this.error)}safeUnwrap(){let e=this.error;return function*(){throw yield y(e),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(e){throw J("Called `_unsafeUnwrap` on an Err",this,e)}_unsafeUnwrapErr(e){return this.error}*[Symbol.iterator](){let e=this;return yield e,e}},Te=F.fromThrowable;var D=class extends Error{constructor(t,n={}){let{cause:o,context:s}=n;super(t,{cause:o});g(this,"context");this.name=this.constructor.name,this.context=s}};var R=r=>{if(r instanceof Error)return r;let e="[Unable to stringify the thrown value]";try{e=JSON.stringify(r)}catch{}return new Error(e)};var _e=()=>typeof Deno<"u";var O=r=>_e()?new URL(`./worker/${r}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${r==="main"?`worker/${r}`:r}.js`));var te=de(ee());var U=new te.default,c,re=!1;self.onmessage=r=>{Pe(r),re||(re=!0,U.once("OPERATION_FAILED",()=>{c&&c.terminate()}))};var Pe=(r,e)=>{let{action:t}=r.data;if(t===5||t===8)c.postMessage(r.data,r.data);else{switch(t){case 2:c=new Worker(O("cancel"),{type:"module"}),c.postMessage(r.data,r.data);break;case 3:c=new Worker(O("download"),{type:"module"}),c.postMessage(r.data,r.data);break;case 4:c=new Worker(O("infos"),{type:"module"}),c.postMessage(r.data,r.data);break;case 7:c=c||new Worker(O("remove"),{type:"module"}),c.postMessage(r.data,r.data);break;case 9:c=c||new Worker(O("upload"),{type:"module"}),c.postMessage(r.data,r.data);break;default:console.error("Action not found")}c.onmessage=n=>{e&&e(n),self.postMessage(n.data,n.data)},c.onerror=n=>{console.error(`Error: ${n.message}`)}}},ne=()=>{U.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),U.once("OPERATION_FAILED",r=>{self.postMessage({event:"OPERATION_FAILED",error:r})})};var I=class extends D{};var S=class extends I{constructor(){super(...arguments);g(this,"message","Failed to remove the file")}};var oe=!1;self.onmessage=r=>{oe||(ne(),oe=!0),Me(r.data).map(()=>{self.postMessage({event:"FILE_REMOVED"})}).mapErr(e=>{self.postMessage({event:"OPERATION_FAILED",error:e})})};var Me=r=>p.fromPromise(new Promise((e,t)=>{let n=r.args.lufiFile;fetch(`${new URL(n.serverUrl).href}d/${n.keys.server}/${n.actionToken}`).then(o=>o.ok?e(void 0):t(new S(void 0,{cause:R(o.statusText)})))}),e=>R(e)); diff --git a/themes/default/public/js/worker/upload.js b/themes/default/public/js/worker/upload.js index 198accc..341c1e0 100644 --- a/themes/default/public/js/worker/upload.js +++ b/themes/default/public/js/worker/upload.js @@ -1 +1 @@ -var kr=Object.create;var lt=Object.defineProperty;var Cr=Object.getOwnPropertyDescriptor;var Pr=Object.getOwnPropertyNames;var Sr=Object.getPrototypeOf,Tr=Object.prototype.hasOwnProperty;var Rt=e=>{throw TypeError(e)};var Rr=(e,t,r)=>t in e?lt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var Ir=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,r)=>(typeof require<"u"?require:t)[r]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var ht=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Mr=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Pr(t))!Tr.call(e,o)&&o!==r&<(e,o,{get:()=>t[o],enumerable:!(n=Cr(t,o))||n.enumerable});return e};var xe=(e,t,r)=>(r=e!=null?kr(Sr(e)):{},Mr(t||!e||!e.__esModule?lt(r,"default",{value:e,enumerable:!0}):r,e));var A=(e,t,r)=>Rr(e,typeof t!="symbol"?t+"":t,r),pt=(e,t,r)=>t.has(e)||Rt("Cannot "+r);var p=(e,t,r)=>(pt(e,t,"read from private field"),r?r.call(e):t.get(e)),L=(e,t,r)=>t.has(e)?Rt("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,r),E=(e,t,r,n)=>(pt(e,t,"write to private field"),n?n.call(e,r):t.set(e,r),r),x=(e,t,r)=>(pt(e,t,"access private method"),r);var He=(e,t,r,n)=>({set _(o){E(e,t,o,r)},get _(){return p(e,t,n)}});var Ge=ht((Zn,mt)=>{"use strict";var ce=typeof Reflect=="object"?Reflect:null,Bt=ce&&typeof ce.apply=="function"?ce.apply:function(t,r,n){return Function.prototype.apply.call(t,r,n)},$e;ce&&typeof ce.ownKeys=="function"?$e=ce.ownKeys:Object.getOwnPropertySymbols?$e=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:$e=function(t){return Object.getOwnPropertyNames(t)};function zr(e){console&&console.warn&&console.warn(e)}var Wt=Number.isNaN||function(t){return t!==t};function g(){g.init.call(this)}mt.exports=g;mt.exports.once=qr;g.EventEmitter=g;g.prototype._events=void 0;g.prototype._eventsCount=0;g.prototype._maxListeners=void 0;var jt=10;function qe(e){if(typeof e!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}Object.defineProperty(g,"defaultMaxListeners",{enumerable:!0,get:function(){return jt},set:function(e){if(typeof e!="number"||e<0||Wt(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");jt=e}});g.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0};g.prototype.setMaxListeners=function(t){if(typeof t!="number"||t<0||Wt(t))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+t+".");return this._maxListeners=t,this};function zt(e){return e._maxListeners===void 0?g.defaultMaxListeners:e._maxListeners}g.prototype.getMaxListeners=function(){return zt(this)};g.prototype.emit=function(t){for(var r=[],n=1;n0&&(s=r[0]),s instanceof Error)throw s;var c=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw c.context=s,c}var u=i[t];if(u===void 0)return!1;if(typeof u=="function")Bt(u,this,r);else for(var f=u.length,l=Gt(u,f),n=0;n0&&s.length>o&&!s.warned){s.warned=!0;var c=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");c.name="MaxListenersExceededWarning",c.emitter=e,c.type=t,c.count=s.length,zr(c)}return e}g.prototype.addListener=function(t,r){return Jt(this,t,r,!1)};g.prototype.on=g.prototype.addListener;g.prototype.prependListener=function(t,r){return Jt(this,t,r,!0)};function Jr(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function Ht(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},o=Jr.bind(n);return o.listener=r,n.wrapFn=o,o}g.prototype.once=function(t,r){return qe(r),this.on(t,Ht(this,t,r)),this};g.prototype.prependOnceListener=function(t,r){return qe(r),this.prependListener(t,Ht(this,t,r)),this};g.prototype.removeListener=function(t,r){var n,o,i,s,c;if(qe(r),o=this._events,o===void 0)return this;if(n=o[t],n===void 0)return this;if(n===r||n.listener===r)--this._eventsCount===0?this._events=Object.create(null):(delete o[t],o.removeListener&&this.emit("removeListener",t,n.listener||r));else if(typeof n!="function"){for(i=-1,s=n.length-1;s>=0;s--)if(n[s]===r||n[s].listener===r){c=n[s].listener,i=s;break}if(i<0)return this;i===0?n.shift():Hr(n,i),n.length===1&&(o[t]=n[0]),o.removeListener!==void 0&&this.emit("removeListener",t,c||r)}return this};g.prototype.off=g.prototype.removeListener;g.prototype.removeAllListeners=function(t){var r,n,o;if(n=this._events,n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[t]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[t]),this;if(arguments.length===0){var i=Object.keys(n),s;for(o=0;o=0;o--)this.removeListener(t,r[o]);return this};function $t(e,t,r){var n=e._events;if(n===void 0)return[];var o=n[t];return o===void 0?[]:typeof o=="function"?r?[o.listener||o]:[o]:r?$r(o):Gt(o,o.length)}g.prototype.listeners=function(t){return $t(this,t,!0)};g.prototype.rawListeners=function(t){return $t(this,t,!1)};g.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):qt.call(e,t)};g.prototype.listenerCount=qt;function qt(e){var t=this._events;if(t!==void 0){var r=t[e];if(typeof r=="function")return 1;if(r!==void 0)return r.length}return 0}g.prototype.eventNames=function(){return this._eventsCount>0?$e(this._events):[]};function Gt(e,t){for(var r=new Array(t),n=0;n{"use strict";var a={cipher:{},hash:{},keyexchange:{},mode:{},misc:{},codec:{},exception:{corrupt:function(e){this.toString=function(){return"CORRUPT: "+this.message},this.message=e},invalid:function(e){this.toString=function(){return"INVALID: "+this.message},this.message=e},bug:function(e){this.toString=function(){return"BUG: "+this.message},this.message=e},notReady:function(e){this.toString=function(){return"NOT READY: "+this.message},this.message=e}}};a.cipher.aes=function(e){this.w[0][0][0]||this.C();var t,r,n,o,i=this.w[0][4],s=this.w[1];t=e.length;var c=1;if(t!==4&&t!==6&&t!==8)throw new a.exception.invalid("invalid aes key size");for(this.b=[n=e.slice(0),o=[]],e=t;e<4*t+28;e++)r=n[e-1],(e%t===0||t===8&&e%t===4)&&(r=i[r>>>24]<<24^i[r>>16&255]<<16^i[r>>8&255]<<8^i[r&255],e%t===0&&(r=r<<8^r>>>24^c<<24,c=c<<1^283*(c>>7))),n[e]=n[e-t]^r;for(t=0;e;t++,e--)r=n[t&3?e:e-4],o[t]=4>=e||4>t?r:s[0][i[r>>>24]]^s[1][i[r>>16&255]]^s[2][i[r>>8&255]]^s[3][i[r&255]]};a.cipher.aes.prototype={encrypt:function(e){return er(this,e,0)},decrypt:function(e){return er(this,e,1)},w:[[[],[],[],[],[]],[[],[],[],[],[]]],C:function(){var e=this.w[0],t=this.w[1],r=e[4],n=t[4],o,i,s,c=[],u=[],f,l,h,m;for(o=0;256>o;o++)u[(c[o]=o<<1^283*(o>>7))^o]=o;for(i=s=0;!r[i];i^=f||1,s=u[s]||1)for(h=s^s<<1^s<<2^s<<3^s<<4,h=h>>8^h&255^99,r[i]=h,n[h]=i,l=c[o=c[f=c[i]]],m=16843009*l^65537*o^257*f^16843008*i,l=257*c[h]^16843008*h,o=0;4>o;o++)e[o][i]=l=l<<24^l>>>8,t[o][h]=m=m<<24^m>>>8;for(o=0;5>o;o++)e[o]=e[o].slice(0),t[o]=t[o].slice(0)}};function er(e,t,r){if(t.length!==4)throw new a.exception.invalid("invalid aes block size");var n=e.b[r],o=t[0]^n[0],i=t[r?3:1]^n[1],s=t[2]^n[2];t=t[r?1:3]^n[3];var c,u,f,l=n.length/4-2,h,m=4,d=[0,0,0,0];c=e.w[r],e=c[0];var b=c[1],F=c[2],J=c[3],Y=c[4];for(h=0;h>>24]^b[i>>16&255]^F[s>>8&255]^J[t&255]^n[m],u=e[i>>>24]^b[s>>16&255]^F[t>>8&255]^J[o&255]^n[m+1],f=e[s>>>24]^b[t>>16&255]^F[o>>8&255]^J[i&255]^n[m+2],t=e[t>>>24]^b[o>>16&255]^F[i>>8&255]^J[s&255]^n[m+3],m+=4,o=c,i=u,s=f;for(h=0;4>h;h++)d[r?3&-h:h]=Y[o>>>24]<<24^Y[i>>16&255]<<16^Y[s>>8&255]<<8^Y[t&255]^n[m++],c=o,o=i,i=s,s=t,t=c;return d}a.bitArray={bitSlice:function(e,t,r){return e=a.bitArray.Y(e.slice(t/32),32-(t&31)).slice(1),r===void 0?e:a.bitArray.clamp(e,r-t)},extract:function(e,t,r){var n=Math.floor(-t-r&31);return((t+r-1^t)&-32?e[t/32|0]<<32-n^e[t/32+1|0]>>>n:e[t/32|0]>>>n)&(1<>t-1,1)),e},partial:function(e,t,r){return e===32?t:(r?t|0:t<<32-e)+1099511627776*e},getPartial:function(e){return Math.round(e/1099511627776)||32},equal:function(e,t){if(a.bitArray.bitLength(e)!==a.bitArray.bitLength(t))return!1;var r=0,n;for(n=0;n>>t),r=e[o]<<32-t;return o=e.length?e[e.length-1]:0,e=a.bitArray.getPartial(o),n.push(a.bitArray.partial(t+e&31,32>>24|r>>>8&65280|(r&65280)<<8|r<<24;return e}};a.codec.utf8String={fromBits:function(e){var t="",r=a.bitArray.bitLength(e),n,o;for(n=0;n>>8>>>8>>>8),o<<=8;return decodeURIComponent(escape(t))},toBits:function(e){e=unescape(encodeURIComponent(e));var t=[],r,n=0;for(r=0;r>>o)>>>26),6>o?(s=e[r]<<6-o,o+=26,r++):(s<<=6,o-=6);for(;n.length&3&&!t;)n+="=";return n},toBits:function(e,t){e=e.replace(/\s|=/g,"");var r=[],n,o=0,i=a.codec.base64.S,s=0,c;for(t&&(i=i.substr(0,62)+"-_"),n=0;nc)throw new a.exception.invalid("this isn't base64!");26>>o),s=c<<32-o):(o+=6,s^=c<<32-o)}return o&56&&r.push(a.bitArray.partial(o&56,s,1)),r}};a.codec.base64url={fromBits:function(e){return a.codec.base64.fromBits(e,1,1)},toBits:function(e){return a.codec.base64.toBits(e,1)}};a.hash.sha256=function(e){this.b[0]||this.C(),e?(this.g=e.g.slice(0),this.f=e.f.slice(0),this.c=e.c):this.reset()};a.hash.sha256.hash=function(e){return new a.hash.sha256().update(e).finalize()};a.hash.sha256.prototype={blockSize:512,reset:function(){return this.g=this.o.slice(0),this.f=[],this.c=0,this},update:function(e){typeof e=="string"&&(e=a.codec.utf8String.toBits(e));var t,r=this.f=a.bitArray.concat(this.f,e);if(t=this.c,e=this.c=t+a.bitArray.bitLength(e),9007199254740991t;r++){for(o=!0,n=2;n*n<=r;n++)if(r%n===0){o=!1;break}o&&(8>t&&(this.o[t]=e(Math.pow(r,.5))),this.b[t]=e(Math.pow(r,1/3)),t++)}},l:function(e){var t,r,n,o=this.g,i=this.b,s=o[0],c=o[1],u=o[2],f=o[3],l=o[4],h=o[5],m=o[6],d=o[7];for(t=0;64>t;t++)16>t?r=e[t]:(r=e[t+1&15],n=e[t+14&15],r=e[t&15]=(r>>>7^r>>>18^r>>>3^r<<25^r<<14)+(n>>>17^n>>>19^n>>>10^n<<15^n<<13)+e[t&15]+e[t+9&15]|0),r=r+d+(l>>>6^l>>>11^l>>>25^l<<26^l<<21^l<<7)+(m^l&(h^m))+i[t],d=m,m=h,h=l,l=f+r|0,f=u,u=c,c=s,s=r+(c&u^f&(c^u))+(c>>>2^c>>>13^c>>>22^c<<30^c<<19^c<<10)|0;o[0]=o[0]+s|0,o[1]=o[1]+c|0,o[2]=o[2]+u|0,o[3]=o[3]+f|0,o[4]=o[4]+l|0,o[5]=o[5]+h|0,o[6]=o[6]+m|0,o[7]=o[7]+d|0}};a.hash.sha512=function(e){this.b[0]||this.C(),e?(this.g=e.g.slice(0),this.f=e.f.slice(0),this.c=e.c):this.reset()};a.hash.sha512.hash=function(e){return new a.hash.sha512().update(e).finalize()};a.hash.sha512.prototype={blockSize:1024,reset:function(){return this.g=this.o.slice(0),this.f=[],this.c=0,this},update:function(e){typeof e=="string"&&(e=a.codec.utf8String.toBits(e));var t,r=this.f=a.bitArray.concat(this.f,e);if(t=this.c,e=this.c=t+a.bitArray.bitLength(e),9007199254740991r;n++){for(i=!0,o=2;o*o<=n;o++)if(n%o===0){i=!1;break}i&&(8>r&&(this.o[2*r]=e(Math.pow(n,.5)),this.o[2*r+1]=t(Math.pow(n,.5))<<24|this.ia[r]),this.b[2*r]=e(Math.pow(n,1/3)),this.b[2*r+1]=t(Math.pow(n,1/3))<<24|this.ka[r],r++)}},l:function(e){var t,r,n=this.g,o=this.b,i=n[0],s=n[1],c=n[2],u=n[3],f=n[4],l=n[5],h=n[6],m=n[7],d=n[8],b=n[9],F=n[10],J=n[11],Y=n[12],je=n[13],Pt=n[14],We=n[15],P;if(typeof Uint32Array<"u"){P=Array(160);for(var k=0;32>k;k++)P[k]=e[k]}else P=e;var k=i,I=s,ge=c,ie=u,Ee=f,se=l,at=h,we=m,H=d,M=b,ze=F,Ae=J,Je=Y,be=je,ct=Pt,Le=We;for(e=0;80>e;e++){if(16>e)t=P[2*e],r=P[2*e+1];else{r=P[2*(e-15)];var w=P[2*(e-15)+1];t=(w<<31|r>>>1)^(w<<24|r>>>8)^r>>>7;var $=(r<<31|w>>>1)^(r<<24|w>>>8)^(r<<25|w>>>7);r=P[2*(e-2)];var q=P[2*(e-2)+1],w=(q<<13|r>>>19)^(r<<3|q>>>29)^r>>>6,q=(r<<13|q>>>19)^(q<<3|r>>>29)^(r<<26|q>>>6),ut=P[2*(e-7)],ft=P[2*(e-16)],Oe=P[2*(e-16)+1];r=$+P[2*(e-7)+1],t=t+ut+(r>>>0<$>>>0?1:0),r+=q,t+=w+(r>>>0>>0?1:0),r+=Oe,t+=ft+(r>>>0>>0?1:0)}P[2*e]=t|=0,P[2*e+1]=r|=0;var ut=H&ze^~H&Je,St=M&Ae^~M&be,q=k&ge^k&Ee^ge&Ee,Dr=I&ie^I&se^ie&se,ft=(I<<4|k>>>28)^(k<<30|I>>>2)^(k<<25|I>>>7),Oe=(k<<4|I>>>28)^(I<<30|k>>>2)^(I<<25|k>>>7),_r=o[2*e],Tt=o[2*e+1],w=Le+((H<<18|M>>>14)^(H<<14|M>>>18)^(M<<23|H>>>9)),$=ct+((M<<18|H>>>14)^(M<<14|H>>>18)^(H<<23|M>>>9))+(w>>>0>>0?1:0),w=w+St,$=$+(ut+(w>>>0>>0?1:0)),w=w+Tt,$=$+(_r+(w>>>0>>0?1:0)),w=w+r|0,$=$+(t+(w>>>0>>0?1:0));r=Oe+Dr,t=ft+q+(r>>>0>>0?1:0),ct=Je,Le=be,Je=ze,be=Ae,ze=H,Ae=M,M=we+w|0,H=at+$+(M>>>0>>0?1:0)|0,at=Ee,we=se,Ee=ge,se=ie,ge=k,ie=I,I=w+r|0,k=$+t+(I>>>0>>0?1:0)|0}s=n[1]=s+I|0,n[0]=i+k+(s>>>0>>0?1:0)|0,u=n[3]=u+ie|0,n[2]=c+ge+(u>>>0>>0?1:0)|0,l=n[5]=l+se|0,n[4]=f+Ee+(l>>>0>>0?1:0)|0,m=n[7]=m+we|0,n[6]=h+at+(m>>>0>>0?1:0)|0,b=n[9]=b+M|0,n[8]=d+H+(b>>>0>>0?1:0)|0,J=n[11]=J+Ae|0,n[10]=F+ze+(J>>>0>>0?1:0)|0,je=n[13]=je+be|0,n[12]=Y+Je+(je>>>0>>0?1:0)|0,We=n[15]=We+Le|0,n[14]=Pt+ct+(We>>>0>>0?1:0)|0}};a.mode.ccm={name:"ccm",F:[],listenProgress:function(e){a.mode.ccm.F.push(e)},unListenProgress:function(e){e=a.mode.ccm.F.indexOf(e),-1u)throw new a.exception.invalid("ccm: iv must be at least 7 bytes");for(i=2;4>i&&f>>>8*i;i++);return i<15-u&&(i=15-u),r=c.clamp(r,8*(15-i)),t=a.mode.ccm.U(e,t,r,n,o,i),s=a.mode.ccm.V(e,s,r,t,o,i),c.concat(s.data,s.tag)},decrypt:function(e,t,r,n,o){o=o||64,n=n||[];var i=a.bitArray,s=i.bitLength(r)/8,f=i.bitLength(t),c=i.clamp(t,f-o),u=i.bitSlice(t,f-o),f=(f-o)/8;if(7>s)throw new a.exception.invalid("ccm: iv must be at least 7 bytes");for(t=2;4>t&&f>>>8*t;t++);if(t<15-s&&(t=15-s),r=i.clamp(r,8*(15-t)),c=a.mode.ccm.V(e,c,r,u,o,t),e=a.mode.ccm.U(e,c.data,r,n,o,t),!i.equal(c.tag,e))throw new a.exception.corrupt("ccm: tag doesn't match");return c.data},ma:function(e,t,r,n,o,i){var s=[],c=a.bitArray,u=c.P;if(n=[c.partial(8,(t.length?64:0)|n-2<<2|i-1)],n=c.concat(n,r),n[3]|=o,n=e.encrypt(n),t.length)for(r=c.bitLength(t)/8,65279>=r?s=[c.partial(16,r)]:4294967295>=r&&(s=c.concat([c.partial(16,65534)],[r])),s=c.concat(s,t),t=0;to||16l&&(a.mode.ccm.da(s/u),l+=h),r[3]++,o=e.encrypt(r),t[s]^=o[0],t[s+1]^=o[1],t[s+2]^=o[2],t[s+3]^=o[3];return{tag:n,data:c.clamp(t,f)}}};a.misc.hmac=function(e,t){this.W=t=t||a.hash.sha256;var r=[[],[]],n,o=t.prototype.blockSize/32;for(this.B=[new t,new t],e.length>o&&(e=t.hash(e)),n=0;nn||0>r)throw new a.exception.invalid("invalid params to pbkdf2");typeof e=="string"&&(e=a.codec.utf8String.toBits(e)),typeof t=="string"&&(t=a.codec.utf8String.toBits(t)),o=o||a.misc.hmac,e=new o(e);var i,s,c,u,f=[],l=a.bitArray;for(u=1;32*f.length<(n||1);u++){for(o=i=e.encrypt(l.concat(t,[u])),s=1;ss;s++)o.push(4294967296*Math.random()|0);for(s=0;s=1<this.u&&(this.u=i),this.N++,this.b=a.hash.sha256.hash(this.b.concat(o)),this.K=new a.cipher.aes(this.b),n=0;4>n&&(this.m[n]=this.m[n]+1|0,!this.m[n]);n++);}for(n=0;n>>1;this.h[s].update([n,this.M++,2,t,i,e.length].concat(e))}break;case"string":t===void 0&&(t=e.length),this.h[s].update([n,this.M++,3,t,i,e.length]),this.h[s].update(e);break;default:u=1}if(u)throw new a.exception.bug("random: addEntropy only supports number, array of numbers or string");this.s[s]+=t,this.i+=t,c===this.A&&(this.isReady()!==this.A&&tr("seeded",Math.max(this.u,this.i)),tr("progress",this.getProgress()))},isReady:function(e){return e=this.R[e!==void 0?e:this.L],this.u&&this.u>=e?this.s[0]>this.$&&new Date().valueOf()>this.X?this.I|this.H:this.H:this.i>=e?this.I|this.A:this.A},getProgress:function(e){return e=this.R[e||this.L],this.u>=e||this.i>e?1:this.i/e},startCollectors:function(){if(!this.D){if(this.a={loadTimeCollector:Ce(this,this.la),mouseCollector:Ce(this,this.na),keyboardCollector:Ce(this,this.ja),accelerometerCollector:Ce(this,this.ca),touchCollector:Ce(this,this.pa)},window.addEventListener)window.addEventListener("load",this.a.loadTimeCollector,!1),window.addEventListener("mousemove",this.a.mouseCollector,!1),window.addEventListener("keypress",this.a.keyboardCollector,!1),window.addEventListener("devicemotion",this.a.accelerometerCollector,!1),window.addEventListener("touchmove",this.a.touchCollector,!1);else if(document.attachEvent)document.attachEvent("onload",this.a.loadTimeCollector),document.attachEvent("onmousemove",this.a.mouseCollector),document.attachEvent("keypress",this.a.keyboardCollector);else throw new a.exception.bug("can't attach event");this.D=!0}},stopCollectors:function(){this.D&&(window.removeEventListener?(window.removeEventListener("load",this.a.loadTimeCollector,!1),window.removeEventListener("mousemove",this.a.mouseCollector,!1),window.removeEventListener("keypress",this.a.keyboardCollector,!1),window.removeEventListener("devicemotion",this.a.accelerometerCollector,!1),window.removeEventListener("touchmove",this.a.touchCollector,!1)):document.detachEvent&&(document.detachEvent("onload",this.a.loadTimeCollector),document.detachEvent("onmousemove",this.a.mouseCollector),document.detachEvent("keypress",this.a.keyboardCollector)),this.D=!1)},addEventListener:function(e,t){this.J[e][this.ea++]=t},removeEventListener:function(e,t){var r,n,o=this.J[e],i=[];for(n in o)o.hasOwnProperty(n)&&o[n]===t&&i.push(n);for(r=0;rt&&(e.m[t]=e.m[t]+1|0,!e.m[t]);t++);return e.K.encrypt(e.m)}function Ce(e,t){return function(){t.apply(e,arguments)}}a.random=new a.prng(6);e:try{if(Qe=typeof fe<"u"&&fe.exports){try{Ze=Ir("crypto")}catch{Ze=null}Qe=Ke=Ze}if(Qe&&Ke.randomBytes)Pe=Ke.randomBytes(128),Pe=new Uint32Array(new Uint8Array(Pe).buffer),a.random.addEntropy(Pe,1024,"crypto['randomBytes']");else if(typeof window<"u"&&typeof Uint32Array<"u"){if(Se=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(Se);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(Se);else break e;a.random.addEntropy(Se,1024,"crypto['getRandomValues']")}}catch(e){typeof window<"u"&&window.console&&(console.log("There was an error collecting entropy from the browser:"),console.log(e))}var Pe,Ke,Se,Qe,Ze;a.json={defaults:{v:1,iter:1e4,ks:128,ts:64,mode:"ccm",adata:"",cipher:"aes"},ha:function(e,t,r,n){r=r||{},n=n||{};var o=a.json,i=o.j({iv:a.random.randomWords(4,0)},o.defaults),s;if(o.j(i,r),r=i.adata,typeof i.salt=="string"&&(i.salt=a.codec.base64.toBits(i.salt)),typeof i.iv=="string"&&(i.iv=a.codec.base64.toBits(i.iv)),!a.mode[i.mode]||!a.cipher[i.cipher]||typeof e=="string"&&100>=i.iter||i.ts!==64&&i.ts!==96&&i.ts!==128||i.ks!==128&&i.ks!==192&&i.ks!==256||2>i.iv.length||4=t.iter||t.ts!==64&&t.ts!==96&&t.ts!==128||t.ks!==128&&t.ks!==192&&t.ks!==256||!t.iv||2>t.iv.length||4{"use strict";var An=Object.prototype.hasOwnProperty,S="~";function Te(){}Object.create&&(Te.prototype=Object.create(null),new Te().__proto__||(S=!1));function bn(e,t,r){this.fn=e,this.context=t,this.once=r||!1}function mr(e,t,r,n,o){if(typeof r!="function")throw new TypeError("The listener must be a function");var i=new bn(r,n||e,o),s=S?S+t:t;return e._events[s]?e._events[s].fn?e._events[s]=[e._events[s],i]:e._events[s].push(i):(e._events[s]=i,e._eventsCount++),e}function et(e,t){--e._eventsCount===0?e._events=new Te:delete e._events[t]}function C(){this._events=new Te,this._eventsCount=0}C.prototype.eventNames=function(){var t=[],r,n;if(this._eventsCount===0)return t;for(n in r=this._events)An.call(r,n)&&t.push(S?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(r)):t};C.prototype.listeners=function(t){var r=S?S+t:t,n=this._events[r];if(!n)return[];if(n.fn)return[n.fn];for(var o=0,i=n.length,s=new Array(i);o{let n=t.isOk()?{type:"Ok",value:t.value}:{type:"Err",value:t.error},o=r.withStackTrace?new Error().stack:void 0;return{data:n,message:e,stack:o}};function ae(e,t,r,n){function o(i){return i instanceof r?i:new r(function(s){s(i)})}return new(r||(r=Promise))(function(i,s){function c(l){try{f(n.next(l))}catch(h){s(h)}}function u(l){try{f(n.throw(l))}catch(h){s(h)}}function f(l){l.done?i(l.value):o(l.value).then(c,u)}f((n=n.apply(e,t||[])).next())})}function It(e){var t=typeof Symbol=="function"&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&typeof e.length=="number")return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function G(e){return this instanceof G?(this.v=e,this):new G(e)}function Mt(e,t,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=r.apply(e,t||[]),o,i=[];return o=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),c("next"),c("throw"),c("return",s),o[Symbol.asyncIterator]=function(){return this},o;function s(d){return function(b){return Promise.resolve(b).then(d,h)}}function c(d,b){n[d]&&(o[d]=function(F){return new Promise(function(J,Y){i.push([d,F,J,Y])>1||u(d,F)})},b&&(o[d]=b(o[d])))}function u(d,b){try{f(n[d](b))}catch(F){m(i[0][3],F)}}function f(d){d.value instanceof G?Promise.resolve(d.value.v).then(l,h):m(i[0][2],d)}function l(d){u("next",d)}function h(d){u("throw",d)}function m(d,b){d(b),i.shift(),i.length&&u(i[0][0],i[0][1])}}function Nr(e){var t,r;return t={},n("next"),n("throw",function(o){throw o}),n("return"),t[Symbol.iterator]=function(){return this},t;function n(o,i){t[o]=e[o]?function(s){return(r=!r)?{value:G(e[o](s)),done:!1}:i?i(s):s}:i}}function Fr(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=e[Symbol.asyncIterator],r;return t?t.call(e):(e=typeof It=="function"?It(e):e[Symbol.iterator](),r={},n("next"),n("throw"),n("return"),r[Symbol.asyncIterator]=function(){return this},r);function n(i){r[i]=e[i]&&function(s){return new Promise(function(c,u){s=e[i](s),o(c,u,s.done,s.value)})}}function o(i,s,c,u){Promise.resolve(u).then(function(f){i({value:f,done:c})},s)}}var O=class e{constructor(t){this._promise=t}static fromSafePromise(t){let r=t.then(n=>new B(n));return new e(r)}static fromPromise(t,r){let n=t.then(o=>new B(o)).catch(o=>new j(r(o)));return new e(n)}static fromThrowable(t,r){return(...n)=>new e(ae(this,void 0,void 0,function*(){try{return new B(yield t(...n))}catch(o){return new j(r?r(o):o)}}))}static combine(t){return Br(t)}static combineWithAllErrors(t){return jr(t)}map(t){return new e(this._promise.then(r=>ae(this,void 0,void 0,function*(){return r.isErr()?new j(r.error):new B(yield t(r.value))})))}andThrough(t){return new e(this._promise.then(r=>ae(this,void 0,void 0,function*(){if(r.isErr())return new j(r.error);let n=yield t(r.value);return n.isErr()?new j(n.error):new B(r.value)})))}andTee(t){return new e(this._promise.then(r=>ae(this,void 0,void 0,function*(){if(r.isErr())return new j(r.error);try{yield t(r.value)}catch{}return new B(r.value)})))}mapErr(t){return new e(this._promise.then(r=>ae(this,void 0,void 0,function*(){return r.isOk()?new B(r.value):new j(yield t(r.error))})))}andThen(t){return new e(this._promise.then(r=>{if(r.isErr())return new j(r.error);let n=t(r.value);return n instanceof e?n._promise:n}))}orElse(t){return new e(this._promise.then(r=>ae(this,void 0,void 0,function*(){return r.isErr()?t(r.error):new B(r.value)})))}match(t,r){return this._promise.then(n=>n.match(t,r))}unwrapOr(t){return this._promise.then(r=>r.unwrapOr(t))}safeUnwrap(){return Mt(this,arguments,function*(){return yield G(yield G(yield*Nr(Fr(yield G(this._promise.then(r=>r.safeUnwrap()))))))})}then(t,r){return this._promise.then(t,r)}[Symbol.asyncIterator](){return Mt(this,arguments,function*(){let r=yield G(this._promise);return r.isErr()&&(yield yield G(D(r.error))),yield G(r.value)})}},T=e=>new O(Promise.resolve(new B(e))),D=e=>new O(Promise.resolve(new j(e))),Dn=O.fromPromise,_n=O.fromSafePromise,kn=O.fromThrowable,Nt=e=>{let t=ne([]);for(let r of e)if(r.isErr()){t=K(r.error);break}else t.map(n=>n.push(r.value));return t},Br=e=>O.fromSafePromise(Promise.all(e)).andThen(Nt),Ft=e=>{let t=ne([]);for(let r of e)r.isErr()&&t.isErr()?t.error.push(r.error):r.isErr()&&t.isOk()?t=K([r.error]):r.isOk()&&t.isOk()&&t.value.push(r.value);return t},jr=e=>O.fromSafePromise(Promise.all(e)).andThen(Ft),dt;(function(e){function t(o,i){return(...s)=>{try{let c=o(...s);return ne(c)}catch(c){return K(i?i(c):c)}}}e.fromThrowable=t;function r(o){return Nt(o)}e.combine=r;function n(o){return Ft(o)}e.combineWithAllErrors=n})(dt||(dt={}));var ne=e=>new B(e);function K(e){return new j(e)}var B=class{constructor(t){this.value=t}isOk(){return!0}isErr(){return!this.isOk()}map(t){return ne(t(this.value))}mapErr(t){return ne(this.value)}andThen(t){return t(this.value)}andThrough(t){return t(this.value).map(r=>this.value)}andTee(t){try{t(this.value)}catch{}return ne(this.value)}orElse(t){return ne(this.value)}asyncAndThen(t){return t(this.value)}asyncAndThrough(t){return t(this.value).map(()=>this.value)}asyncMap(t){return O.fromSafePromise(t(this.value))}unwrapOr(t){return this.value}match(t,r){return t(this.value)}safeUnwrap(){let t=this.value;return function*(){return t}()}_unsafeUnwrap(t){return this.value}_unsafeUnwrapErr(t){throw Ut("Called `_unsafeUnwrapErr` on an Ok",this,t)}*[Symbol.iterator](){return this.value}},j=class{constructor(t){this.error=t}isOk(){return!1}isErr(){return!this.isOk()}map(t){return K(this.error)}mapErr(t){return K(t(this.error))}andThrough(t){return K(this.error)}andTee(t){return K(this.error)}andThen(t){return K(this.error)}orElse(t){return t(this.error)}asyncAndThen(t){return D(this.error)}asyncAndThrough(t){return D(this.error)}asyncMap(t){return D(this.error)}unwrapOr(t){return t}match(t,r){return r(this.error)}safeUnwrap(){let t=this.error;return function*(){throw yield K(t),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(t){throw Ut("Called `_unsafeUnwrap` on an Err",this,t)}_unsafeUnwrapErr(t){return this.error}*[Symbol.iterator](){let t=this;return yield t,t}},Cn=dt.fromThrowable;var U=class extends Error{constructor(r,n={}){let{cause:o,context:i}=n;super(r,{cause:o});A(this,"context");this.name=this.constructor.name,this.context=i}};var Q=e=>{if(e instanceof Error)return e;let t="[Unable to stringify the thrown value]";try{t=JSON.stringify(e)}catch{}return new Error(t)};var Wr=()=>typeof Deno<"u";var Z=e=>Wr()?new URL(`./worker/${e}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${e==="main"?`worker/${e}`:e}.js`));var V=class extends U{};var De=class extends V{constructor(){super(...arguments);A(this,"message","An error occured while trying to connect to WebSocket")}};var Kt=xe(Ge());var v=new Kt.default,_,Xt=!1;self.onmessage=e=>{Vr(e),Xt||(Xt=!0,v.once("OPERATION_FAILED",()=>{_&&_.terminate()}))};var ee=(e,t)=>(Object.assign(e,t),typeof WorkerGlobalScope<"u"&&self.postMessage({event:"FILE_UPDATED",lufiFile:e}),e),Ye=(e,t)=>{ee(e,{uploadStatus:2}),self.postMessage({event:"OPERATION_FAILED",error:t})},Vr=(e,t)=>{let{action:r}=e.data;if(r===5||r===8)_.postMessage(e.data);else{switch(r){case 2:_=new Worker(Z("cancel"),{type:"module"}),_.postMessage(e.data);break;case 3:_=new Worker(Z("download"),{type:"module"}),_.postMessage(e.data);break;case 4:_=new Worker(Z("infos"),{type:"module"}),_.postMessage(e.data);break;case 7:_=_||new Worker(Z("remove"),{type:"module"}),_.postMessage(e.data);break;case 9:_=_||new Worker(Z("upload"),{type:"module"}),_.postMessage(e.data);break;default:console.error("Action not found")}_.onmessage=n=>{t&&t(n),self.postMessage(n.data)},_.onerror=n=>{console.error(`Error: ${n.message}`)}}},Qt=()=>{v.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),v.once("OPERATION_FAILED",e=>{self.postMessage({event:"OPERATION_FAILED",error:e})})};var ue=class{constructor(t,r){if(!t||t.length!=64)throw Error("Charset must contain 64 characters");this._charset=t,this._noPadding=!!r,this._valid=new RegExp("^["+this._charset.replace("-","\\-")+"]+={0,2}$")}Encode(t){let r=t.byteLength;if(!r)return"";let n=new Uint8Array(t),o="";for(let i=0;i>2]+this._charset[(n[i]&3)<<4|n[i+1]>>4]+this._charset[(n[i+1]&15)<<2|n[i+2]>>6]+this._charset[n[i+2]&63];return r%3==2?(o=o.substring(0,o.length-1),this._noPadding||(o+="=")):r%3==1&&(o=o.substring(0,o.length-2),this._noPadding||(o+="==")),o}Decode(t){if(t=(t||"").replace(/[\s]/g,""),!t)return new ArrayBuffer(0);if(!this._valid.test(t))throw Error("Invalid base64 input sequence");let r=Math.floor(t.length*.75);t[t.length-2]=="="?r-=2:t[t.length-1]=="="&&r--;let n=new Uint8Array(r),o,i,s,c,u=0,f=0;for(;u>4,n[u++]=(i&15)<<4|s>>2,n[u++]=(s&3)<<6|c;return n.buffer}};var Xr=new ue("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");function _e(e){return Xr.Decode(e)}var Yr=new ue("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",!0);function yt(e){return Yr.Decode(e)}var or=xe(nr());var te=class extends U{};var le=class extends te{constructor(){super(...arguments);A(this,"message","Unable to decrypt the provided data")}};var ir=(e,t)=>{try{let r=typeof t=="string"?t:t.data;return T(_e(or.default.decrypt(e,r)))}catch(r){return D(new le(void 0,{cause:Q(r)}))}};var sr=(e,t)=>tn(e).andThen(r=>O.fromPromise(crypto.subtle.decrypt({name:"AES-GCM",iv:t.iv},r,_e(t.data)),n=>new le(void 0,{cause:Q(n)})));var tn=e=>O.fromPromise(crypto.subtle.importKey("raw",yt(e),{name:"AES-GCM"},!1,["encrypt","decrypt"]),t=>new te("Unable to import cryptography key",{cause:Q(t)}));var ar=(e,t)=>t.algo===void 0||t.algo===0?ir(e,t):sr(e,t);var N={},ur=5,nn=e=>(v.emit("UPLOAD_CANCELLED",e.success),T(void 0)),on=(e,t)=>{let r=e.split("XXMOJOXX"),n=r.shift();if(n!==void 0){let o=JSON.parse(n);if(dn(o)){let i=r.shift();if(i){let s=JSON.parse(i);return s.iv&&(s.iv=new Uint8Array(Object.values(s.iv))),ar(t.keys.client,s).andThen(c=>{let u=typeof c=="string"?new TextEncoder().encode(c).buffer:c;return o.part===0?(ee(t,{chunksReady:t.chunksReady+1,delAtFirstView:o.del_at_first_view,delay:o.delay,name:o.name,size:o.size,totalChunks:o.total,type:o.type,zipped:o.zipped}),v.emit("DOWNLOAD_STARTED")):ee(t,{chunksReady:t.chunksReady+1}),v.emit("CHUNK_DOWNLOADED",u,o.part),++o.part===o.total?un(t).andThen(()=>(v.emit("DOWNLOAD_COMPLETE"),v.emit("SOCKET_OPERATION_TERMINATED"),T(void 0))):T(void 0)})}else{let s=new V("Cannot retrieve metadata from data received by the server");return v.emit("OPERATION_FAILED",s),D(s)}}else{let i=new V(o.msg);return v.emit("OPERATION_FAILED",i),D(i)}}else{let o=new V("Cannot retrieve metadata from data received by the server");return v.emit("OPERATION_FAILED",o),D(o)}},sn=(e,t)=>{if(e.success)return e.j===0&&(ee(t,{keys:{client:t.keys.client,server:e.short},actionToken:e.token,queueIndex:e.i}),v.emit("UPLOAD_STARTED")),ee(t,{chunksReady:t.chunksReady+1,createdAt:e.created_at}),v.emit("CHUNK_UPLOADED"),t.chunksReady===t.totalChunks&&(ee(t,{uploadStatus:1}),v.emit("UPLOAD_COMPLETE"),v.emit("SOCKET_OPERATION_TERMINATED")),T(void 0);{let r=new V(e.msg);return v.emit("OPERATION_FAILED",r),D(r)}},an=(e,t)=>{let r=pn(e.data),n;if(r)if(!r.action&&r.msg){let o=new V(r.msg);return v.emit("OPERATION_FAILED",o),D(o)}else"delay"in r?n=sn(r,t):n=nn(r);else n=on(e.data,t);return n},cn=e=>N!==void 0&&N[e]!==void 0&&N[e].readyState===WebSocket.CONNECTING,Et=e=>N!==void 0&&N[e]!==void 0&&N[e].readyState===WebSocket.OPEN;var un=e=>{let t;return e.password?t={ended:!0,file_pwd:e.password}:t={ended:!0},At(ln(e),e,JSON.stringify(t))},wt=(e,t,r)=>At(hn(e),e,`${JSON.stringify(t)}XXMOJOXX${JSON.stringify(r)}`),At=(e,t,r)=>Et(e)?(N[e].onmessage=n=>an(n,t),N[e].send(r),T(void 0)):fr(e).andThen(()=>At(e,t,r)),fr=(e,t=0)=>(!Et(e)&&!cn(e)&&(N[e]=new WebSocket(e),v.once("SOCKET_OPERATION_TERMINATED",()=>{N[e].close()}),v.once("OPERATION_FAILED",()=>{v.emit("SOCKET_OPERATION_TERMINATED")}),N[e].onopen=()=>{v.emit("SOCKET_OPENED")},N[e].onclose=()=>{},N[e].onerror=()=>++t<=ur?(console.error(`An error happened while trying to connect to WebSocket ${e}. Trying again. ${t} / ${ur}`),fr(e,t)):(v.emit("SOCKET_ONERROR"),D(new De(`Unable to connect to WebSocket ${e}.`)))),fn(e).andThen(()=>T(e)).orElse(r=>D(r))),fn=e=>O.fromPromise(new Promise((t,r)=>{Et(e)?t(void 0):(v.once("SOCKET_OPENED",()=>{t(void 0)}),v.on("SOCKET_ONERROR",()=>{r(new De)}))}),t=>Q(t));var lr=(e,t)=>{let r=new URL(e);return r.protocol=r.protocol==="http:"?"ws:":"wss:",r.pathname+=t,new URL(r.origin+r.pathname)},ln=e=>lr(new URL(e.serverUrl),"download"+`/${e.keys.server}`).toString(),hn=e=>lr(new URL(e.serverUrl),"upload").toString(),pn=e=>{try{let t=JSON.parse(e);if(t&&typeof t=="object")return t}catch{}return!1},dn=e=>typeof e=="object"&&e!==null&&!("msg"in e);var pr=xe(Ge());var vn=xe(Ge());var En={},bs=new pr.default;var wn=()=>Object.values(En).filter(e=>e.uploadStatus===4),dr=e=>Object.keys(wn()).indexOf(e);var Lt=xe(yr(),1);var Re=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},Ot=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},vr=e=>globalThis.DOMException===void 0?new Ot(e):new DOMException(e),gr=e=>{let t=e.reason===void 0?vr("This operation was aborted."):e.reason;return t instanceof Error?t:vr(t)};function xt(e,t){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout}}=t,s,u=new Promise((f,l)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(t.signal){let{signal:m}=t;m.aborted&&l(gr(m));let d=()=>{l(gr(m))};m.addEventListener("abort",d,{once:!0}),e.finally(()=>{m.removeEventListener("abort",d)})}if(r===Number.POSITIVE_INFINITY){e.then(f,l);return}let h=new Re;s=i.setTimeout.call(void 0,()=>{if(n){try{f(n())}catch(m){l(m)}return}typeof e.cancel=="function"&&e.cancel(),o===!1?f():o instanceof Error?l(o):(h.message=o!=null?o:`Promise timed out after ${r} milliseconds`,l(h))},r),(async()=>{try{f(await e)}catch(m){l(m)}})()}).finally(()=>{u.clear()});return u.clear=()=>{i.clearTimeout.call(void 0,s),s=void 0},u}function Dt(e,t,r){let n=0,o=e.length;for(;o>0;){let i=Math.trunc(o/2),s=n+i;r(e[s],t)<=0?(n=++s,o-=i+1):o=i}return n}var X,Ie=class{constructor(){L(this,X,[])}enqueue(t,r){r={priority:0,...r};let n={priority:r.priority,run:t};if(this.size&&p(this,X)[this.size-1].priority>=r.priority){p(this,X).push(n);return}let o=Dt(p(this,X),n,(i,s)=>s.priority-i.priority);p(this,X).splice(o,0,n)}dequeue(){let t=p(this,X).shift();return t==null?void 0:t.run}filter(t){return p(this,X).filter(r=>r.priority===t.priority).map(r=>r.run)}get size(){return p(this,X).length}};X=new WeakMap;var he,pe,oe,Ue,de,Ne,W,me,R,Fe,z,ye,re,Be,y,Er,wr,Ar,br,Lr,tt,_t,kt,rt,Or,nt,Me=class extends Lt.default{constructor(r){var n,o,i,s;super();L(this,y);L(this,he);L(this,pe);L(this,oe,0);L(this,Ue);L(this,de);L(this,Ne,0);L(this,W);L(this,me);L(this,R);L(this,Fe);L(this,z,0);L(this,ye);L(this,re);L(this,Be);A(this,"timeout");if(r={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:Ie,...r},!(typeof r.intervalCap=="number"&&r.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${(o=(n=r.intervalCap)==null?void 0:n.toString())!=null?o:""}\` (${typeof r.intervalCap})`);if(r.interval===void 0||!(Number.isFinite(r.interval)&&r.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${(s=(i=r.interval)==null?void 0:i.toString())!=null?s:""}\` (${typeof r.interval})`);E(this,he,r.carryoverConcurrencyCount),E(this,pe,r.intervalCap===Number.POSITIVE_INFINITY||r.interval===0),E(this,Ue,r.intervalCap),E(this,de,r.interval),E(this,R,new r.queueClass),E(this,Fe,r.queueClass),this.concurrency=r.concurrency,this.timeout=r.timeout,E(this,Be,r.throwOnTimeout===!0),E(this,re,r.autoStart===!1)}get concurrency(){return p(this,ye)}set concurrency(r){if(!(typeof r=="number"&&r>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${r}\` (${typeof r})`);E(this,ye,r),x(this,y,rt).call(this)}async add(r,n={}){return n={timeout:this.timeout,throwOnTimeout:p(this,Be),...n},new Promise((o,i)=>{p(this,R).enqueue(async()=>{var s;He(this,z)._++,He(this,oe)._++;try{(s=n.signal)==null||s.throwIfAborted();let c=r({signal:n.signal});n.timeout&&(c=xt(Promise.resolve(c),{milliseconds:n.timeout})),n.signal&&(c=Promise.race([c,x(this,y,Or).call(this,n.signal)]));let u=await c;o(u),this.emit("completed",u)}catch(c){if(c instanceof Re&&!n.throwOnTimeout){o();return}i(c),this.emit("error",c)}finally{x(this,y,Ar).call(this)}},n),this.emit("add"),x(this,y,tt).call(this)})}async addAll(r,n){return Promise.all(r.map(async o=>this.add(o,n)))}start(){return p(this,re)?(E(this,re,!1),x(this,y,rt).call(this),this):this}pause(){E(this,re,!0)}clear(){E(this,R,new(p(this,Fe)))}async onEmpty(){p(this,R).size!==0&&await x(this,y,nt).call(this,"empty")}async onSizeLessThan(r){p(this,R).sizep(this,R).size{x(this,y,br).call(this)},n)),!0}return!1},tt=function(){if(p(this,R).size===0)return p(this,W)&&clearInterval(p(this,W)),E(this,W,void 0),this.emit("empty"),p(this,z)===0&&this.emit("idle"),!1;if(!p(this,re)){let r=!p(this,y,Lr);if(p(this,y,Er)&&p(this,y,wr)){let n=p(this,R).dequeue();return n?(this.emit("active"),n(),r&&x(this,y,_t).call(this),!0):!1}}return!1},_t=function(){p(this,pe)||p(this,W)!==void 0||(E(this,W,setInterval(()=>{x(this,y,kt).call(this)},p(this,de))),E(this,Ne,Date.now()+p(this,de)))},kt=function(){p(this,oe)===0&&p(this,z)===0&&p(this,W)&&(clearInterval(p(this,W)),E(this,W,void 0)),E(this,oe,p(this,he)?p(this,z):0),x(this,y,rt).call(this)},rt=function(){for(;x(this,y,tt).call(this););},Or=async function(r){return new Promise((n,o)=>{r.addEventListener("abort",()=>{o(r.reason)},{once:!0})})},nt=async function(r,n){return new Promise(o=>{let i=()=>{n&&!n()||(this.off(r,i),o())};this.on(r,i)})};var xr=!1,Ct=navigator.hardwareConcurrency||4,ve=new Me({concurrency:Ct,autoStart:!1}),it=0,st=[],ot=!1;self.onmessage=e=>{let t=e.data,{chunk:r,lufiFile:n}=t.args;if(xr||(Qt(),xr=!0),r){if(st[r.index]=r,st.length===n.totalChunks)return v.once("UPLOAD_COMPLETE",()=>{self.postMessage({event:"UPLOAD_COMPLETE"})}),v.on("FILE_UPDATED",ee),v.on("CHUNK_UPLOADED",()=>{self.postMessage({event:"CHUNK_UPLOADED"}),it--,!ot&&itOn(e,dr(e.args.lufiFile.keys.client)),On=(e,t)=>{let{lufiFile:r}=e.args,n=new Worker(Z("encrypt"),{type:"module"});return v.on("UPLOAD_STARTED",()=>{n.onmessage=async o=>{if(o.data.encryptedData){let{encryptedData:i}=o.data;await ve.add(async()=>{await wt(r,{total:r.totalChunks,part:o.data.chunkIndex,size:r.size,name:r.name.split("/").pop(),type:r.type,delay:r.delay,del_at_first_view:r.delAtFirstView,zipped:r.zipped,id:r.keys.server,i:t,file_pwd:r.password},i),it++,(ot||it===Ct)&&ve.pause()})}ve.start(),o.data.error&&(Ye(r,o.data.error),n.terminate())};for(let o=1;o{if(o.data.encryptedData){let{encryptedData:i}=o.data;wt(r,{total:r.totalChunks,part:o.data.chunkIndex,size:r.size,name:r.name.split("/").pop(),type:r.type,delay:r.delay,del_at_first_view:r.delAtFirstView,zipped:r.zipped,id:null,i:t,file_pwd:r.password},i).mapErr(s=>{Ye(r,s)})}o.data.error&&Ye(r,o.data.error)},e.args.chunk=st[0],n.postMessage(e),T(void 0)}; +var Cr=Object.create;var lt=Object.defineProperty;var kr=Object.getOwnPropertyDescriptor;var Pr=Object.getOwnPropertyNames;var Sr=Object.getPrototypeOf,Tr=Object.prototype.hasOwnProperty;var Rt=e=>{throw TypeError(e)};var Rr=(e,t,r)=>t in e?lt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var Ir=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,r)=>(typeof require<"u"?require:t)[r]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var ht=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Mr=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Pr(t))!Tr.call(e,o)&&o!==r&<(e,o,{get:()=>t[o],enumerable:!(n=kr(t,o))||n.enumerable});return e};var xe=(e,t,r)=>(r=e!=null?Cr(Sr(e)):{},Mr(t||!e||!e.__esModule?lt(r,"default",{value:e,enumerable:!0}):r,e));var A=(e,t,r)=>Rr(e,typeof t!="symbol"?t+"":t,r),pt=(e,t,r)=>t.has(e)||Rt("Cannot "+r);var p=(e,t,r)=>(pt(e,t,"read from private field"),r?r.call(e):t.get(e)),L=(e,t,r)=>t.has(e)?Rt("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,r),E=(e,t,r,n)=>(pt(e,t,"write to private field"),n?n.call(e,r):t.set(e,r),r),x=(e,t,r)=>(pt(e,t,"access private method"),r);var He=(e,t,r,n)=>({set _(o){E(e,t,o,r)},get _(){return p(e,t,n)}});var Ge=ht((Zn,mt)=>{"use strict";var ce=typeof Reflect=="object"?Reflect:null,Bt=ce&&typeof ce.apply=="function"?ce.apply:function(t,r,n){return Function.prototype.apply.call(t,r,n)},$e;ce&&typeof ce.ownKeys=="function"?$e=ce.ownKeys:Object.getOwnPropertySymbols?$e=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:$e=function(t){return Object.getOwnPropertyNames(t)};function zr(e){console&&console.warn&&console.warn(e)}var Wt=Number.isNaN||function(t){return t!==t};function v(){v.init.call(this)}mt.exports=v;mt.exports.once=qr;v.EventEmitter=v;v.prototype._events=void 0;v.prototype._eventsCount=0;v.prototype._maxListeners=void 0;var jt=10;function qe(e){if(typeof e!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}Object.defineProperty(v,"defaultMaxListeners",{enumerable:!0,get:function(){return jt},set:function(e){if(typeof e!="number"||e<0||Wt(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");jt=e}});v.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0};v.prototype.setMaxListeners=function(t){if(typeof t!="number"||t<0||Wt(t))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+t+".");return this._maxListeners=t,this};function zt(e){return e._maxListeners===void 0?v.defaultMaxListeners:e._maxListeners}v.prototype.getMaxListeners=function(){return zt(this)};v.prototype.emit=function(t){for(var r=[],n=1;n0&&(s=r[0]),s instanceof Error)throw s;var c=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw c.context=s,c}var u=i[t];if(u===void 0)return!1;if(typeof u=="function")Bt(u,this,r);else for(var f=u.length,l=Gt(u,f),n=0;n0&&s.length>o&&!s.warned){s.warned=!0;var c=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");c.name="MaxListenersExceededWarning",c.emitter=e,c.type=t,c.count=s.length,zr(c)}return e}v.prototype.addListener=function(t,r){return Jt(this,t,r,!1)};v.prototype.on=v.prototype.addListener;v.prototype.prependListener=function(t,r){return Jt(this,t,r,!0)};function Jr(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function Ht(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},o=Jr.bind(n);return o.listener=r,n.wrapFn=o,o}v.prototype.once=function(t,r){return qe(r),this.on(t,Ht(this,t,r)),this};v.prototype.prependOnceListener=function(t,r){return qe(r),this.prependListener(t,Ht(this,t,r)),this};v.prototype.removeListener=function(t,r){var n,o,i,s,c;if(qe(r),o=this._events,o===void 0)return this;if(n=o[t],n===void 0)return this;if(n===r||n.listener===r)--this._eventsCount===0?this._events=Object.create(null):(delete o[t],o.removeListener&&this.emit("removeListener",t,n.listener||r));else if(typeof n!="function"){for(i=-1,s=n.length-1;s>=0;s--)if(n[s]===r||n[s].listener===r){c=n[s].listener,i=s;break}if(i<0)return this;i===0?n.shift():Hr(n,i),n.length===1&&(o[t]=n[0]),o.removeListener!==void 0&&this.emit("removeListener",t,c||r)}return this};v.prototype.off=v.prototype.removeListener;v.prototype.removeAllListeners=function(t){var r,n,o;if(n=this._events,n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[t]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[t]),this;if(arguments.length===0){var i=Object.keys(n),s;for(o=0;o=0;o--)this.removeListener(t,r[o]);return this};function $t(e,t,r){var n=e._events;if(n===void 0)return[];var o=n[t];return o===void 0?[]:typeof o=="function"?r?[o.listener||o]:[o]:r?$r(o):Gt(o,o.length)}v.prototype.listeners=function(t){return $t(this,t,!0)};v.prototype.rawListeners=function(t){return $t(this,t,!1)};v.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):qt.call(e,t)};v.prototype.listenerCount=qt;function qt(e){var t=this._events;if(t!==void 0){var r=t[e];if(typeof r=="function")return 1;if(r!==void 0)return r.length}return 0}v.prototype.eventNames=function(){return this._eventsCount>0?$e(this._events):[]};function Gt(e,t){for(var r=new Array(t),n=0;n{"use strict";var a={cipher:{},hash:{},keyexchange:{},mode:{},misc:{},codec:{},exception:{corrupt:function(e){this.toString=function(){return"CORRUPT: "+this.message},this.message=e},invalid:function(e){this.toString=function(){return"INVALID: "+this.message},this.message=e},bug:function(e){this.toString=function(){return"BUG: "+this.message},this.message=e},notReady:function(e){this.toString=function(){return"NOT READY: "+this.message},this.message=e}}};a.cipher.aes=function(e){this.w[0][0][0]||this.C();var t,r,n,o,i=this.w[0][4],s=this.w[1];t=e.length;var c=1;if(t!==4&&t!==6&&t!==8)throw new a.exception.invalid("invalid aes key size");for(this.b=[n=e.slice(0),o=[]],e=t;e<4*t+28;e++)r=n[e-1],(e%t===0||t===8&&e%t===4)&&(r=i[r>>>24]<<24^i[r>>16&255]<<16^i[r>>8&255]<<8^i[r&255],e%t===0&&(r=r<<8^r>>>24^c<<24,c=c<<1^283*(c>>7))),n[e]=n[e-t]^r;for(t=0;e;t++,e--)r=n[t&3?e:e-4],o[t]=4>=e||4>t?r:s[0][i[r>>>24]]^s[1][i[r>>16&255]]^s[2][i[r>>8&255]]^s[3][i[r&255]]};a.cipher.aes.prototype={encrypt:function(e){return er(this,e,0)},decrypt:function(e){return er(this,e,1)},w:[[[],[],[],[],[]],[[],[],[],[],[]]],C:function(){var e=this.w[0],t=this.w[1],r=e[4],n=t[4],o,i,s,c=[],u=[],f,l,h,m;for(o=0;256>o;o++)u[(c[o]=o<<1^283*(o>>7))^o]=o;for(i=s=0;!r[i];i^=f||1,s=u[s]||1)for(h=s^s<<1^s<<2^s<<3^s<<4,h=h>>8^h&255^99,r[i]=h,n[h]=i,l=c[o=c[f=c[i]]],m=16843009*l^65537*o^257*f^16843008*i,l=257*c[h]^16843008*h,o=0;4>o;o++)e[o][i]=l=l<<24^l>>>8,t[o][h]=m=m<<24^m>>>8;for(o=0;5>o;o++)e[o]=e[o].slice(0),t[o]=t[o].slice(0)}};function er(e,t,r){if(t.length!==4)throw new a.exception.invalid("invalid aes block size");var n=e.b[r],o=t[0]^n[0],i=t[r?3:1]^n[1],s=t[2]^n[2];t=t[r?1:3]^n[3];var c,u,f,l=n.length/4-2,h,m=4,d=[0,0,0,0];c=e.w[r],e=c[0];var b=c[1],F=c[2],J=c[3],Y=c[4];for(h=0;h>>24]^b[i>>16&255]^F[s>>8&255]^J[t&255]^n[m],u=e[i>>>24]^b[s>>16&255]^F[t>>8&255]^J[o&255]^n[m+1],f=e[s>>>24]^b[t>>16&255]^F[o>>8&255]^J[i&255]^n[m+2],t=e[t>>>24]^b[o>>16&255]^F[i>>8&255]^J[s&255]^n[m+3],m+=4,o=c,i=u,s=f;for(h=0;4>h;h++)d[r?3&-h:h]=Y[o>>>24]<<24^Y[i>>16&255]<<16^Y[s>>8&255]<<8^Y[t&255]^n[m++],c=o,o=i,i=s,s=t,t=c;return d}a.bitArray={bitSlice:function(e,t,r){return e=a.bitArray.Y(e.slice(t/32),32-(t&31)).slice(1),r===void 0?e:a.bitArray.clamp(e,r-t)},extract:function(e,t,r){var n=Math.floor(-t-r&31);return((t+r-1^t)&-32?e[t/32|0]<<32-n^e[t/32+1|0]>>>n:e[t/32|0]>>>n)&(1<>t-1,1)),e},partial:function(e,t,r){return e===32?t:(r?t|0:t<<32-e)+1099511627776*e},getPartial:function(e){return Math.round(e/1099511627776)||32},equal:function(e,t){if(a.bitArray.bitLength(e)!==a.bitArray.bitLength(t))return!1;var r=0,n;for(n=0;n>>t),r=e[o]<<32-t;return o=e.length?e[e.length-1]:0,e=a.bitArray.getPartial(o),n.push(a.bitArray.partial(t+e&31,32>>24|r>>>8&65280|(r&65280)<<8|r<<24;return e}};a.codec.utf8String={fromBits:function(e){var t="",r=a.bitArray.bitLength(e),n,o;for(n=0;n>>8>>>8>>>8),o<<=8;return decodeURIComponent(escape(t))},toBits:function(e){e=unescape(encodeURIComponent(e));var t=[],r,n=0;for(r=0;r>>o)>>>26),6>o?(s=e[r]<<6-o,o+=26,r++):(s<<=6,o-=6);for(;n.length&3&&!t;)n+="=";return n},toBits:function(e,t){e=e.replace(/\s|=/g,"");var r=[],n,o=0,i=a.codec.base64.S,s=0,c;for(t&&(i=i.substr(0,62)+"-_"),n=0;nc)throw new a.exception.invalid("this isn't base64!");26>>o),s=c<<32-o):(o+=6,s^=c<<32-o)}return o&56&&r.push(a.bitArray.partial(o&56,s,1)),r}};a.codec.base64url={fromBits:function(e){return a.codec.base64.fromBits(e,1,1)},toBits:function(e){return a.codec.base64.toBits(e,1)}};a.hash.sha256=function(e){this.b[0]||this.C(),e?(this.g=e.g.slice(0),this.f=e.f.slice(0),this.c=e.c):this.reset()};a.hash.sha256.hash=function(e){return new a.hash.sha256().update(e).finalize()};a.hash.sha256.prototype={blockSize:512,reset:function(){return this.g=this.o.slice(0),this.f=[],this.c=0,this},update:function(e){typeof e=="string"&&(e=a.codec.utf8String.toBits(e));var t,r=this.f=a.bitArray.concat(this.f,e);if(t=this.c,e=this.c=t+a.bitArray.bitLength(e),9007199254740991t;r++){for(o=!0,n=2;n*n<=r;n++)if(r%n===0){o=!1;break}o&&(8>t&&(this.o[t]=e(Math.pow(r,.5))),this.b[t]=e(Math.pow(r,1/3)),t++)}},l:function(e){var t,r,n,o=this.g,i=this.b,s=o[0],c=o[1],u=o[2],f=o[3],l=o[4],h=o[5],m=o[6],d=o[7];for(t=0;64>t;t++)16>t?r=e[t]:(r=e[t+1&15],n=e[t+14&15],r=e[t&15]=(r>>>7^r>>>18^r>>>3^r<<25^r<<14)+(n>>>17^n>>>19^n>>>10^n<<15^n<<13)+e[t&15]+e[t+9&15]|0),r=r+d+(l>>>6^l>>>11^l>>>25^l<<26^l<<21^l<<7)+(m^l&(h^m))+i[t],d=m,m=h,h=l,l=f+r|0,f=u,u=c,c=s,s=r+(c&u^f&(c^u))+(c>>>2^c>>>13^c>>>22^c<<30^c<<19^c<<10)|0;o[0]=o[0]+s|0,o[1]=o[1]+c|0,o[2]=o[2]+u|0,o[3]=o[3]+f|0,o[4]=o[4]+l|0,o[5]=o[5]+h|0,o[6]=o[6]+m|0,o[7]=o[7]+d|0}};a.hash.sha512=function(e){this.b[0]||this.C(),e?(this.g=e.g.slice(0),this.f=e.f.slice(0),this.c=e.c):this.reset()};a.hash.sha512.hash=function(e){return new a.hash.sha512().update(e).finalize()};a.hash.sha512.prototype={blockSize:1024,reset:function(){return this.g=this.o.slice(0),this.f=[],this.c=0,this},update:function(e){typeof e=="string"&&(e=a.codec.utf8String.toBits(e));var t,r=this.f=a.bitArray.concat(this.f,e);if(t=this.c,e=this.c=t+a.bitArray.bitLength(e),9007199254740991r;n++){for(i=!0,o=2;o*o<=n;o++)if(n%o===0){i=!1;break}i&&(8>r&&(this.o[2*r]=e(Math.pow(n,.5)),this.o[2*r+1]=t(Math.pow(n,.5))<<24|this.ia[r]),this.b[2*r]=e(Math.pow(n,1/3)),this.b[2*r+1]=t(Math.pow(n,1/3))<<24|this.ka[r],r++)}},l:function(e){var t,r,n=this.g,o=this.b,i=n[0],s=n[1],c=n[2],u=n[3],f=n[4],l=n[5],h=n[6],m=n[7],d=n[8],b=n[9],F=n[10],J=n[11],Y=n[12],je=n[13],Pt=n[14],We=n[15],P;if(typeof Uint32Array<"u"){P=Array(160);for(var C=0;32>C;C++)P[C]=e[C]}else P=e;var C=i,I=s,ve=c,ie=u,Ee=f,se=l,at=h,we=m,H=d,M=b,ze=F,Ae=J,Je=Y,be=je,ct=Pt,Le=We;for(e=0;80>e;e++){if(16>e)t=P[2*e],r=P[2*e+1];else{r=P[2*(e-15)];var w=P[2*(e-15)+1];t=(w<<31|r>>>1)^(w<<24|r>>>8)^r>>>7;var $=(r<<31|w>>>1)^(r<<24|w>>>8)^(r<<25|w>>>7);r=P[2*(e-2)];var q=P[2*(e-2)+1],w=(q<<13|r>>>19)^(r<<3|q>>>29)^r>>>6,q=(r<<13|q>>>19)^(q<<3|r>>>29)^(r<<26|q>>>6),ut=P[2*(e-7)],ft=P[2*(e-16)],Oe=P[2*(e-16)+1];r=$+P[2*(e-7)+1],t=t+ut+(r>>>0<$>>>0?1:0),r+=q,t+=w+(r>>>0>>0?1:0),r+=Oe,t+=ft+(r>>>0>>0?1:0)}P[2*e]=t|=0,P[2*e+1]=r|=0;var ut=H&ze^~H&Je,St=M&Ae^~M&be,q=C&ve^C&Ee^ve&Ee,Dr=I&ie^I&se^ie&se,ft=(I<<4|C>>>28)^(C<<30|I>>>2)^(C<<25|I>>>7),Oe=(C<<4|I>>>28)^(I<<30|C>>>2)^(I<<25|C>>>7),_r=o[2*e],Tt=o[2*e+1],w=Le+((H<<18|M>>>14)^(H<<14|M>>>18)^(M<<23|H>>>9)),$=ct+((M<<18|H>>>14)^(M<<14|H>>>18)^(H<<23|M>>>9))+(w>>>0>>0?1:0),w=w+St,$=$+(ut+(w>>>0>>0?1:0)),w=w+Tt,$=$+(_r+(w>>>0>>0?1:0)),w=w+r|0,$=$+(t+(w>>>0>>0?1:0));r=Oe+Dr,t=ft+q+(r>>>0>>0?1:0),ct=Je,Le=be,Je=ze,be=Ae,ze=H,Ae=M,M=we+w|0,H=at+$+(M>>>0>>0?1:0)|0,at=Ee,we=se,Ee=ve,se=ie,ve=C,ie=I,I=w+r|0,C=$+t+(I>>>0>>0?1:0)|0}s=n[1]=s+I|0,n[0]=i+C+(s>>>0>>0?1:0)|0,u=n[3]=u+ie|0,n[2]=c+ve+(u>>>0>>0?1:0)|0,l=n[5]=l+se|0,n[4]=f+Ee+(l>>>0>>0?1:0)|0,m=n[7]=m+we|0,n[6]=h+at+(m>>>0>>0?1:0)|0,b=n[9]=b+M|0,n[8]=d+H+(b>>>0>>0?1:0)|0,J=n[11]=J+Ae|0,n[10]=F+ze+(J>>>0>>0?1:0)|0,je=n[13]=je+be|0,n[12]=Y+Je+(je>>>0>>0?1:0)|0,We=n[15]=We+Le|0,n[14]=Pt+ct+(We>>>0>>0?1:0)|0}};a.mode.ccm={name:"ccm",F:[],listenProgress:function(e){a.mode.ccm.F.push(e)},unListenProgress:function(e){e=a.mode.ccm.F.indexOf(e),-1u)throw new a.exception.invalid("ccm: iv must be at least 7 bytes");for(i=2;4>i&&f>>>8*i;i++);return i<15-u&&(i=15-u),r=c.clamp(r,8*(15-i)),t=a.mode.ccm.U(e,t,r,n,o,i),s=a.mode.ccm.V(e,s,r,t,o,i),c.concat(s.data,s.tag)},decrypt:function(e,t,r,n,o){o=o||64,n=n||[];var i=a.bitArray,s=i.bitLength(r)/8,f=i.bitLength(t),c=i.clamp(t,f-o),u=i.bitSlice(t,f-o),f=(f-o)/8;if(7>s)throw new a.exception.invalid("ccm: iv must be at least 7 bytes");for(t=2;4>t&&f>>>8*t;t++);if(t<15-s&&(t=15-s),r=i.clamp(r,8*(15-t)),c=a.mode.ccm.V(e,c,r,u,o,t),e=a.mode.ccm.U(e,c.data,r,n,o,t),!i.equal(c.tag,e))throw new a.exception.corrupt("ccm: tag doesn't match");return c.data},ma:function(e,t,r,n,o,i){var s=[],c=a.bitArray,u=c.P;if(n=[c.partial(8,(t.length?64:0)|n-2<<2|i-1)],n=c.concat(n,r),n[3]|=o,n=e.encrypt(n),t.length)for(r=c.bitLength(t)/8,65279>=r?s=[c.partial(16,r)]:4294967295>=r&&(s=c.concat([c.partial(16,65534)],[r])),s=c.concat(s,t),t=0;to||16l&&(a.mode.ccm.da(s/u),l+=h),r[3]++,o=e.encrypt(r),t[s]^=o[0],t[s+1]^=o[1],t[s+2]^=o[2],t[s+3]^=o[3];return{tag:n,data:c.clamp(t,f)}}};a.misc.hmac=function(e,t){this.W=t=t||a.hash.sha256;var r=[[],[]],n,o=t.prototype.blockSize/32;for(this.B=[new t,new t],e.length>o&&(e=t.hash(e)),n=0;nn||0>r)throw new a.exception.invalid("invalid params to pbkdf2");typeof e=="string"&&(e=a.codec.utf8String.toBits(e)),typeof t=="string"&&(t=a.codec.utf8String.toBits(t)),o=o||a.misc.hmac,e=new o(e);var i,s,c,u,f=[],l=a.bitArray;for(u=1;32*f.length<(n||1);u++){for(o=i=e.encrypt(l.concat(t,[u])),s=1;ss;s++)o.push(4294967296*Math.random()|0);for(s=0;s=1<this.u&&(this.u=i),this.N++,this.b=a.hash.sha256.hash(this.b.concat(o)),this.K=new a.cipher.aes(this.b),n=0;4>n&&(this.m[n]=this.m[n]+1|0,!this.m[n]);n++);}for(n=0;n>>1;this.h[s].update([n,this.M++,2,t,i,e.length].concat(e))}break;case"string":t===void 0&&(t=e.length),this.h[s].update([n,this.M++,3,t,i,e.length]),this.h[s].update(e);break;default:u=1}if(u)throw new a.exception.bug("random: addEntropy only supports number, array of numbers or string");this.s[s]+=t,this.i+=t,c===this.A&&(this.isReady()!==this.A&&tr("seeded",Math.max(this.u,this.i)),tr("progress",this.getProgress()))},isReady:function(e){return e=this.R[e!==void 0?e:this.L],this.u&&this.u>=e?this.s[0]>this.$&&new Date().valueOf()>this.X?this.I|this.H:this.H:this.i>=e?this.I|this.A:this.A},getProgress:function(e){return e=this.R[e||this.L],this.u>=e||this.i>e?1:this.i/e},startCollectors:function(){if(!this.D){if(this.a={loadTimeCollector:ke(this,this.la),mouseCollector:ke(this,this.na),keyboardCollector:ke(this,this.ja),accelerometerCollector:ke(this,this.ca),touchCollector:ke(this,this.pa)},window.addEventListener)window.addEventListener("load",this.a.loadTimeCollector,!1),window.addEventListener("mousemove",this.a.mouseCollector,!1),window.addEventListener("keypress",this.a.keyboardCollector,!1),window.addEventListener("devicemotion",this.a.accelerometerCollector,!1),window.addEventListener("touchmove",this.a.touchCollector,!1);else if(document.attachEvent)document.attachEvent("onload",this.a.loadTimeCollector),document.attachEvent("onmousemove",this.a.mouseCollector),document.attachEvent("keypress",this.a.keyboardCollector);else throw new a.exception.bug("can't attach event");this.D=!0}},stopCollectors:function(){this.D&&(window.removeEventListener?(window.removeEventListener("load",this.a.loadTimeCollector,!1),window.removeEventListener("mousemove",this.a.mouseCollector,!1),window.removeEventListener("keypress",this.a.keyboardCollector,!1),window.removeEventListener("devicemotion",this.a.accelerometerCollector,!1),window.removeEventListener("touchmove",this.a.touchCollector,!1)):document.detachEvent&&(document.detachEvent("onload",this.a.loadTimeCollector),document.detachEvent("onmousemove",this.a.mouseCollector),document.detachEvent("keypress",this.a.keyboardCollector)),this.D=!1)},addEventListener:function(e,t){this.J[e][this.ea++]=t},removeEventListener:function(e,t){var r,n,o=this.J[e],i=[];for(n in o)o.hasOwnProperty(n)&&o[n]===t&&i.push(n);for(r=0;rt&&(e.m[t]=e.m[t]+1|0,!e.m[t]);t++);return e.K.encrypt(e.m)}function ke(e,t){return function(){t.apply(e,arguments)}}a.random=new a.prng(6);e:try{if(Qe=typeof fe<"u"&&fe.exports){try{Ze=Ir("crypto")}catch{Ze=null}Qe=Ke=Ze}if(Qe&&Ke.randomBytes)Pe=Ke.randomBytes(128),Pe=new Uint32Array(new Uint8Array(Pe).buffer),a.random.addEntropy(Pe,1024,"crypto['randomBytes']");else if(typeof window<"u"&&typeof Uint32Array<"u"){if(Se=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(Se);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(Se);else break e;a.random.addEntropy(Se,1024,"crypto['getRandomValues']")}}catch(e){typeof window<"u"&&window.console&&(console.log("There was an error collecting entropy from the browser:"),console.log(e))}var Pe,Ke,Se,Qe,Ze;a.json={defaults:{v:1,iter:1e4,ks:128,ts:64,mode:"ccm",adata:"",cipher:"aes"},ha:function(e,t,r,n){r=r||{},n=n||{};var o=a.json,i=o.j({iv:a.random.randomWords(4,0)},o.defaults),s;if(o.j(i,r),r=i.adata,typeof i.salt=="string"&&(i.salt=a.codec.base64.toBits(i.salt)),typeof i.iv=="string"&&(i.iv=a.codec.base64.toBits(i.iv)),!a.mode[i.mode]||!a.cipher[i.cipher]||typeof e=="string"&&100>=i.iter||i.ts!==64&&i.ts!==96&&i.ts!==128||i.ks!==128&&i.ks!==192&&i.ks!==256||2>i.iv.length||4=t.iter||t.ts!==64&&t.ts!==96&&t.ts!==128||t.ks!==128&&t.ks!==192&&t.ks!==256||!t.iv||2>t.iv.length||4{"use strict";var An=Object.prototype.hasOwnProperty,S="~";function Te(){}Object.create&&(Te.prototype=Object.create(null),new Te().__proto__||(S=!1));function bn(e,t,r){this.fn=e,this.context=t,this.once=r||!1}function mr(e,t,r,n,o){if(typeof r!="function")throw new TypeError("The listener must be a function");var i=new bn(r,n||e,o),s=S?S+t:t;return e._events[s]?e._events[s].fn?e._events[s]=[e._events[s],i]:e._events[s].push(i):(e._events[s]=i,e._eventsCount++),e}function et(e,t){--e._eventsCount===0?e._events=new Te:delete e._events[t]}function k(){this._events=new Te,this._eventsCount=0}k.prototype.eventNames=function(){var t=[],r,n;if(this._eventsCount===0)return t;for(n in r=this._events)An.call(r,n)&&t.push(S?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(r)):t};k.prototype.listeners=function(t){var r=S?S+t:t,n=this._events[r];if(!n)return[];if(n.fn)return[n.fn];for(var o=0,i=n.length,s=new Array(i);o{let n=t.isOk()?{type:"Ok",value:t.value}:{type:"Err",value:t.error},o=r.withStackTrace?new Error().stack:void 0;return{data:n,message:e,stack:o}};function ae(e,t,r,n){function o(i){return i instanceof r?i:new r(function(s){s(i)})}return new(r||(r=Promise))(function(i,s){function c(l){try{f(n.next(l))}catch(h){s(h)}}function u(l){try{f(n.throw(l))}catch(h){s(h)}}function f(l){l.done?i(l.value):o(l.value).then(c,u)}f((n=n.apply(e,t||[])).next())})}function It(e){var t=typeof Symbol=="function"&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&typeof e.length=="number")return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function G(e){return this instanceof G?(this.v=e,this):new G(e)}function Mt(e,t,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=r.apply(e,t||[]),o,i=[];return o=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),c("next"),c("throw"),c("return",s),o[Symbol.asyncIterator]=function(){return this},o;function s(d){return function(b){return Promise.resolve(b).then(d,h)}}function c(d,b){n[d]&&(o[d]=function(F){return new Promise(function(J,Y){i.push([d,F,J,Y])>1||u(d,F)})},b&&(o[d]=b(o[d])))}function u(d,b){try{f(n[d](b))}catch(F){m(i[0][3],F)}}function f(d){d.value instanceof G?Promise.resolve(d.value.v).then(l,h):m(i[0][2],d)}function l(d){u("next",d)}function h(d){u("throw",d)}function m(d,b){d(b),i.shift(),i.length&&u(i[0][0],i[0][1])}}function Nr(e){var t,r;return t={},n("next"),n("throw",function(o){throw o}),n("return"),t[Symbol.iterator]=function(){return this},t;function n(o,i){t[o]=e[o]?function(s){return(r=!r)?{value:G(e[o](s)),done:!1}:i?i(s):s}:i}}function Fr(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=e[Symbol.asyncIterator],r;return t?t.call(e):(e=typeof It=="function"?It(e):e[Symbol.iterator](),r={},n("next"),n("throw"),n("return"),r[Symbol.asyncIterator]=function(){return this},r);function n(i){r[i]=e[i]&&function(s){return new Promise(function(c,u){s=e[i](s),o(c,u,s.done,s.value)})}}function o(i,s,c,u){Promise.resolve(u).then(function(f){i({value:f,done:c})},s)}}var O=class e{constructor(t){this._promise=t}static fromSafePromise(t){let r=t.then(n=>new B(n));return new e(r)}static fromPromise(t,r){let n=t.then(o=>new B(o)).catch(o=>new j(r(o)));return new e(n)}static fromThrowable(t,r){return(...n)=>new e(ae(this,void 0,void 0,function*(){try{return new B(yield t(...n))}catch(o){return new j(r?r(o):o)}}))}static combine(t){return Br(t)}static combineWithAllErrors(t){return jr(t)}map(t){return new e(this._promise.then(r=>ae(this,void 0,void 0,function*(){return r.isErr()?new j(r.error):new B(yield t(r.value))})))}andThrough(t){return new e(this._promise.then(r=>ae(this,void 0,void 0,function*(){if(r.isErr())return new j(r.error);let n=yield t(r.value);return n.isErr()?new j(n.error):new B(r.value)})))}andTee(t){return new e(this._promise.then(r=>ae(this,void 0,void 0,function*(){if(r.isErr())return new j(r.error);try{yield t(r.value)}catch{}return new B(r.value)})))}mapErr(t){return new e(this._promise.then(r=>ae(this,void 0,void 0,function*(){return r.isOk()?new B(r.value):new j(yield t(r.error))})))}andThen(t){return new e(this._promise.then(r=>{if(r.isErr())return new j(r.error);let n=t(r.value);return n instanceof e?n._promise:n}))}orElse(t){return new e(this._promise.then(r=>ae(this,void 0,void 0,function*(){return r.isErr()?t(r.error):new B(r.value)})))}match(t,r){return this._promise.then(n=>n.match(t,r))}unwrapOr(t){return this._promise.then(r=>r.unwrapOr(t))}safeUnwrap(){return Mt(this,arguments,function*(){return yield G(yield G(yield*Nr(Fr(yield G(this._promise.then(r=>r.safeUnwrap()))))))})}then(t,r){return this._promise.then(t,r)}[Symbol.asyncIterator](){return Mt(this,arguments,function*(){let r=yield G(this._promise);return r.isErr()&&(yield yield G(D(r.error))),yield G(r.value)})}},T=e=>new O(Promise.resolve(new B(e))),D=e=>new O(Promise.resolve(new j(e))),Dn=O.fromPromise,_n=O.fromSafePromise,Cn=O.fromThrowable,Nt=e=>{let t=ne([]);for(let r of e)if(r.isErr()){t=K(r.error);break}else t.map(n=>n.push(r.value));return t},Br=e=>O.fromSafePromise(Promise.all(e)).andThen(Nt),Ft=e=>{let t=ne([]);for(let r of e)r.isErr()&&t.isErr()?t.error.push(r.error):r.isErr()&&t.isOk()?t=K([r.error]):r.isOk()&&t.isOk()&&t.value.push(r.value);return t},jr=e=>O.fromSafePromise(Promise.all(e)).andThen(Ft),dt;(function(e){function t(o,i){return(...s)=>{try{let c=o(...s);return ne(c)}catch(c){return K(i?i(c):c)}}}e.fromThrowable=t;function r(o){return Nt(o)}e.combine=r;function n(o){return Ft(o)}e.combineWithAllErrors=n})(dt||(dt={}));var ne=e=>new B(e);function K(e){return new j(e)}var B=class{constructor(t){this.value=t}isOk(){return!0}isErr(){return!this.isOk()}map(t){return ne(t(this.value))}mapErr(t){return ne(this.value)}andThen(t){return t(this.value)}andThrough(t){return t(this.value).map(r=>this.value)}andTee(t){try{t(this.value)}catch{}return ne(this.value)}orElse(t){return ne(this.value)}asyncAndThen(t){return t(this.value)}asyncAndThrough(t){return t(this.value).map(()=>this.value)}asyncMap(t){return O.fromSafePromise(t(this.value))}unwrapOr(t){return this.value}match(t,r){return t(this.value)}safeUnwrap(){let t=this.value;return function*(){return t}()}_unsafeUnwrap(t){return this.value}_unsafeUnwrapErr(t){throw Ut("Called `_unsafeUnwrapErr` on an Ok",this,t)}*[Symbol.iterator](){return this.value}},j=class{constructor(t){this.error=t}isOk(){return!1}isErr(){return!this.isOk()}map(t){return K(this.error)}mapErr(t){return K(t(this.error))}andThrough(t){return K(this.error)}andTee(t){return K(this.error)}andThen(t){return K(this.error)}orElse(t){return t(this.error)}asyncAndThen(t){return D(this.error)}asyncAndThrough(t){return D(this.error)}asyncMap(t){return D(this.error)}unwrapOr(t){return t}match(t,r){return r(this.error)}safeUnwrap(){let t=this.error;return function*(){throw yield K(t),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(t){throw Ut("Called `_unsafeUnwrap` on an Err",this,t)}_unsafeUnwrapErr(t){return this.error}*[Symbol.iterator](){let t=this;return yield t,t}},kn=dt.fromThrowable;var U=class extends Error{constructor(r,n={}){let{cause:o,context:i}=n;super(r,{cause:o});A(this,"context");this.name=this.constructor.name,this.context=i}};var Q=e=>{if(e instanceof Error)return e;let t="[Unable to stringify the thrown value]";try{t=JSON.stringify(e)}catch{}return new Error(t)};var Wr=()=>typeof Deno<"u";var Z=e=>Wr()?new URL(`./worker/${e}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${e==="main"?`worker/${e}`:e}.js`));var V=class extends U{};var De=class extends V{constructor(){super(...arguments);A(this,"message","An error occured while trying to connect to WebSocket")}};var Kt=xe(Ge());var g=new Kt.default,_,Xt=!1;self.onmessage=e=>{Vr(e),Xt||(Xt=!0,g.once("OPERATION_FAILED",()=>{_&&_.terminate()}))};var ee=(e,t)=>(Object.assign(e,t),typeof WorkerGlobalScope<"u"&&self.postMessage({event:"FILE_UPDATED",lufiFile:e}),e),Ye=(e,t)=>{ee(e,{uploadStatus:2}),self.postMessage({event:"OPERATION_FAILED",error:t})},Vr=(e,t)=>{let{action:r}=e.data;if(r===5||r===8)_.postMessage(e.data,e.data);else{switch(r){case 2:_=new Worker(Z("cancel"),{type:"module"}),_.postMessage(e.data,e.data);break;case 3:_=new Worker(Z("download"),{type:"module"}),_.postMessage(e.data,e.data);break;case 4:_=new Worker(Z("infos"),{type:"module"}),_.postMessage(e.data,e.data);break;case 7:_=_||new Worker(Z("remove"),{type:"module"}),_.postMessage(e.data,e.data);break;case 9:_=_||new Worker(Z("upload"),{type:"module"}),_.postMessage(e.data,e.data);break;default:console.error("Action not found")}_.onmessage=n=>{t&&t(n),self.postMessage(n.data,n.data)},_.onerror=n=>{console.error(`Error: ${n.message}`)}}},Qt=()=>{g.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),g.once("OPERATION_FAILED",e=>{self.postMessage({event:"OPERATION_FAILED",error:e})})};var ue=class{constructor(t,r){if(!t||t.length!=64)throw Error("Charset must contain 64 characters");this._charset=t,this._noPadding=!!r,this._valid=new RegExp("^["+this._charset.replace("-","\\-")+"]+={0,2}$")}Encode(t){let r=t.byteLength;if(!r)return"";let n=new Uint8Array(t),o="";for(let i=0;i>2]+this._charset[(n[i]&3)<<4|n[i+1]>>4]+this._charset[(n[i+1]&15)<<2|n[i+2]>>6]+this._charset[n[i+2]&63];return r%3==2?(o=o.substring(0,o.length-1),this._noPadding||(o+="=")):r%3==1&&(o=o.substring(0,o.length-2),this._noPadding||(o+="==")),o}Decode(t){if(t=(t||"").replace(/[\s]/g,""),!t)return new ArrayBuffer(0);if(!this._valid.test(t))throw Error("Invalid base64 input sequence");let r=Math.floor(t.length*.75);t[t.length-2]=="="?r-=2:t[t.length-1]=="="&&r--;let n=new Uint8Array(r),o,i,s,c,u=0,f=0;for(;u>4,n[u++]=(i&15)<<4|s>>2,n[u++]=(s&3)<<6|c;return n.buffer}};var Xr=new ue("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");function _e(e){return Xr.Decode(e)}var Yr=new ue("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",!0);function yt(e){return Yr.Decode(e)}var or=xe(nr());var te=class extends U{};var le=class extends te{constructor(){super(...arguments);A(this,"message","Unable to decrypt the provided data")}};var ir=(e,t)=>{try{let r=typeof t=="string"?t:t.data;return T(_e(or.default.decrypt(e,r)))}catch(r){return D(new le(void 0,{cause:Q(r)}))}};var sr=(e,t)=>tn(e).andThen(r=>O.fromPromise(crypto.subtle.decrypt({name:"AES-GCM",iv:t.iv},r,_e(t.data)),n=>new le(void 0,{cause:Q(n)})));var tn=e=>O.fromPromise(crypto.subtle.importKey("raw",yt(e),{name:"AES-GCM"},!1,["encrypt","decrypt"]),t=>new te("Unable to import cryptography key",{cause:Q(t)}));var ar=(e,t)=>t.algo===void 0||t.algo===0?ir(e,t):sr(e,t);var N={},ur=5,nn=e=>(g.emit("UPLOAD_CANCELLED",e.success),T(void 0)),on=(e,t)=>{let r=e.split("XXMOJOXX"),n=r.shift();if(n!==void 0){let o=JSON.parse(n);if(dn(o)){let i=r.shift();if(i){let s=JSON.parse(i);return s.iv&&(s.iv=new Uint8Array(Object.values(s.iv))),ar(t.keys.client,s).andThen(c=>{let u=typeof c=="string"?new TextEncoder().encode(c).buffer:c;return o.part===0?(ee(t,{chunksReady:t.chunksReady+1,delAtFirstView:o.del_at_first_view,delay:o.delay,name:o.name,size:o.size,totalChunks:o.total,type:o.type,zipped:o.zipped}),g.emit("DOWNLOAD_STARTED")):ee(t,{chunksReady:t.chunksReady+1}),g.emit("CHUNK_DOWNLOADED",u,o.part),++o.part===o.total?un(t).andThen(()=>(g.emit("DOWNLOAD_COMPLETE"),g.emit("SOCKET_OPERATION_TERMINATED"),T(void 0))):T(void 0)})}else{let s=new V("Cannot retrieve metadata from data received by the server");return g.emit("OPERATION_FAILED",s),D(s)}}else{let i=new V(o.msg);return g.emit("OPERATION_FAILED",i),D(i)}}else{let o=new V("Cannot retrieve metadata from data received by the server");return g.emit("OPERATION_FAILED",o),D(o)}},sn=(e,t)=>{if(e.success)return e.j===0&&(ee(t,{keys:{client:t.keys.client,server:e.short},actionToken:e.token,queueIndex:e.i}),g.emit("UPLOAD_STARTED")),ee(t,{chunksReady:t.chunksReady+1,createdAt:e.created_at}),g.emit("CHUNK_UPLOADED"),t.chunksReady===t.totalChunks&&(ee(t,{uploadStatus:1}),g.emit("UPLOAD_COMPLETE"),g.emit("SOCKET_OPERATION_TERMINATED")),T(void 0);{let r=new V(e.msg);return g.emit("OPERATION_FAILED",r),D(r)}},an=(e,t)=>{let r=pn(e.data),n;if(r)if(!r.action&&r.msg){let o=new V(r.msg);return g.emit("OPERATION_FAILED",o),D(o)}else"delay"in r?n=sn(r,t):n=nn(r);else n=on(e.data,t);return n},cn=e=>N!==void 0&&N[e]!==void 0&&N[e].readyState===WebSocket.CONNECTING,Et=e=>N!==void 0&&N[e]!==void 0&&N[e].readyState===WebSocket.OPEN;var un=e=>{let t;return e.password?t={ended:!0,file_pwd:e.password}:t={ended:!0},At(ln(e),e,JSON.stringify(t))},wt=(e,t,r)=>At(hn(e),e,`${JSON.stringify(t)}XXMOJOXX${JSON.stringify(r)}`),At=(e,t,r)=>Et(e)?(N[e].onmessage=n=>an(n,t),N[e].send(r),T(void 0)):fr(e).andThen(()=>At(e,t,r)),fr=(e,t=0)=>(!Et(e)&&!cn(e)&&(N[e]=new WebSocket(e),g.once("SOCKET_OPERATION_TERMINATED",()=>{N[e].close()}),g.once("OPERATION_FAILED",()=>{g.emit("SOCKET_OPERATION_TERMINATED")}),N[e].onopen=()=>{g.emit("SOCKET_OPENED")},N[e].onclose=()=>{},N[e].onerror=()=>++t<=ur?(console.error(`An error happened while trying to connect to WebSocket ${e}. Trying again. ${t} / ${ur}`),fr(e,t)):(g.emit("SOCKET_ONERROR"),D(new De(`Unable to connect to WebSocket ${e}.`)))),fn(e).andThen(()=>T(e)).orElse(r=>D(r))),fn=e=>O.fromPromise(new Promise((t,r)=>{Et(e)?t(void 0):(g.once("SOCKET_OPENED",()=>{t(void 0)}),g.on("SOCKET_ONERROR",()=>{r(new De)}))}),t=>Q(t));var lr=(e,t)=>{let r=new URL(e);return r.protocol=r.protocol==="http:"?"ws:":"wss:",r.pathname+=t,new URL(r.origin+r.pathname)},ln=e=>lr(new URL(e.serverUrl),"download"+`/${e.keys.server}`).toString(),hn=e=>lr(new URL(e.serverUrl),"upload").toString(),pn=e=>{try{let t=JSON.parse(e);if(t&&typeof t=="object")return t}catch{}return!1},dn=e=>typeof e=="object"&&e!==null&&!("msg"in e);var pr=xe(Ge());var gn=xe(Ge());var En={},bs=new pr.default;var wn=()=>Object.values(En).filter(e=>e.uploadStatus===4),dr=e=>Object.keys(wn()).indexOf(e);var Lt=xe(yr(),1);var Re=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},Ot=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},gr=e=>globalThis.DOMException===void 0?new Ot(e):new DOMException(e),vr=e=>{let t=e.reason===void 0?gr("This operation was aborted."):e.reason;return t instanceof Error?t:gr(t)};function xt(e,t){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout}}=t,s,u=new Promise((f,l)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(t.signal){let{signal:m}=t;m.aborted&&l(vr(m));let d=()=>{l(vr(m))};m.addEventListener("abort",d,{once:!0}),e.finally(()=>{m.removeEventListener("abort",d)})}if(r===Number.POSITIVE_INFINITY){e.then(f,l);return}let h=new Re;s=i.setTimeout.call(void 0,()=>{if(n){try{f(n())}catch(m){l(m)}return}typeof e.cancel=="function"&&e.cancel(),o===!1?f():o instanceof Error?l(o):(h.message=o!=null?o:`Promise timed out after ${r} milliseconds`,l(h))},r),(async()=>{try{f(await e)}catch(m){l(m)}})()}).finally(()=>{u.clear()});return u.clear=()=>{i.clearTimeout.call(void 0,s),s=void 0},u}function Dt(e,t,r){let n=0,o=e.length;for(;o>0;){let i=Math.trunc(o/2),s=n+i;r(e[s],t)<=0?(n=++s,o-=i+1):o=i}return n}var X,Ie=class{constructor(){L(this,X,[])}enqueue(t,r){r={priority:0,...r};let n={priority:r.priority,run:t};if(this.size&&p(this,X)[this.size-1].priority>=r.priority){p(this,X).push(n);return}let o=Dt(p(this,X),n,(i,s)=>s.priority-i.priority);p(this,X).splice(o,0,n)}dequeue(){let t=p(this,X).shift();return t==null?void 0:t.run}filter(t){return p(this,X).filter(r=>r.priority===t.priority).map(r=>r.run)}get size(){return p(this,X).length}};X=new WeakMap;var he,pe,oe,Ue,de,Ne,W,me,R,Fe,z,ye,re,Be,y,Er,wr,Ar,br,Lr,tt,_t,Ct,rt,Or,nt,Me=class extends Lt.default{constructor(r){var n,o,i,s;super();L(this,y);L(this,he);L(this,pe);L(this,oe,0);L(this,Ue);L(this,de);L(this,Ne,0);L(this,W);L(this,me);L(this,R);L(this,Fe);L(this,z,0);L(this,ye);L(this,re);L(this,Be);A(this,"timeout");if(r={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:Ie,...r},!(typeof r.intervalCap=="number"&&r.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${(o=(n=r.intervalCap)==null?void 0:n.toString())!=null?o:""}\` (${typeof r.intervalCap})`);if(r.interval===void 0||!(Number.isFinite(r.interval)&&r.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${(s=(i=r.interval)==null?void 0:i.toString())!=null?s:""}\` (${typeof r.interval})`);E(this,he,r.carryoverConcurrencyCount),E(this,pe,r.intervalCap===Number.POSITIVE_INFINITY||r.interval===0),E(this,Ue,r.intervalCap),E(this,de,r.interval),E(this,R,new r.queueClass),E(this,Fe,r.queueClass),this.concurrency=r.concurrency,this.timeout=r.timeout,E(this,Be,r.throwOnTimeout===!0),E(this,re,r.autoStart===!1)}get concurrency(){return p(this,ye)}set concurrency(r){if(!(typeof r=="number"&&r>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${r}\` (${typeof r})`);E(this,ye,r),x(this,y,rt).call(this)}async add(r,n={}){return n={timeout:this.timeout,throwOnTimeout:p(this,Be),...n},new Promise((o,i)=>{p(this,R).enqueue(async()=>{var s;He(this,z)._++,He(this,oe)._++;try{(s=n.signal)==null||s.throwIfAborted();let c=r({signal:n.signal});n.timeout&&(c=xt(Promise.resolve(c),{milliseconds:n.timeout})),n.signal&&(c=Promise.race([c,x(this,y,Or).call(this,n.signal)]));let u=await c;o(u),this.emit("completed",u)}catch(c){if(c instanceof Re&&!n.throwOnTimeout){o();return}i(c),this.emit("error",c)}finally{x(this,y,Ar).call(this)}},n),this.emit("add"),x(this,y,tt).call(this)})}async addAll(r,n){return Promise.all(r.map(async o=>this.add(o,n)))}start(){return p(this,re)?(E(this,re,!1),x(this,y,rt).call(this),this):this}pause(){E(this,re,!0)}clear(){E(this,R,new(p(this,Fe)))}async onEmpty(){p(this,R).size!==0&&await x(this,y,nt).call(this,"empty")}async onSizeLessThan(r){p(this,R).sizep(this,R).size{x(this,y,br).call(this)},n)),!0}return!1},tt=function(){if(p(this,R).size===0)return p(this,W)&&clearInterval(p(this,W)),E(this,W,void 0),this.emit("empty"),p(this,z)===0&&this.emit("idle"),!1;if(!p(this,re)){let r=!p(this,y,Lr);if(p(this,y,Er)&&p(this,y,wr)){let n=p(this,R).dequeue();return n?(this.emit("active"),n(),r&&x(this,y,_t).call(this),!0):!1}}return!1},_t=function(){p(this,pe)||p(this,W)!==void 0||(E(this,W,setInterval(()=>{x(this,y,Ct).call(this)},p(this,de))),E(this,Ne,Date.now()+p(this,de)))},Ct=function(){p(this,oe)===0&&p(this,z)===0&&p(this,W)&&(clearInterval(p(this,W)),E(this,W,void 0)),E(this,oe,p(this,he)?p(this,z):0),x(this,y,rt).call(this)},rt=function(){for(;x(this,y,tt).call(this););},Or=async function(r){return new Promise((n,o)=>{r.addEventListener("abort",()=>{o(r.reason)},{once:!0})})},nt=async function(r,n){return new Promise(o=>{let i=()=>{n&&!n()||(this.off(r,i),o())};this.on(r,i)})};var xr=!1,kt=navigator.hardwareConcurrency||4,ge=new Me({concurrency:kt,autoStart:!1}),it=0,st=[],ot=!1;self.onmessage=e=>{let t=e.data,{chunk:r,lufiFile:n}=t.args;if(xr||(Qt(),xr=!0),r){if(st[r.index]=r,st.length===n.totalChunks)return g.once("UPLOAD_COMPLETE",()=>{self.postMessage({event:"UPLOAD_COMPLETE"})}),g.on("FILE_UPDATED",ee),g.on("CHUNK_UPLOADED",()=>{self.postMessage({event:"CHUNK_UPLOADED"}),it--,!ot&&itOn(e,dr(e.args.lufiFile.keys.client)),On=(e,t)=>{let{lufiFile:r}=e.args,n=new Worker(Z("encrypt"),{type:"module"});return g.on("UPLOAD_STARTED",()=>{n.onmessage=async o=>{if(o.data.encryptedData){let{encryptedData:i}=o.data;await ge.add(async()=>{await wt(r,{total:r.totalChunks,part:o.data.chunkIndex,size:r.size,name:r.name.split("/").pop(),type:r.type,delay:r.delay,del_at_first_view:r.delAtFirstView,zipped:r.zipped,id:r.keys.server,i:t,file_pwd:r.password},i),it++,(ot||it===kt)&&ge.pause()})}ge.start(),o.data.error&&(Ye(r,o.data.error),n.terminate())};for(let o=1;o{if(o.data.encryptedData){let{encryptedData:i}=o.data;wt(r,{total:r.totalChunks,part:o.data.chunkIndex,size:r.size,name:r.name.split("/").pop(),type:r.type,delay:r.delay,del_at_first_view:r.delAtFirstView,zipped:r.zipped,id:null,i:t,file_pwd:r.password},i).mapErr(s=>{Ye(r,s)})}o.data.error&&Ye(r,o.data.error)},e.args.chunk=st[0],n.postMessage(e),T(void 0)};