From dbf9e7f19dc997bc70a027e57b19bd9289993666 Mon Sep 17 00:00:00 2001 From: Booteille Date: Tue, 12 Nov 2024 17:32:35 +0100 Subject: [PATCH] Update lufi API --- themes/default/public/js/lufi.js | 2 +- themes/default/public/js/worker/cancel.js | 2 +- themes/default/public/js/worker/download.js | 2 +- themes/default/public/js/worker/encrypt.js | 2 +- themes/default/public/js/worker/infos.js | 2 +- themes/default/public/js/worker/main.js | 2 +- themes/default/public/js/worker/remove.js | 2 +- themes/default/public/js/worker/upload.js | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/themes/default/public/js/lufi.js b/themes/default/public/js/lufi.js index 8f6b25b..a514b57 100755 --- a/themes/default/public/js/lufi.js +++ b/themes/default/public/js/lufi.js @@ -1 +1 @@ -var Fr=Object.create;var Ze=Object.defineProperty;var Br=Object.getOwnPropertyDescriptor;var _r=Object.getOwnPropertyNames;var jr=Object.getPrototypeOf,Nr=Object.prototype.hasOwnProperty;var Jr=(t,e,r)=>e in t?Ze(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var Gr=(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 zt=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),qr=(t,e)=>{for(var r in e)Ze(t,r,{get:e[r],enumerable:!0})},Zr=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of _r(e))!Nr.call(t,i)&&i!==r&&Ze(t,i,{get:()=>e[i],enumerable:!(n=Br(e,i))||n.enumerable});return t};var lt=(t,e,r)=>(r=t!=null?Fr(jr(t)):{},Zr(e||!t||!t.__esModule?Ze(r,"default",{value:t,enumerable:!0}):r,t));var d=(t,e,r)=>Jr(t,typeof e!="symbol"?e+"":e,r);var vt=zt((Jn,pt)=>{"use strict";var xe=typeof Reflect=="object"?Reflect:null,Ft=xe&&typeof xe.apply=="function"?xe.apply:function(e,r,n){return Function.prototype.apply.call(e,r,n)},He;xe&&typeof xe.ownKeys=="function"?He=xe.ownKeys:Object.getOwnPropertySymbols?He=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:He=function(e){return Object.getOwnPropertyNames(e)};function Hr(t){console&&console.warn&&console.warn(t)}var _t=Number.isNaN||function(e){return e!==e};function C(){C.init.call(this)}pt.exports=C;pt.exports.once=Vr;C.EventEmitter=C;C.prototype._events=void 0;C.prototype._eventsCount=0;C.prototype._maxListeners=void 0;var Bt=10;function We(t){if(typeof t!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t)}Object.defineProperty(C,"defaultMaxListeners",{enumerable:!0,get:function(){return Bt},set:function(t){if(typeof t!="number"||t<0||_t(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");Bt=t}});C.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};C.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 jt(t){return t._maxListeners===void 0?C.defaultMaxListeners:t._maxListeners}C.prototype.getMaxListeners=function(){return jt(this)};C.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 c=o[e];if(c===void 0)return!1;if(typeof c=="function")Ft(c,this,r);else for(var u=c.length,h=Zt(c,u),n=0;n0&&s.length>i&&!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,Hr(a)}return t}C.prototype.addListener=function(e,r){return Nt(this,e,r,!1)};C.prototype.on=C.prototype.addListener;C.prototype.prependListener=function(e,r){return Nt(this,e,r,!0)};function Wr(){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 Jt(t,e,r){var n={fired:!1,wrapFn:void 0,target:t,type:e,listener:r},i=Wr.bind(n);return i.listener=r,n.wrapFn=i,i}C.prototype.once=function(e,r){return We(r),this.on(e,Jt(this,e,r)),this};C.prototype.prependOnceListener=function(e,r){return We(r),this.prependListener(e,Jt(this,e,r)),this};C.prototype.removeListener=function(e,r){var n,i,o,s,a;if(We(r),i=this._events,i===void 0)return this;if(n=i[e],n===void 0)return this;if(n===r||n.listener===r)--this._eventsCount===0?this._events=Object.create(null):(delete i[e],i.removeListener&&this.emit("removeListener",e,n.listener||r));else if(typeof n!="function"){for(o=-1,s=n.length-1;s>=0;s--)if(n[s]===r||n[s].listener===r){a=n[s].listener,o=s;break}if(o<0)return this;o===0?n.shift():$r(n,o),n.length===1&&(i[e]=n[0]),i.removeListener!==void 0&&this.emit("removeListener",e,a||r)}return this};C.prototype.off=C.prototype.removeListener;C.prototype.removeAllListeners=function(e){var r,n,i;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 o=Object.keys(n),s;for(i=0;i=0;i--)this.removeListener(e,r[i]);return this};function Gt(t,e,r){var n=t._events;if(n===void 0)return[];var i=n[e];return i===void 0?[]:typeof i=="function"?r?[i.listener||i]:[i]:r?Kr(i):Zt(i,i.length)}C.prototype.listeners=function(e){return Gt(this,e,!0)};C.prototype.rawListeners=function(e){return Gt(this,e,!1)};C.listenerCount=function(t,e){return typeof t.listenerCount=="function"?t.listenerCount(e):qt.call(t,e)};C.prototype.listenerCount=qt;function qt(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}C.prototype.eventNames=function(){return this._eventsCount>0?He(this._events):[]};function Zt(t,e){for(var r=new Array(e),n=0;n{"use strict";var f={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}}};f.cipher.aes=function(t){this.s[0][0][0]||this.O();var e,r,n,i,o=this.s[0][4],s=this.s[1];e=t.length;var a=1;if(e!==4&&e!==6&&e!==8)throw new f.exception.invalid("invalid aes key size");for(this.b=[n=t.slice(0),i=[]],t=e;t<4*e+28;t++)r=n[t-1],(t%e===0||e===8&&t%e===4)&&(r=o[r>>>24]<<24^o[r>>16&255]<<16^o[r>>8&255]<<8^o[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],i[e]=4>=t||4>e?r:s[0][o[r>>>24]]^s[1][o[r>>16&255]]^s[2][o[r>>8&255]]^s[3][o[r&255]]};f.cipher.aes.prototype={encrypt:function(t){return nr(this,t,0)},decrypt:function(t){return nr(this,t,1)},s:[[[],[],[],[],[]],[[],[],[],[],[]]],O:function(){var t=this.s[0],e=this.s[1],r=t[4],n=e[4],i,o,s,a=[],c=[],u,h,l,p;for(i=0;256>i;i++)c[(a[i]=i<<1^283*(i>>7))^i]=i;for(o=s=0;!r[o];o^=u||1,s=c[s]||1)for(l=s^s<<1^s<<2^s<<3^s<<4,l=l>>8^l&255^99,r[o]=l,n[l]=o,h=a[i=a[u=a[o]]],p=16843009*h^65537*i^257*u^16843008*o,h=257*a[l]^16843008*l,i=0;4>i;i++)t[i][o]=h=h<<24^h>>>8,e[i][l]=p=p<<24^p>>>8;for(i=0;5>i;i++)t[i]=t[i].slice(0),e[i]=e[i].slice(0)}};function nr(t,e,r){if(e.length!==4)throw new f.exception.invalid("invalid aes block size");var n=t.b[r],i=e[0]^n[0],o=e[r?3:1]^n[1],s=e[2]^n[2];e=e[r?1:3]^n[3];var a,c,u,h=n.length/4-2,l,p=4,v=[0,0,0,0];a=t.s[r],t=a[0];var m=a[1],w=a[2],g=a[3],A=a[4];for(l=0;l>>24]^m[o>>16&255]^w[s>>8&255]^g[e&255]^n[p],c=t[o>>>24]^m[s>>16&255]^w[e>>8&255]^g[i&255]^n[p+1],u=t[s>>>24]^m[e>>16&255]^w[i>>8&255]^g[o&255]^n[p+2],e=t[e>>>24]^m[i>>16&255]^w[o>>8&255]^g[s&255]^n[p+3],p+=4,i=a,o=c,s=u;for(l=0;4>l;l++)v[r?3&-l:l]=A[i>>>24]<<24^A[o>>16&255]<<16^A[s>>8&255]<<8^A[e&255]^n[p++],a=i,i=o,o=s,s=e,e=a;return v}f.bitArray={bitSlice:function(t,e,r){return t=f.bitArray.$(t.slice(e/32),32-(e&31)).slice(1),r===void 0?t:f.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(f.bitArray.bitLength(t)!==f.bitArray.bitLength(e))return!1;var r=0,n;for(n=0;n>>e),r=t[i]<<32-e;return i=t.length?t[t.length-1]:0,t=f.bitArray.getPartial(i),n.push(f.bitArray.partial(e+t&31,32>>24|r>>>8&65280|(r&65280)<<8|r<<24;return t}};f.codec.utf8String={fromBits:function(t){var e="",r=f.bitArray.bitLength(t),n,i;for(n=0;n>>8>>>8>>>8),i<<=8;return decodeURIComponent(escape(e))},toBits:function(t){t=unescape(encodeURIComponent(t));var e=[],r,n=0;for(r=0;r>>s)>>>i),sh){if(!e)try{return f.codec.base32hex.toBits(t)}catch{}throw new f.exception.invalid("this isn't "+l+"!")}a>i?(a-=i,o.push(u^h>>>a),u=h<>>i)>>>26),6>i?(s=t[r]<<6-i,i+=26,r++):(s<<=6,i-=6);for(;n.length&3&&!e;)n+="=";return n},toBits:function(t,e){t=t.replace(/\s|=/g,"");var r=[],n,i=0,o=f.codec.base64.B,s=0,a;for(e&&(o=o.substr(0,62)+"-_"),n=0;na)throw new f.exception.invalid("this isn't base64!");26>>i),s=a<<32-i):(i+=6,s^=a<<32-i)}return i&56&&r.push(f.bitArray.partial(i&56,s,1)),r}};f.codec.base64url={fromBits:function(t){return f.codec.base64.fromBits(t,1,1)},toBits:function(t){return f.codec.base64.toBits(t,1)}};f.hash.sha256=function(t){this.b[0]||this.O(),t?(this.F=t.F.slice(0),this.A=t.A.slice(0),this.l=t.l):this.reset()};f.hash.sha256.hash=function(t){return new f.hash.sha256().update(t).finalize()};f.hash.sha256.prototype={blockSize:512,reset:function(){return this.F=this.Y.slice(0),this.A=[],this.l=0,this},update:function(t){typeof t=="string"&&(t=f.codec.utf8String.toBits(t));var e,r=this.A=f.bitArray.concat(this.A,t);if(e=this.l,t=this.l=e+f.bitArray.bitLength(t),9007199254740991e;r++){for(i=!0,n=2;n*n<=r;n++)if(r%n===0){i=!1;break}i&&(8>e&&(this.Y[e]=t(Math.pow(r,.5))),this.b[e]=t(Math.pow(r,1/3)),e++)}}};function gt(t,e){var r,n,i,o=t.F,s=t.b,a=o[0],c=o[1],u=o[2],h=o[3],l=o[4],p=o[5],v=o[6],m=o[7];for(r=0;64>r;r++)16>r?n=e[r]:(n=e[r+1&15],i=e[r+14&15],n=e[r&15]=(n>>>7^n>>>18^n>>>3^n<<25^n<<14)+(i>>>17^i>>>19^i>>>10^i<<15^i<<13)+e[r&15]+e[r+9&15]|0),n=n+m+(l>>>6^l>>>11^l>>>25^l<<26^l<<21^l<<7)+(v^l&(p^v))+s[r],m=v,v=p,p=l,l=h+n|0,h=u,u=c,c=a,a=n+(c&u^h&(c^u))+(c>>>2^c>>>13^c>>>22^c<<30^c<<19^c<<10)|0;o[0]=o[0]+a|0,o[1]=o[1]+c|0,o[2]=o[2]+u|0,o[3]=o[3]+h|0,o[4]=o[4]+l|0,o[5]=o[5]+p|0,o[6]=o[6]+v|0,o[7]=o[7]+m|0}f.mode.ccm={name:"ccm",G:[],listenProgress:function(t){f.mode.ccm.G.push(t)},unListenProgress:function(t){t=f.mode.ccm.G.indexOf(t),-1c)throw new f.exception.invalid("ccm: iv must be at least 7 bytes");for(o=2;4>o&&u>>>8*o;o++);return o<15-c&&(o=15-c),r=a.clamp(r,8*(15-o)),e=f.mode.ccm.V(t,e,r,n,i,o),s=f.mode.ccm.C(t,s,r,e,i,o),a.concat(s.data,s.tag)},decrypt:function(t,e,r,n,i){i=i||64,n=n||[];var o=f.bitArray,s=o.bitLength(r)/8,u=o.bitLength(e),a=o.clamp(e,u-i),c=o.bitSlice(e,u-i),u=(u-i)/8;if(7>s)throw new f.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=o.clamp(r,8*(15-e)),a=f.mode.ccm.C(t,a,r,c,i,e),t=f.mode.ccm.V(t,a.data,r,n,i,e),!o.equal(a.tag,t))throw new f.exception.corrupt("ccm: tag doesn't match");return a.data},na:function(t,e,r,n,i,o){var s=[],a=f.bitArray,c=a.i;if(n=[a.partial(8,(e.length?64:0)|n-2<<2|o-1)],n=a.concat(n,r),n[3]|=i,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;ei||16h&&(f.mode.ccm.fa(s/c),h+=l),r[3]++,i=t.encrypt(r),e[s]^=i[0],e[s+1]^=i[1],e[s+2]^=i[2],e[s+3]^=i[3];return{tag:n,data:a.clamp(e,u)}}};f.mode.ocb2={name:"ocb2",encrypt:function(t,e,r,n,i,o){if(f.bitArray.bitLength(r)!==128)throw new f.exception.invalid("ocb iv must be 128 bits");var s,a=f.mode.ocb2.S,c=f.bitArray,u=c.i,h=[0,0,0,0];r=a(t.encrypt(r));var l,p=[];for(n=n||[],i=i||64,s=0;s+4i.bitLength(r)&&(a=o(a,n(a)),r=i.concat(r,[-2147483648,0,0,0])),s=o(s,r),t.encrypt(o(n(o(a,n(a))),s))},S:function(t){return[t[0]<<1^t[1]>>>31,t[1]<<1^t[2]>>>31,t[2]<<1^t[3]>>>31,t[3]<<1^135*(t[0]>>>31)]}};f.mode.gcm={name:"gcm",encrypt:function(t,e,r,n,i){var o=e.slice(0);return e=f.bitArray,n=n||[],t=f.mode.gcm.C(!0,t,o,n,r,i||128),e.concat(t.data,t.tag)},decrypt:function(t,e,r,n,i){var o=e.slice(0),s=f.bitArray,a=s.bitLength(o);if(i=i||128,n=n||[],i<=a?(e=s.bitSlice(o,a-i),o=s.bitSlice(o,0,a-i)):(e=o,o=[]),t=f.mode.gcm.C(!1,t,o,n,r,i),!s.equal(t.tag,e))throw new f.exception.corrupt("gcm: tag doesn't match");return t.data},ka:function(t,e){var r,n,i,o,s,a=f.bitArray.i;for(i=[0,0,0,0],o=e.slice(0),r=0;128>r;r++){for((n=(t[Math.floor(r/32)]&1<<31-r%32)!==0)&&(i=a(i,o)),s=(o[3]&1)!==0,n=3;0>>1|(o[n-1]&1)<<31;o[0]>>>=1,s&&(o[0]^=-520093696)}return i},j:function(t,e,r){var n,i=r.length;for(e=e.slice(0),n=0;ni&&(t=e.hash(t)),n=0;nn||0>r)throw new f.exception.invalid("invalid params to pbkdf2");typeof t=="string"&&(t=f.codec.utf8String.toBits(t)),typeof e=="string"&&(e=f.codec.utf8String.toBits(e)),i=i||f.misc.hmac,t=new i(t);var o,s,a,c,u=[],h=f.bitArray;for(c=1;32*u.length<(n||1);c++){for(i=o=t.encrypt(h.concat(e,[c])),s=1;ss;s++)i.push(4294967296*Math.random()|0);for(s=0;s=1<this.o&&(this.o=o),this.P++,this.b=f.hash.sha256.hash(this.b.concat(i)),this.L=new f.cipher.aes(this.b),n=0;4>n&&(this.h[n]=this.h[n]+1|0,!this.h[n]);n++);}for(n=0;n>>1;this.c[s].update([n,this.N++,2,e,o,t.length].concat(t))}break;case"string":e===void 0&&(e=t.length),this.c[s].update([n,this.N++,3,e,o,t.length]),this.c[s].update(t);break;default:c=1}if(c)throw new f.exception.bug("random: addEntropy only supports number, array of numbers or string");this.m[s]+=e,this.f+=e,a===this.u&&(this.isReady()!==this.u&&ir("seeded",Math.max(this.o,this.f)),ir("progress",this.getProgress()))},isReady:function(t){return t=this.T[t!==void 0?t:this.M],this.o&&this.o>=t?this.m[0]>this.ba&&new Date().valueOf()>this.Z?this.J|this.I:this.I:this.f>=t?this.J|this.u:this.u},getProgress:function(t){return t=this.T[t||this.M],this.o>=t||this.f>t?1:this.f/t},startCollectors:function(){if(!this.D){if(this.a={loadTimeCollector:ze(this,this.ma),mouseCollector:ze(this,this.oa),keyboardCollector:ze(this,this.la),accelerometerCollector:ze(this,this.ea),touchCollector:ze(this,this.qa)},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 f.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.K[t][this.ga++]=e},removeEventListener:function(t,e){var r,n,i=this.K[t],o=[];for(n in i)i.hasOwnProperty(n)&&i[n]===e&&o.push(n);for(r=0;re&&(t.h[e]=t.h[e]+1|0,!t.h[e]);e++);return t.L.encrypt(t.h)}function ze(t,e){return function(){e.apply(t,arguments)}}f.random=new f.prng(6);e:try{if(Xe=typeof De<"u"&&De.exports){try{Qe=Gr("crypto")}catch{Qe=null}Xe=Ye=Qe}if(Xe&&Ye.randomBytes)Fe=Ye.randomBytes(128),Fe=new Uint32Array(new Uint8Array(Fe).buffer),f.random.addEntropy(Fe,1024,"crypto['randomBytes']");else if(typeof window<"u"&&typeof Uint32Array<"u"){if(Be=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(Be);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(Be);else break e;f.random.addEntropy(Be,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 Fe,Ye,Be,Xe,Qe;f.json={defaults:{v:1,iter:1e4,ks:128,ts:64,mode:"ccm",adata:"",cipher:"aes"},ja:function(t,e,r,n){r=r||{},n=n||{};var i=f.json,o=i.g({iv:f.random.randomWords(4,0)},i.defaults),s;if(i.g(o,r),r=o.adata,typeof o.salt=="string"&&(o.salt=f.codec.base64.toBits(o.salt)),typeof o.iv=="string"&&(o.iv=f.codec.base64.toBits(o.iv)),!f.mode[o.mode]||!f.cipher[o.cipher]||typeof t=="string"&&100>=o.iter||o.ts!==64&&o.ts!==96&&o.ts!==128||o.ks!==128&&o.ks!==192&&o.ks!==256||2>o.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||4Tr,cancel:()=>kn,compress:()=>Ir,decompress:()=>Mn,download:()=>Un,events:()=>Tt,getFileIndexInQueue:()=>jn,infos:()=>Rn,pause:()=>Tn,remove:()=>In,resume:()=>zn,upload:()=>Bn});var Rr=lt(vt());var Xr={withStackTrace:!1},$t=(t,e,r=Xr)=>{let n=e.isOk()?{type:"Ok",value:e.value}:{type:"Err",value:e.error},i=r.withStackTrace?new Error().stack:void 0;return{data:n,message:t,stack:i}};function Ae(t,e,r,n){function i(o){return o instanceof r?o:new r(function(s){s(o)})}return new(r||(r=Promise))(function(o,s){function a(h){try{u(n.next(h))}catch(l){s(l)}}function c(h){try{u(n.throw(h))}catch(l){s(l)}}function u(h){h.done?o(h.value):i(h.value).then(a,c)}u((n=n.apply(t,[])).next())})}function Wt(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 me(t){return this instanceof me?(this.v=t,this):new me(t)}function Qr(t,e,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=r.apply(t,e||[]),i,o=[];return i={},s("next"),s("throw"),s("return"),i[Symbol.asyncIterator]=function(){return this},i;function s(p){n[p]&&(i[p]=function(v){return new Promise(function(m,w){o.push([p,v,m,w])>1||a(p,v)})})}function a(p,v){try{c(n[p](v))}catch(m){l(o[0][3],m)}}function c(p){p.value instanceof me?Promise.resolve(p.value.v).then(u,h):l(o[0][2],p)}function u(p){a("next",p)}function h(p){a("throw",p)}function l(p,v){p(v),o.shift(),o.length&&a(o[0][0],o[0][1])}}function en(t){var e,r;return e={},n("next"),n("throw",function(i){throw i}),n("return"),e[Symbol.iterator]=function(){return this},e;function n(i,o){e[i]=t[i]?function(s){return(r=!r)?{value:me(t[i](s)),done:i==="return"}:o?o(s):s}:o}}function tn(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 Wt=="function"?Wt(t):t[Symbol.iterator](),r={},n("next"),n("throw"),n("return"),r[Symbol.asyncIterator]=function(){return this},r);function n(o){r[o]=t[o]&&function(s){return new Promise(function(a,c){s=t[o](s),i(a,c,s.done,s.value)})}}function i(o,s,a,c){Promise.resolve(c).then(function(u){o({value:u,done:a})},s)}}var b=class t{constructor(e){this._promise=e}static fromSafePromise(e){let r=e.then(n=>new Y(n));return new t(r)}static fromPromise(e,r){let n=e.then(i=>new Y(i)).catch(i=>new X(r(i)));return new t(n)}static fromThrowable(e,r){return(...n)=>new t(Ae(this,void 0,void 0,function*(){try{return new Y(yield e(...n))}catch(i){return new X(r?r(i):i)}}))}static combine(e){return rn(e)}static combineWithAllErrors(e){return nn(e)}map(e){return new t(this._promise.then(r=>Ae(this,void 0,void 0,function*(){return r.isErr()?new X(r.error):new Y(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 X(r.error);let n=yield e(r.value);return n.isErr()?new X(n.error):new Y(r.value)})))}andTee(e){return new t(this._promise.then(r=>Ae(this,void 0,void 0,function*(){if(r.isErr())return new X(r.error);try{yield e(r.value)}catch{}return new Y(r.value)})))}mapErr(e){return new t(this._promise.then(r=>Ae(this,void 0,void 0,function*(){return r.isOk()?new Y(r.value):new X(yield e(r.error))})))}andThen(e){return new t(this._promise.then(r=>{if(r.isErr())return new X(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 Y(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 Qr(this,arguments,function*(){return yield me(yield me(yield*en(tn(yield me(this._promise.then(r=>r.safeUnwrap()))))))})}then(e,r){return this._promise.then(e,r)}},G=t=>new b(Promise.resolve(new Y(t))),Z=t=>new b(Promise.resolve(new X(t))),Gn=b.fromPromise,qn=b.fromSafePromise,Zn=b.fromThrowable,Kt=t=>{let e=se([]);for(let r of t)if(r.isErr()){e=Q(r.error);break}else e.map(n=>n.push(r.value));return e},rn=t=>b.fromSafePromise(Promise.all(t)).andThen(Kt),Vt=t=>{let e=se([]);for(let r of t)r.isErr()&&e.isErr()?e.error.push(r.error):r.isErr()&&e.isOk()?e=Q([r.error]):r.isOk()&&e.isOk()&&e.value.push(r.value);return e},nn=t=>b.fromSafePromise(Promise.all(t)).andThen(Vt),mt;(function(t){function e(i,o){return(...s)=>{try{let a=i(...s);return se(a)}catch(a){return Q(o?o(a):a)}}}t.fromThrowable=e;function r(i){return Kt(i)}t.combine=r;function n(i){return Vt(i)}t.combineWithAllErrors=n})(mt||(mt={}));var se=t=>new Y(t);function Q(t){return new X(t)}var Y=class{constructor(e){this.value=e}isOk(){return!0}isErr(){return!this.isOk()}map(e){return se(e(this.value))}mapErr(e){return se(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 se(this.value)}orElse(e){return se(this.value)}asyncAndThen(e){return e(this.value)}asyncAndThrough(e){return e(this.value).map(()=>this.value)}asyncMap(e){return b.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 $t("Called `_unsafeUnwrapErr` on an Ok",this,e)}},X=class{constructor(e){this.error=e}isOk(){return!1}isErr(){return!this.isOk()}map(e){return Q(this.error)}mapErr(e){return Q(e(this.error))}andThrough(e){return Q(this.error)}andTee(e){return Q(this.error)}andThen(e){return Q(this.error)}orElse(e){return e(this.error)}asyncAndThen(e){return Z(this.error)}asyncAndThrough(e){return Z(this.error)}asyncMap(e){return Z(this.error)}unwrapOr(e){return e}match(e,r){return r(this.error)}safeUnwrap(){let e=this.error;return function*(){throw yield Q(e),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(e){throw $t("Called `_unsafeUnwrap` on an Err",this,e)}_unsafeUnwrapErr(e){return this.error}},Hn=mt.fromThrowable;var ne=class t{constructor(e,r){d(this,"actionToken","");d(this,"chunksReady",0);d(this,"createdAt",0);d(this,"delay",0);d(this,"delAtFirstView",!1);d(this,"keys",{client:"",server:""});d(this,"name","");d(this,"password","");d(this,"queueIndex",0);d(this,"serverUrl");d(this,"size",0);d(this,"uploadStatus",3);d(this,"totalChunks",0);d(this,"type","");d(this,"zipped",!1);this.serverUrl=e,Object.assign(this,r)}downloadUrl(){let e=new URL(this.serverUrl);return new URL(`${e.origin+e.pathname}r/${this.keys.server}#${this.keys.client}`)}removeUrl(){let e=new URL(this.serverUrl);return new URL(`${e.origin+e.pathname}d/${this.keys.server}/${this.actionToken}`)}static fromDownloadUrl(e,r=""){let n=e.pathname.split("r/"),i={client:e.hash.slice(1).split("&")[0],server:n[1]};return new t(e.origin+n[0],{keys:i,password:r})}static fromRemoveUrl(e,r=""){let n=e.pathname.split("d/"),i=n[1].split("/"),o={client:"",server:i[0]};return new t(e.origin+n[0],{keys:o,password:r,actionToken:i[1]})}};var er=lt(vt());var ae=class extends Error{constructor(r,n={}){let{cause:i,context:o}=n;super(r,{cause:i});d(this,"context");this.name=this.constructor.name,this.context=o}};var $e=class extends ae{constructor(){super(...arguments);d(this,"message","Unable to connect. Is the computer able to access the url?")}};var Ke=class extends ae{constructor(){super(...arguments);d(this,"message","The server returned an error")}};var R=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)},yt=t=>{let e=t.href.match(/(.*?)\/?(?:\/[dr]{1}|login\/?|files\/?)/),r=e&&e[1]?e[1]:t.origin;return b.fromPromise(fetch(r+"/about/config"),n=>new $e(void 0,{cause:R(n)})).andThen(n=>n.ok?b.fromPromise(n.json(),i=>R(i)):Z(new Ke(void 0,{context:n.statusText})))},Xt=()=>typeof Deno<"u",on=()=>Xt()||typeof window<"u"&&(window.isSecureContext||window.location.protocol==="https:"),Qt=t=>Xt()?new URL(`./worker/${t}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${t==="main"?`worker/${t}`:t}.js`)),Ve=async t=>t?Array.from(new Uint8Array(await crypto.subtle.digest("SHA-512",new TextEncoder().encode(t)))).map(e=>e.toString(16).padStart(2,"0")).join(""):"";var ve=class{constructor(e){d(this,"events",new er.default);d(this,"lufiFile");d(this,"status",2);d(this,"tmpFile");d(this,"tmpChunks",[]);d(this,"worker");d(this,"isTerminated",!1);d(this,"complete",()=>{this.status=0,this.events.emit("JOB_TERMINATED")});d(this,"hasFailed",()=>this.status===1);d(this,"onError",e=>(this.worker.onerror=r=>{e(r)},this));d(this,"onMessage",e=>(this.worker.onmessage=r=>{e&&e(r);let n=r.data.event;n&&(n==="FILE_UPDATED"?Object.assign(this.lufiFile,r.data.lufiFile):this.dispatchEvent(n,r.data.error))},this));d(this,"onMessageError",e=>(this.worker.onmessageerror=r=>{e(r)},this));d(this,"onProgress",e=>(this.events.on("CHUNK_UPLOADED",()=>{e()}),this.events.on("CHUNK_DOWNLOADED",()=>{e()}),this));d(this,"requestMessage",(e,r=[])=>(this.worker.postMessage(e,r),this));d(this,"terminate",()=>(this.worker.terminate(),this));d(this,"waitForCompletion",()=>this.isTerminated?this.status===0?G(this):Z(R("Job has failed")):b.fromPromise(new Promise((e,r)=>{this.events.once("OPERATION_FAILED",n=>{r(n)}),this.events.once("JOB_TERMINATED",()=>{this.status===0&&e(this)})}),e=>R(e)));d(this,"dispatchEvent",(e,r)=>{this.events.emit(e,r)});this.worker=new Worker(Qt("main"),{type:"module"}),this.lufiFile=e,this.events.once("JOB_TERMINATED",()=>{this.isTerminated=!0,this.terminate()}),this.events.once("OPERATION_FAILED",r=>{this.status=1,this.lufiFile.uploadStatus=2,this.events.emit("JOB_TERMINATED",r)}),this.onError(r=>console.error(r.error))}};var Le=(r=>(r[r.Sjcl=0]="Sjcl",r[r.WebCrypto=1]="WebCrypto",r))(Le||{});var be=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),i="";for(let o=0;o>2]+this._charset[(n[o]&3)<<4|n[o+1]>>4]+this._charset[(n[o+1]&15)<<2|n[o+2]>>6]+this._charset[n[o+2]&63];return r%3==2?(i=i.substring(0,i.length-1),this._noPadding||(i+="=")):r%3==1&&(i=i.substring(0,i.length-2),this._noPadding||(i+="==")),i}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),i,o,s,a,c=0,u=0;for(;c>4,n[c++]=(o&15)<<4|s>>2,n[c++]=(s&3)<<6|a;return n.buffer}};var Li=new be("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");var fn=new be("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",!0);function dt(t){return fn.Encode(t)}var Et=lt(sr());var he=class extends ae{};var Ce=class extends he{constructor(){super(...arguments);d(this,"message","Unable to decrypt the provided data")}};var ar=()=>{try{return G(Et.default.codec.base64.fromBits(Et.default.random.randomWords(8,10)))}catch(t){return Z(new he("Unable to generate a random key",{cause:R(t)}))}};var fr=()=>b.fromPromise(new Promise(t=>crypto.subtle.generateKey({name:"AES-GCM",length:256},!0,["encrypt","decrypt"]).then(e=>crypto.subtle.exportKey("raw",e).then(r=>t(dt(r))).catch(r=>Z(new Ce(void 0,{cause:R(r)})))).catch(e=>Z(new Ce(void 0,{cause:R(e)})))),t=>new he("Unable to base64 encode the url",{cause:R(t)}));var cr=(t=1)=>t===0?ar():fr();var et=class extends ae{constructor(){super(...arguments);d(this,"message","An error occured while dealing with a file")}};var tt=class extends et{constructor(){super(...arguments);d(this,"message","An error occured while operating on a file")}};var rt=class extends tt{constructor(){super(...arguments);d(this,"message","An error occured while slicing a file")}};var ur={},pn=function(t,e,r,n,i){var o=new Worker(ur[e]||(ur[e]=URL.createObjectURL(new Blob([t+';addEventListener("error",function(e){e=e.error;postMessage({$e$:[e.message,e.code,e.stack]})})'],{type:"text/javascript"}))));return o.onmessage=function(s){var a=s.data,c=a.$e$;if(c){var u=new Error(c[0]);u.code=c[1],u.stack=c[2],i(u,null)}else i(null,a)},o.postMessage(r,n),o},S=Uint8Array,H=Uint16Array,Ne=Int32Array,ke=new S([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),Me=new S([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),_e=new S([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),mr=function(t,e){for(var r=new H(31),n=0;n<31;++n)r[n]=e+=1<>1|(D&21845)<<1,le=(le&52428)>>2|(le&13107)<<2,le=(le&61680)>>4|(le&3855)<<4,je[D]=((le&65280)>>8|(le&255)<<8)>>1;var le,D,te=function(t,e,r){for(var n=t.length,i=0,o=new H(e);i>c]=u}else for(a=new H(n),i=0;i>15-t[i]);return a},pe=new S(288);for(D=0;D<144;++D)pe[D]=8;var D;for(D=144;D<256;++D)pe[D]=9;var D;for(D=256;D<280;++D)pe[D]=7;var D;for(D=280;D<288;++D)pe[D]=8;var D,Se=new S(32);for(D=0;D<32;++D)Se[D]=5;var D,wr=te(pe,9,0),Er=te(pe,9,1),xr=te(Se,5,0),Ar=te(Se,5,1),it=function(t){for(var e=t[0],r=1;re&&(e=t[r]);return e},ee=function(t,e,r){var n=e/8|0;return(t[n]|t[n+1]<<8)>>(e&7)&r},ot=function(t,e){var r=e/8|0;return(t[r]|t[r+1]<<8|t[r+2]<<16)>>(e&7)},Je=function(t){return(t+7)/8|0},ye=function(t,e,r){return(e==null||e<0)&&(e=0),(r==null||r>t.length)&&(r=t.length),new S(t.subarray(e,r))};var Lr=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],_=function(t,e,r){var n=new Error(e||Lr[t]);if(n.code=t,Error.captureStackTrace&&Error.captureStackTrace(n,_),!r)throw n;return n},br=function(t,e,r,n){var i=t.length,o=n?n.length:0;if(!i||e.f&&!e.l)return r||new S(0);var s=!r,a=s||e.i!=2,c=e.i;s&&(r=new S(i*3));var u=function(Re){var Te=r.length;if(Re>Te){var Ee=new S(Math.max(Te*2,Re));Ee.set(r),r=Ee}},h=e.f||0,l=e.p||0,p=e.b||0,v=e.l,m=e.d,w=e.m,g=e.n,A=i*8;do{if(!v){h=ee(t,l,1);var T=ee(t,l+1,3);if(l+=3,T)if(T==1)v=Er,m=Ar,w=9,g=5;else if(T==2){var I=ee(t,l,31)+257,k=ee(t,l+10,15)+4,x=I+ee(t,l+5,31)+1;l+=14;for(var y=new S(x),M=new S(19),O=0;O>4;if(L<16)y[O++]=L;else{var B=0,U=0;for(L==16?(U=3+ee(t,l,3),l+=2,B=y[O-1]):L==17?(U=3+ee(t,l,7),l+=3):L==18&&(U=11+ee(t,l,127),l+=7);U--;)y[O++]=B}}var W=y.subarray(0,I),J=y.subarray(I);w=it(W),g=it(J),v=te(W,w,1),m=te(J,g,1)}else _(1);else{var L=Je(l)+4,E=t[L-4]|t[L-3]<<8,P=L+E;if(P>i){c&&_(0);break}a&&u(p+E),r.set(t.subarray(L,P),p),e.b=p+=E,e.p=l=P*8,e.f=h;continue}if(l>A){c&&_(0);break}}a&&u(p+131072);for(var Ue=(1<>4;if(l+=B&15,l>A){c&&_(0);break}if(B||_(2),$<256)r[p++]=$;else if($==256){ue=l,v=null;break}else{var K=$-254;if($>264){var O=$-257,F=ke[O];K=ee(t,l,(1<>4;oe||_(3),l+=oe&15;var J=gr[ge];if(ge>3){var F=Me[ge];J+=ot(t,l)&(1<A){c&&_(0);break}a&&u(p+131072);var we=p+K;if(p>8},Oe=function(t,e,r){r<<=e&7;var n=e/8|0;t[n]|=r,t[n+1]|=r>>8,t[n+2]|=r>>16},st=function(t,e){for(var r=[],n=0;np&&(p=o[n].s);var v=new H(p+1),m=ft(r[h-1],v,0);if(m>e){var n=0,w=0,g=m-e,A=1<e)w+=A-(1<>=g;w>0;){var L=o[n].s;v[L]=0&&w;--n){var E=o[n].s;v[E]==e&&(--v[E],++w)}m=e}return{t:new S(v),l:m}},ft=function(t,e,r){return t.s==-1?Math.max(ft(t.l,e,r+1),ft(t.r,e,r+1)):e[t.s]=r},Lt=function(t){for(var e=t.length;e&&!t[--e];);for(var r=new H(++e),n=0,i=t[0],o=1,s=function(c){r[n++]=c},a=1;a<=e;++a)if(t[a]==i&&a!=e)++o;else{if(!i&&o>2){for(;o>138;o-=138)s(32754);o>2&&(s(o>10?o-11<<5|28690:o-3<<5|12305),o=0)}else if(o>3){for(s(i),--o;o>6;o-=6)s(8304);o>2&&(s(o-3<<5|8208),o=0)}for(;o--;)s(i);o=1,i=t[a]}return{c:r.subarray(0,n),n:e}},Pe=function(t,e){for(var r=0,n=0;n>8,t[i+2]=t[i]^255,t[i+3]=t[i+1]^255;for(var o=0;o4&&!M[_e[z-1]];--z);var re=u+5<<3,j=Pe(i,pe)+Pe(o,Se)+s,N=Pe(i,p)+Pe(o,w)+s+14+3*z+Pe(k,M)+2*k[16]+3*k[17]+7*k[18];if(c>=0&&re<=j&&re<=N)return Pt(e,h,t.subarray(c,c+u));var B,U,W,J;if(fe(e,h,1+(N15&&(fe(e,h,$[x]>>5&127),h+=$[x]>>12)}}else B=wr,U=pe,W=xr,J=Se;for(var x=0;x255){var K=F>>18&31;Oe(e,h,B[K+257]),h+=U[K+257],K>7&&(fe(e,h,F>>23&31),h+=ke[K]);var oe=F&31;Oe(e,h,W[oe]),h+=J[oe],oe>3&&(Oe(e,h,F>>5&8191),h+=Me[oe])}else Oe(e,h,B[F]),h+=U[F]}return Oe(e,h,B[256]),h+U[256]},Dr=new Ne([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),St=new S(0),Cr=function(t,e,r,n,i,o){var s=o.z||t.length,a=new S(n+s+5*(1+Math.ceil(s/7e3))+i),c=a.subarray(n,a.length-i),u=o.l,h=(o.r||0)&7;if(e){h&&(c[0]=o.r>>3);for(var l=Dr[e-1],p=l>>13,v=l&8191,m=(1<7e3||M>24576)&&(B>423||!u)){h=bt(t,c,0,E,P,I,x,M,z,y-z,h),M=k=x=0,z=y;for(var U=0;U<286;++U)P[U]=0;for(var U=0;U<30;++U)I[U]=0}var W=2,J=0,Ue=v,V=j-N&32767;if(B>2&&re==L(y-V))for(var ue=Math.min(p,B)-1,$=Math.min(32767,y),K=Math.min(258,B);V<=$&&--Ue&&j!=N;){if(t[y+W]==t[y+W-V]){for(var F=0;FW){if(W=F,J=V,F>ue)break;for(var oe=Math.min(V,F-2),ge=0,U=0;Uge&&(ge=qe,N=we)}}}j=N,N=w[j],V+=j-N&32767}if(J){E[M++]=268435456|at[W]<<18|At[J];var Re=at[W]&31,Te=At[J]&31;x+=ke[Re]+Me[Te],++P[257+Re],++I[Te],O=y+W,++k}else E[M++]=t[y],++P[t[y]]}}for(y=Math.max(y,O);y=s&&(c[h/8|0]=u,Ee=s),h=Pt(c,h+1,t.subarray(y,Ee))}o.i=s}return ye(a,0,n+Je(h)+i)},vn=function(){for(var t=new Int32Array(256),e=0;e<256;++e){for(var r=e,n=9;--n;)r=(r&1&&-306674912)^r>>>1;t[e]=r}return t}(),mn=function(){var t=-1;return{p:function(e){for(var r=t,n=0;n>>8;t=r},d:function(){return~t}}};var Or=function(t,e,r,n,i){if(!i&&(i={l:1},e.dictionary)){var o=e.dictionary.subarray(-32768),s=new S(o.length+t.length);s.set(o),s.set(t,o.length),t=s,i.w=o.length}return Cr(t,e.level==null?6:e.level,e.mem==null?i.l?Math.ceil(Math.max(8,Math.min(13,Math.log(t.length)))*1.5):20:12+e.mem,r,n,i)},kt=function(t,e){var r={};for(var n in t)r[n]=t[n];for(var n in e)r[n]=e[n];return r},hr=function(t,e,r){for(var n=t(),i=t.toString(),o=i.slice(i.indexOf("[")+1,i.lastIndexOf("]")).replace(/\s+/g,"").split(","),s=0;s>>0},xt=function(t,e){return ie(t,e)+ie(t,e+4)*4294967296},q=function(t,e,r){for(;r;++e)t[e]=r,r>>>=8};function En(t,e,r){return r||(r=e,e={}),typeof r!="function"&&_(7),Sr(t,e,[wn],function(n){return ut(Mt(n.data[0],n.data[1]))},0,r)}function Mt(t,e){return Or(t,e||{},0,0)}function xn(t,e,r){return r||(r=e,e={}),typeof r!="function"&&_(7),Sr(t,e,[gn],function(n){return ut(Ut(n.data[0],Pr(n.data[1])))},1,r)}function Ut(t,e){return br(t,{i:2},e&&e.out,e&&e.dictionary)}var kr=function(t,e,r,n){for(var i in t){var o=t[i],s=e+i,a=n;Array.isArray(o)&&(a=kt(n,o[1]),o=o[0]),o instanceof S?r[s]=[o,a]:(r[s+="/"]=[new S(0),a],kr(o,s,r,n))}},lr=typeof TextEncoder<"u"&&new TextEncoder,Dt=typeof TextDecoder<"u"&&new TextDecoder,An=0;try{Dt.decode(St,{stream:!0}),An=1}catch{}var Ln=function(t){for(var e="",r=0;;){var n=t[r++],i=(n>127)+(n>223)+(n>239);if(r+i>t.length)return{s:e,r:ye(t,r-1)};i?i==3?(n=((n&15)<<18|(t[r++]&63)<<12|(t[r++]&63)<<6|t[r++]&63)-65536,e+=String.fromCharCode(55296|n>>10,56320|n&1023)):i&1?e+=String.fromCharCode((n&31)<<6|t[r++]&63):e+=String.fromCharCode((n&15)<<12|(t[r++]&63)<<6|t[r++]&63):e+=String.fromCharCode(n)}};function pr(t,e){if(e){for(var r=new S(t.length),n=0;n>1)),s=0,a=function(h){o[s++]=h},n=0;no.length){var c=new S(s+8+(i-n<<1));c.set(o),o=c}var u=t.charCodeAt(n);u<128||e?a(u):u<2048?(a(192|u>>6),a(128|u&63)):u>55295&&u<57344?(u=65536+(u&1047552)|t.charCodeAt(++n)&1023,a(240|u>>18),a(128|u>>12&63),a(128|u>>6&63),a(128|u&63)):(a(224|u>>12),a(128|u>>6&63),a(128|u&63))}return ye(o,0,s)}function bn(t,e){if(e){for(var r="",n=0;n65535&&_(9),e+=n+4}return e},vr=function(t,e,r,n,i,o,s,a){var c=n.length,u=r.extra,h=a&&a.length,l=Ct(u);q(t,e,s!=null?33639248:67324752),e+=4,s!=null&&(t[e++]=20,t[e++]=r.os),t[e]=20,e+=2,t[e++]=r.flag<<1|(o<0&&8),t[e++]=i&&8,t[e++]=r.compression&255,t[e++]=r.compression>>8;var p=new Date(r.mtime==null?Date.now():r.mtime),v=p.getFullYear()-1980;if((v<0||v>119)&&_(10),q(t,e,v<<25|p.getMonth()+1<<21|p.getDate()<<16|p.getHours()<<11|p.getMinutes()<<5|p.getSeconds()>>1),e+=4,o!=-1&&(q(t,e,r.crc),q(t,e+4,o<0?-o-2:o),q(t,e+8,r.size)),q(t,e+12,c),q(t,e+14,l),e+=16,s!=null&&(q(t,e,h),q(t,e+6,r.attrs),q(t,e+10,s),e+=14),t.set(n,e),e+=c,l)for(var m in u){var w=u[m],g=w.length;q(t,e,+m),q(t,e+2,g),t.set(w,e+4),e+=4+g}return h&&(t.set(a,e),e+=h),e},Pn=function(t,e,r,n,i){q(t,e,101010256),q(t,e+8,r),q(t,e+10,r),q(t,e+12,n),q(t,e+16,i)};function Mr(t,e,r){r||(r=e,e={}),typeof r!="function"&&_(7);var n={};kr(t,"",n,e);var i=Object.keys(n),o=i.length,s=0,a=0,c=o,u=new Array(o),h=[],l=function(){for(var g=0;g65535&&j(_(11,0,1),null),!re)j(null,L);else if(I<16e4)try{j(null,Mt(L,E))}catch(N){j(N,null)}else h.push(En(L,E,j))},w=0;w65558)return s(_(13,0,1),null),i;var c=ce(t,a+8);if(c){var u=c,h=ie(t,a+16),l=h==4294967295||u==65535;if(l){var p=ie(t,a-12);l=ie(t,p)==101075792,l&&(u=c=ie(t,p+32),h=ie(t,p+48))}for(var v=e&&e.filter,m=function(g){var A=Cn(t,h,l),T=A[0],L=A[1],E=A[2],P=A[3],I=A[4],k=A[5],x=Dn(t,k);h=I;var y=function(O,z){O?(i(),s(O,null)):(z&&(o[P]=z),--c||s(null,o))};if(!v||v({name:P,size:L,originalSize:E,compression:T}))if(!T)y(null,ye(t,x,x+L));else if(T==8){var M=t.subarray(x,x+L);if(E<524288||L>.8*E)try{y(null,Ut(M,{out:new S(E)}))}catch(O){y(O,null)}else n.push(xn(M,{size:E},y))}else y(_(14,"unknown compression type "+T,1),null);else y(null,null)},w=0;w{t.terminate();let e=new ve(t.lufiFile);return b.fromPromise(new Promise((r,n)=>{e.onMessage(i=>{i.data.event==="UPLOAD_CANCELLED"&&(de[e.lufiFile.keys.client].uploadStatus=0,r(e)),i.data.event==="OPERATION_FAILED"&&n(i.data.error)}).requestMessage({action:2,args:{lufiFile:e.lufiFile}})}),r=>R(r))},Tr=(t,e={})=>{let r=async n=>{var i;for(let o of n){let s=((i=o.name.split("/"))==null?void 0:i.pop())||o.name,a=s.split(".").shift(),c=s.split(".").pop(),u=s;if(e[u]!==void 0){let h=1;do u=`${a}_(${h}).${c}`,h++;while(e[u]!==void 0)}Tt.emit("ARCHIVE_ADDED_FILE",{name:u,size:o.size}),e[u]=await o.bytes()}};return b.fromPromise(r(t),n=>R(n)).andThen(()=>G(e))},Ir=(t,e)=>{let r=()=>new Promise((n,i)=>{Mr(t,(o,s)=>{o&&i(o),n(s)})});return b.fromPromise(r(),n=>R(n)).andThen(n=>G(new File([new Blob([n])],e,{type:"application/zip"}))).orElse(n=>Z(n))},Mn=t=>{let e=async()=>{let r=await t.bytes();return new Promise((n,i)=>{Ur(r,(o,s)=>{o&&i(o),n(s)})})};return b.fromPromise(e(),r=>R(r)).andThen(r=>{let n=[];for(let i in r)n.push(new File([new Blob([r[i]])],i));return G(n)})},Un=(t,e)=>{let r;return e?r=yt(t).andThen(n=>n.version.tag>"0.07.0"?b.fromPromise(Ve(e).then(i=>ne.fromDownloadUrl(t,i)),i=>R(i)):G(ne.fromDownloadUrl(t,e))):r=G(ne.fromDownloadUrl(t)),r.andThen(n=>{let i=new ve(n);return b.fromPromise(new Promise((o,s)=>i.onMessage(a=>{zr(o,s,i,a),a.data.event==="CHUNK_DOWNLOADED"&&(i.tmpChunks[a.data.chunk.index]=new Blob([a.data.chunk.buffer])),a.data.event==="DOWNLOAD_COMPLETE"&&(i.tmpFile=new Blob(i.tmpChunks,{type:n.type}),i.tmpChunks=[],i.complete())}).requestMessage({action:3,args:{lufiFile:n}})),o=>R(o))})},Rn=(t,e)=>{let r;return e?r=yt(t).andThen(n=>n.version.tag>"0.07.0"?b.fromPromise(Ve(e).then(i=>ne.fromDownloadUrl(t,i)),i=>R(i)):G(ne.fromDownloadUrl(t,e))):r=G(ne.fromDownloadUrl(t)),r.andThen(n=>G(new ve(n))).andThen(n=>b.fromPromise(new Promise((i,o)=>{n.onMessage(s=>{s.data.event==="INFOS_RETRIEVED"&&(n.complete(),i(n)),s.data.event==="OPERATION_FAILED"&&o(s.data.error)}).requestMessage({action:4,args:{lufiFile:n.lufiFile}})}),i=>R(i)))},Tn=t=>(t.status=3,G(t.requestMessage({action:5,args:{lufiFile:t.lufiFile}}))),In=(t,e)=>{let r=ne.fromRemoveUrl(t,e),n=new ve(r);return b.fromPromise(new Promise((i,o)=>{n.onMessage(s=>{s.data.event==="FILE_REMOVED"&&(n.complete(),i(n)),s.data.event==="OPERATION_FAILED"&&o(s.data.error)}).requestMessage({action:7,args:{lufiFile:r}})}),i=>R(i))},zn=t=>(t.status=2,G(t.requestMessage({action:8,args:{lufiFile:t.lufiFile}}))),Fn=(t,e,r=Sn)=>{let n=Math.ceil(t.size/r);if(de[e].totalChunks=n,n>0){let i=[];for(let o=0;o{let c=[];return i?e.length===1&&e[0].type==="application/zip"?c.push(Rt(t,e[0],r,n,i,s,a)):c.push(Tr(e).andThen(u=>Ir(u,o).andThen(h=>(Tt.emit("ARCHIVE_CREATED",h),Rt(t,h,r,n,i,s,a))))):e.forEach(u=>{c.push(Rt(t,u,r,n,i,s,a))}),b.combine(c)},Rt=(t,e,r,n,i,o,s)=>cr(s).andThen(a=>b.fromPromise(Ve(o).then(c=>(de[a]=new ne(t.toString(),{delay:r,delAtFirstView:n,zipped:i,password:c,name:e.name.split("/").pop(),size:e.size,type:e.type,keys:{client:a,server:""}}),a)),c=>R(c))).andThen(a=>{let c=new ve(de[a]);return Fn(e,a).asyncAndThen(u=>{de[a].uploadStatus=4;let h=new Promise((p,v)=>{c.onMessage(m=>{switch(zr(p,v,c,m),m.data.event){case"UPLOAD_COMPLETE":c.complete(),c.lufiFile.uploadStatus=1;break}})}),l=async p=>{for(let[v,m]of p.entries()){let w=await m.arrayBuffer();c.requestMessage({action:9,args:{chunk:{buffer:w,index:v},lufiFile:de[a],algo:s}},[w])}};return b.fromPromise(l(u),p=>R(p)).andThen(()=>b.fromPromise(h,p=>R(p)))}).orElse(u=>Z(u))}),zr=(t,e,r,n)=>{n.data.event==="SOCKET_OPENED"&&t(r),n.data.event==="OPERATION_FAILED"&&e(n.data.error)},_n=()=>Object.values(de).filter(t=>t.uploadStatus===4),jn=t=>Object.keys(_n()).indexOf(t);export{Le as CryptoAlgorithm,b as ResultAsync,Q as err,Z as errAsync,on as isSecureContext,It as lufi,se as ok,G as okAsync}; +var Br=Object.create;var Ze=Object.defineProperty;var _r=Object.getOwnPropertyDescriptor;var jr=Object.getOwnPropertyNames;var Nr=Object.getPrototypeOf,Jr=Object.prototype.hasOwnProperty;var Gr=(t,e,r)=>e in t?Ze(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var qr=(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 zt=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),Zr=(t,e)=>{for(var r in e)Ze(t,r,{get:e[r],enumerable:!0})},Hr=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of jr(e))!Jr.call(t,i)&&i!==r&&Ze(t,i,{get:()=>e[i],enumerable:!(n=_r(e,i))||n.enumerable});return t};var lt=(t,e,r)=>(r=t!=null?Br(Nr(t)):{},Hr(e||!t||!t.__esModule?Ze(r,"default",{value:t,enumerable:!0}):r,t));var d=(t,e,r)=>Gr(t,typeof e!="symbol"?e+"":e,r);var vt=zt((Jn,pt)=>{"use strict";var xe=typeof Reflect=="object"?Reflect:null,Ft=xe&&typeof xe.apply=="function"?xe.apply:function(e,r,n){return Function.prototype.apply.call(e,r,n)},He;xe&&typeof xe.ownKeys=="function"?He=xe.ownKeys:Object.getOwnPropertySymbols?He=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:He=function(e){return Object.getOwnPropertyNames(e)};function Wr(t){console&&console.warn&&console.warn(t)}var _t=Number.isNaN||function(e){return e!==e};function C(){C.init.call(this)}pt.exports=C;pt.exports.once=Yr;C.EventEmitter=C;C.prototype._events=void 0;C.prototype._eventsCount=0;C.prototype._maxListeners=void 0;var Bt=10;function We(t){if(typeof t!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t)}Object.defineProperty(C,"defaultMaxListeners",{enumerable:!0,get:function(){return Bt},set:function(t){if(typeof t!="number"||t<0||_t(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");Bt=t}});C.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};C.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 jt(t){return t._maxListeners===void 0?C.defaultMaxListeners:t._maxListeners}C.prototype.getMaxListeners=function(){return jt(this)};C.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 c=o[e];if(c===void 0)return!1;if(typeof c=="function")Ft(c,this,r);else for(var u=c.length,h=Zt(c,u),n=0;n0&&s.length>i&&!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,Wr(a)}return t}C.prototype.addListener=function(e,r){return Nt(this,e,r,!1)};C.prototype.on=C.prototype.addListener;C.prototype.prependListener=function(e,r){return Nt(this,e,r,!0)};function $r(){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 Jt(t,e,r){var n={fired:!1,wrapFn:void 0,target:t,type:e,listener:r},i=$r.bind(n);return i.listener=r,n.wrapFn=i,i}C.prototype.once=function(e,r){return We(r),this.on(e,Jt(this,e,r)),this};C.prototype.prependOnceListener=function(e,r){return We(r),this.prependListener(e,Jt(this,e,r)),this};C.prototype.removeListener=function(e,r){var n,i,o,s,a;if(We(r),i=this._events,i===void 0)return this;if(n=i[e],n===void 0)return this;if(n===r||n.listener===r)--this._eventsCount===0?this._events=Object.create(null):(delete i[e],i.removeListener&&this.emit("removeListener",e,n.listener||r));else if(typeof n!="function"){for(o=-1,s=n.length-1;s>=0;s--)if(n[s]===r||n[s].listener===r){a=n[s].listener,o=s;break}if(o<0)return this;o===0?n.shift():Kr(n,o),n.length===1&&(i[e]=n[0]),i.removeListener!==void 0&&this.emit("removeListener",e,a||r)}return this};C.prototype.off=C.prototype.removeListener;C.prototype.removeAllListeners=function(e){var r,n,i;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 o=Object.keys(n),s;for(i=0;i=0;i--)this.removeListener(e,r[i]);return this};function Gt(t,e,r){var n=t._events;if(n===void 0)return[];var i=n[e];return i===void 0?[]:typeof i=="function"?r?[i.listener||i]:[i]:r?Vr(i):Zt(i,i.length)}C.prototype.listeners=function(e){return Gt(this,e,!0)};C.prototype.rawListeners=function(e){return Gt(this,e,!1)};C.listenerCount=function(t,e){return typeof t.listenerCount=="function"?t.listenerCount(e):qt.call(t,e)};C.prototype.listenerCount=qt;function qt(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}C.prototype.eventNames=function(){return this._eventsCount>0?He(this._events):[]};function Zt(t,e){for(var r=new Array(e),n=0;n{"use strict";var f={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}}};f.cipher.aes=function(t){this.s[0][0][0]||this.O();var e,r,n,i,o=this.s[0][4],s=this.s[1];e=t.length;var a=1;if(e!==4&&e!==6&&e!==8)throw new f.exception.invalid("invalid aes key size");for(this.b=[n=t.slice(0),i=[]],t=e;t<4*e+28;t++)r=n[t-1],(t%e===0||e===8&&t%e===4)&&(r=o[r>>>24]<<24^o[r>>16&255]<<16^o[r>>8&255]<<8^o[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],i[e]=4>=t||4>e?r:s[0][o[r>>>24]]^s[1][o[r>>16&255]]^s[2][o[r>>8&255]]^s[3][o[r&255]]};f.cipher.aes.prototype={encrypt:function(t){return ir(this,t,0)},decrypt:function(t){return ir(this,t,1)},s:[[[],[],[],[],[]],[[],[],[],[],[]]],O:function(){var t=this.s[0],e=this.s[1],r=t[4],n=e[4],i,o,s,a=[],c=[],u,h,l,p;for(i=0;256>i;i++)c[(a[i]=i<<1^283*(i>>7))^i]=i;for(o=s=0;!r[o];o^=u||1,s=c[s]||1)for(l=s^s<<1^s<<2^s<<3^s<<4,l=l>>8^l&255^99,r[o]=l,n[l]=o,h=a[i=a[u=a[o]]],p=16843009*h^65537*i^257*u^16843008*o,h=257*a[l]^16843008*l,i=0;4>i;i++)t[i][o]=h=h<<24^h>>>8,e[i][l]=p=p<<24^p>>>8;for(i=0;5>i;i++)t[i]=t[i].slice(0),e[i]=e[i].slice(0)}};function ir(t,e,r){if(e.length!==4)throw new f.exception.invalid("invalid aes block size");var n=t.b[r],i=e[0]^n[0],o=e[r?3:1]^n[1],s=e[2]^n[2];e=e[r?1:3]^n[3];var a,c,u,h=n.length/4-2,l,p=4,v=[0,0,0,0];a=t.s[r],t=a[0];var m=a[1],g=a[2],w=a[3],A=a[4];for(l=0;l>>24]^m[o>>16&255]^g[s>>8&255]^w[e&255]^n[p],c=t[o>>>24]^m[s>>16&255]^g[e>>8&255]^w[i&255]^n[p+1],u=t[s>>>24]^m[e>>16&255]^g[i>>8&255]^w[o&255]^n[p+2],e=t[e>>>24]^m[i>>16&255]^g[o>>8&255]^w[s&255]^n[p+3],p+=4,i=a,o=c,s=u;for(l=0;4>l;l++)v[r?3&-l:l]=A[i>>>24]<<24^A[o>>16&255]<<16^A[s>>8&255]<<8^A[e&255]^n[p++],a=i,i=o,o=s,s=e,e=a;return v}f.bitArray={bitSlice:function(t,e,r){return t=f.bitArray.$(t.slice(e/32),32-(e&31)).slice(1),r===void 0?t:f.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(f.bitArray.bitLength(t)!==f.bitArray.bitLength(e))return!1;var r=0,n;for(n=0;n>>e),r=t[i]<<32-e;return i=t.length?t[t.length-1]:0,t=f.bitArray.getPartial(i),n.push(f.bitArray.partial(e+t&31,32>>24|r>>>8&65280|(r&65280)<<8|r<<24;return t}};f.codec.utf8String={fromBits:function(t){var e="",r=f.bitArray.bitLength(t),n,i;for(n=0;n>>8>>>8>>>8),i<<=8;return decodeURIComponent(escape(e))},toBits:function(t){t=unescape(encodeURIComponent(t));var e=[],r,n=0;for(r=0;r>>s)>>>i),sh){if(!e)try{return f.codec.base32hex.toBits(t)}catch{}throw new f.exception.invalid("this isn't "+l+"!")}a>i?(a-=i,o.push(u^h>>>a),u=h<>>i)>>>26),6>i?(s=t[r]<<6-i,i+=26,r++):(s<<=6,i-=6);for(;n.length&3&&!e;)n+="=";return n},toBits:function(t,e){t=t.replace(/\s|=/g,"");var r=[],n,i=0,o=f.codec.base64.B,s=0,a;for(e&&(o=o.substr(0,62)+"-_"),n=0;na)throw new f.exception.invalid("this isn't base64!");26>>i),s=a<<32-i):(i+=6,s^=a<<32-i)}return i&56&&r.push(f.bitArray.partial(i&56,s,1)),r}};f.codec.base64url={fromBits:function(t){return f.codec.base64.fromBits(t,1,1)},toBits:function(t){return f.codec.base64.toBits(t,1)}};f.hash.sha256=function(t){this.b[0]||this.O(),t?(this.F=t.F.slice(0),this.A=t.A.slice(0),this.l=t.l):this.reset()};f.hash.sha256.hash=function(t){return new f.hash.sha256().update(t).finalize()};f.hash.sha256.prototype={blockSize:512,reset:function(){return this.F=this.Y.slice(0),this.A=[],this.l=0,this},update:function(t){typeof t=="string"&&(t=f.codec.utf8String.toBits(t));var e,r=this.A=f.bitArray.concat(this.A,t);if(e=this.l,t=this.l=e+f.bitArray.bitLength(t),9007199254740991e;r++){for(i=!0,n=2;n*n<=r;n++)if(r%n===0){i=!1;break}i&&(8>e&&(this.Y[e]=t(Math.pow(r,.5))),this.b[e]=t(Math.pow(r,1/3)),e++)}}};function gt(t,e){var r,n,i,o=t.F,s=t.b,a=o[0],c=o[1],u=o[2],h=o[3],l=o[4],p=o[5],v=o[6],m=o[7];for(r=0;64>r;r++)16>r?n=e[r]:(n=e[r+1&15],i=e[r+14&15],n=e[r&15]=(n>>>7^n>>>18^n>>>3^n<<25^n<<14)+(i>>>17^i>>>19^i>>>10^i<<15^i<<13)+e[r&15]+e[r+9&15]|0),n=n+m+(l>>>6^l>>>11^l>>>25^l<<26^l<<21^l<<7)+(v^l&(p^v))+s[r],m=v,v=p,p=l,l=h+n|0,h=u,u=c,c=a,a=n+(c&u^h&(c^u))+(c>>>2^c>>>13^c>>>22^c<<30^c<<19^c<<10)|0;o[0]=o[0]+a|0,o[1]=o[1]+c|0,o[2]=o[2]+u|0,o[3]=o[3]+h|0,o[4]=o[4]+l|0,o[5]=o[5]+p|0,o[6]=o[6]+v|0,o[7]=o[7]+m|0}f.mode.ccm={name:"ccm",G:[],listenProgress:function(t){f.mode.ccm.G.push(t)},unListenProgress:function(t){t=f.mode.ccm.G.indexOf(t),-1c)throw new f.exception.invalid("ccm: iv must be at least 7 bytes");for(o=2;4>o&&u>>>8*o;o++);return o<15-c&&(o=15-c),r=a.clamp(r,8*(15-o)),e=f.mode.ccm.V(t,e,r,n,i,o),s=f.mode.ccm.C(t,s,r,e,i,o),a.concat(s.data,s.tag)},decrypt:function(t,e,r,n,i){i=i||64,n=n||[];var o=f.bitArray,s=o.bitLength(r)/8,u=o.bitLength(e),a=o.clamp(e,u-i),c=o.bitSlice(e,u-i),u=(u-i)/8;if(7>s)throw new f.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=o.clamp(r,8*(15-e)),a=f.mode.ccm.C(t,a,r,c,i,e),t=f.mode.ccm.V(t,a.data,r,n,i,e),!o.equal(a.tag,t))throw new f.exception.corrupt("ccm: tag doesn't match");return a.data},na:function(t,e,r,n,i,o){var s=[],a=f.bitArray,c=a.i;if(n=[a.partial(8,(e.length?64:0)|n-2<<2|o-1)],n=a.concat(n,r),n[3]|=i,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;ei||16h&&(f.mode.ccm.fa(s/c),h+=l),r[3]++,i=t.encrypt(r),e[s]^=i[0],e[s+1]^=i[1],e[s+2]^=i[2],e[s+3]^=i[3];return{tag:n,data:a.clamp(e,u)}}};f.mode.ocb2={name:"ocb2",encrypt:function(t,e,r,n,i,o){if(f.bitArray.bitLength(r)!==128)throw new f.exception.invalid("ocb iv must be 128 bits");var s,a=f.mode.ocb2.S,c=f.bitArray,u=c.i,h=[0,0,0,0];r=a(t.encrypt(r));var l,p=[];for(n=n||[],i=i||64,s=0;s+4i.bitLength(r)&&(a=o(a,n(a)),r=i.concat(r,[-2147483648,0,0,0])),s=o(s,r),t.encrypt(o(n(o(a,n(a))),s))},S:function(t){return[t[0]<<1^t[1]>>>31,t[1]<<1^t[2]>>>31,t[2]<<1^t[3]>>>31,t[3]<<1^135*(t[0]>>>31)]}};f.mode.gcm={name:"gcm",encrypt:function(t,e,r,n,i){var o=e.slice(0);return e=f.bitArray,n=n||[],t=f.mode.gcm.C(!0,t,o,n,r,i||128),e.concat(t.data,t.tag)},decrypt:function(t,e,r,n,i){var o=e.slice(0),s=f.bitArray,a=s.bitLength(o);if(i=i||128,n=n||[],i<=a?(e=s.bitSlice(o,a-i),o=s.bitSlice(o,0,a-i)):(e=o,o=[]),t=f.mode.gcm.C(!1,t,o,n,r,i),!s.equal(t.tag,e))throw new f.exception.corrupt("gcm: tag doesn't match");return t.data},ka:function(t,e){var r,n,i,o,s,a=f.bitArray.i;for(i=[0,0,0,0],o=e.slice(0),r=0;128>r;r++){for((n=(t[Math.floor(r/32)]&1<<31-r%32)!==0)&&(i=a(i,o)),s=(o[3]&1)!==0,n=3;0>>1|(o[n-1]&1)<<31;o[0]>>>=1,s&&(o[0]^=-520093696)}return i},j:function(t,e,r){var n,i=r.length;for(e=e.slice(0),n=0;ni&&(t=e.hash(t)),n=0;nn||0>r)throw new f.exception.invalid("invalid params to pbkdf2");typeof t=="string"&&(t=f.codec.utf8String.toBits(t)),typeof e=="string"&&(e=f.codec.utf8String.toBits(e)),i=i||f.misc.hmac,t=new i(t);var o,s,a,c,u=[],h=f.bitArray;for(c=1;32*u.length<(n||1);c++){for(i=o=t.encrypt(h.concat(e,[c])),s=1;ss;s++)i.push(4294967296*Math.random()|0);for(s=0;s=1<this.o&&(this.o=o),this.P++,this.b=f.hash.sha256.hash(this.b.concat(i)),this.L=new f.cipher.aes(this.b),n=0;4>n&&(this.h[n]=this.h[n]+1|0,!this.h[n]);n++);}for(n=0;n>>1;this.c[s].update([n,this.N++,2,e,o,t.length].concat(t))}break;case"string":e===void 0&&(e=t.length),this.c[s].update([n,this.N++,3,e,o,t.length]),this.c[s].update(t);break;default:c=1}if(c)throw new f.exception.bug("random: addEntropy only supports number, array of numbers or string");this.m[s]+=e,this.f+=e,a===this.u&&(this.isReady()!==this.u&&or("seeded",Math.max(this.o,this.f)),or("progress",this.getProgress()))},isReady:function(t){return t=this.T[t!==void 0?t:this.M],this.o&&this.o>=t?this.m[0]>this.ba&&new Date().valueOf()>this.Z?this.J|this.I:this.I:this.f>=t?this.J|this.u:this.u},getProgress:function(t){return t=this.T[t||this.M],this.o>=t||this.f>t?1:this.f/t},startCollectors:function(){if(!this.D){if(this.a={loadTimeCollector:ze(this,this.ma),mouseCollector:ze(this,this.oa),keyboardCollector:ze(this,this.la),accelerometerCollector:ze(this,this.ea),touchCollector:ze(this,this.qa)},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 f.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.K[t][this.ga++]=e},removeEventListener:function(t,e){var r,n,i=this.K[t],o=[];for(n in i)i.hasOwnProperty(n)&&i[n]===e&&o.push(n);for(r=0;re&&(t.h[e]=t.h[e]+1|0,!t.h[e]);e++);return t.L.encrypt(t.h)}function ze(t,e){return function(){e.apply(t,arguments)}}f.random=new f.prng(6);e:try{if(Xe=typeof De<"u"&&De.exports){try{Qe=qr("crypto")}catch{Qe=null}Xe=Ye=Qe}if(Xe&&Ye.randomBytes)Fe=Ye.randomBytes(128),Fe=new Uint32Array(new Uint8Array(Fe).buffer),f.random.addEntropy(Fe,1024,"crypto['randomBytes']");else if(typeof window<"u"&&typeof Uint32Array<"u"){if(Be=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(Be);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(Be);else break e;f.random.addEntropy(Be,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 Fe,Ye,Be,Xe,Qe;f.json={defaults:{v:1,iter:1e4,ks:128,ts:64,mode:"ccm",adata:"",cipher:"aes"},ja:function(t,e,r,n){r=r||{},n=n||{};var i=f.json,o=i.g({iv:f.random.randomWords(4,0)},i.defaults),s;if(i.g(o,r),r=o.adata,typeof o.salt=="string"&&(o.salt=f.codec.base64.toBits(o.salt)),typeof o.iv=="string"&&(o.iv=f.codec.base64.toBits(o.iv)),!f.mode[o.mode]||!f.cipher[o.cipher]||typeof t=="string"&&100>=o.iter||o.ts!==64&&o.ts!==96&&o.ts!==128||o.ks!==128&&o.ks!==192&&o.ks!==256||2>o.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||4Tr,cancel:()=>kn,compress:()=>zr,decompress:()=>Mn,download:()=>Rn,events:()=>It,getFileIndexInQueue:()=>jn,infos:()=>Un,pause:()=>In,remove:()=>Tn,resume:()=>zn,upload:()=>Bn});var Ir=lt(vt());var Qr={withStackTrace:!1},Kt=(t,e,r=Qr)=>{let n=e.isOk()?{type:"Ok",value:e.value}:{type:"Err",value:e.error},i=r.withStackTrace?new Error().stack:void 0;return{data:n,message:t,stack:i}};function Ae(t,e,r,n){function i(o){return o instanceof r?o:new r(function(s){s(o)})}return new(r||(r=Promise))(function(o,s){function a(h){try{u(n.next(h))}catch(l){s(l)}}function c(h){try{u(n.throw(h))}catch(l){s(l)}}function u(h){h.done?o(h.value):i(h.value).then(a,c)}u((n=n.apply(t,e||[])).next())})}function Wt(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 se(t){return this instanceof se?(this.v=t,this):new se(t)}function $t(t,e,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=r.apply(t,e||[]),i,o=[];return i=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),a("next"),a("throw"),a("return",s),i[Symbol.asyncIterator]=function(){return this},i;function s(v){return function(m){return Promise.resolve(m).then(v,l)}}function a(v,m){n[v]&&(i[v]=function(g){return new Promise(function(w,A){o.push([v,g,w,A])>1||c(v,g)})},m&&(i[v]=m(i[v])))}function c(v,m){try{u(n[v](m))}catch(g){p(o[0][3],g)}}function u(v){v.value instanceof se?Promise.resolve(v.value.v).then(h,l):p(o[0][2],v)}function h(v){c("next",v)}function l(v){c("throw",v)}function p(v,m){v(m),o.shift(),o.length&&c(o[0][0],o[0][1])}}function en(t){var e,r;return e={},n("next"),n("throw",function(i){throw i}),n("return"),e[Symbol.iterator]=function(){return this},e;function n(i,o){e[i]=t[i]?function(s){return(r=!r)?{value:se(t[i](s)),done:!1}:o?o(s):s}:o}}function tn(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 Wt=="function"?Wt(t):t[Symbol.iterator](),r={},n("next"),n("throw"),n("return"),r[Symbol.asyncIterator]=function(){return this},r);function n(o){r[o]=t[o]&&function(s){return new Promise(function(a,c){s=t[o](s),i(a,c,s.done,s.value)})}}function i(o,s,a,c){Promise.resolve(c).then(function(u){o({value:u,done:a})},s)}}var b=class t{constructor(e){this._promise=e}static fromSafePromise(e){let r=e.then(n=>new Y(n));return new t(r)}static fromPromise(e,r){let n=e.then(i=>new Y(i)).catch(i=>new X(r(i)));return new t(n)}static fromThrowable(e,r){return(...n)=>new t(Ae(this,void 0,void 0,function*(){try{return new Y(yield e(...n))}catch(i){return new X(r?r(i):i)}}))}static combine(e){return rn(e)}static combineWithAllErrors(e){return nn(e)}map(e){return new t(this._promise.then(r=>Ae(this,void 0,void 0,function*(){return r.isErr()?new X(r.error):new Y(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 X(r.error);let n=yield e(r.value);return n.isErr()?new X(n.error):new Y(r.value)})))}andTee(e){return new t(this._promise.then(r=>Ae(this,void 0,void 0,function*(){if(r.isErr())return new X(r.error);try{yield e(r.value)}catch{}return new Y(r.value)})))}mapErr(e){return new t(this._promise.then(r=>Ae(this,void 0,void 0,function*(){return r.isOk()?new Y(r.value):new X(yield e(r.error))})))}andThen(e){return new t(this._promise.then(r=>{if(r.isErr())return new X(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 Y(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 $t(this,arguments,function*(){return yield se(yield se(yield*en(tn(yield se(this._promise.then(r=>r.safeUnwrap()))))))})}then(e,r){return this._promise.then(e,r)}[Symbol.asyncIterator](){return $t(this,arguments,function*(){let r=yield se(this._promise);return r.isErr()&&(yield yield se(G(r.error))),yield se(r.value)})}},q=t=>new b(Promise.resolve(new Y(t))),G=t=>new b(Promise.resolve(new X(t))),Gn=b.fromPromise,qn=b.fromSafePromise,Zn=b.fromThrowable,Vt=t=>{let e=ae([]);for(let r of t)if(r.isErr()){e=Q(r.error);break}else e.map(n=>n.push(r.value));return e},rn=t=>b.fromSafePromise(Promise.all(t)).andThen(Vt),Yt=t=>{let e=ae([]);for(let r of t)r.isErr()&&e.isErr()?e.error.push(r.error):r.isErr()&&e.isOk()?e=Q([r.error]):r.isOk()&&e.isOk()&&e.value.push(r.value);return e},nn=t=>b.fromSafePromise(Promise.all(t)).andThen(Yt),mt;(function(t){function e(i,o){return(...s)=>{try{let a=i(...s);return ae(a)}catch(a){return Q(o?o(a):a)}}}t.fromThrowable=e;function r(i){return Vt(i)}t.combine=r;function n(i){return Yt(i)}t.combineWithAllErrors=n})(mt||(mt={}));var ae=t=>new Y(t);function Q(t){return new X(t)}var Y=class{constructor(e){this.value=e}isOk(){return!0}isErr(){return!this.isOk()}map(e){return ae(e(this.value))}mapErr(e){return ae(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 ae(this.value)}orElse(e){return ae(this.value)}asyncAndThen(e){return e(this.value)}asyncAndThrough(e){return e(this.value).map(()=>this.value)}asyncMap(e){return b.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 Kt("Called `_unsafeUnwrapErr` on an Ok",this,e)}*[Symbol.iterator](){return this.value}},X=class{constructor(e){this.error=e}isOk(){return!1}isErr(){return!this.isOk()}map(e){return Q(this.error)}mapErr(e){return Q(e(this.error))}andThrough(e){return Q(this.error)}andTee(e){return Q(this.error)}andThen(e){return Q(this.error)}orElse(e){return e(this.error)}asyncAndThen(e){return G(this.error)}asyncAndThrough(e){return G(this.error)}asyncMap(e){return G(this.error)}unwrapOr(e){return e}match(e,r){return r(this.error)}safeUnwrap(){let e=this.error;return function*(){throw yield Q(e),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(e){throw Kt("Called `_unsafeUnwrap` on an Err",this,e)}_unsafeUnwrapErr(e){return this.error}*[Symbol.iterator](){let e=this;return yield e,e}},Hn=mt.fromThrowable;var ne=class t{constructor(e,r){d(this,"actionToken","");d(this,"chunksReady",0);d(this,"createdAt",0);d(this,"delay",0);d(this,"delAtFirstView",!1);d(this,"keys",{client:"",server:""});d(this,"name","");d(this,"password","");d(this,"queueIndex",0);d(this,"serverUrl");d(this,"size",0);d(this,"uploadStatus",3);d(this,"totalChunks",0);d(this,"type","");d(this,"zipped",!1);this.serverUrl=e,Object.assign(this,r)}downloadUrl(){let e=new URL(this.serverUrl);return new URL(`${e.origin+e.pathname}r/${this.keys.server}#${this.keys.client}`)}removeUrl(){let e=new URL(this.serverUrl);return new URL(`${e.origin+e.pathname}d/${this.keys.server}/${this.actionToken}`)}static fromDownloadUrl(e,r=""){let n=e.pathname.split("r/"),i={client:e.hash.slice(1).split("&")[0],server:n[1]};return new t(e.origin+n[0],{keys:i,password:r})}static fromRemoveUrl(e,r=""){let n=e.pathname.split("d/"),i=n[1].split("/"),o={client:"",server:i[0]};return new t(e.origin+n[0],{keys:o,password:r,actionToken:i[1]})}};var tr=lt(vt());var fe=class extends Error{constructor(r,n={}){let{cause:i,context:o}=n;super(r,{cause:i});d(this,"context");this.name=this.constructor.name,this.context=o}};var $e=class extends fe{constructor(){super(...arguments);d(this,"message","Unable to connect. Is the computer able to access the url?")}};var Ke=class extends fe{constructor(){super(...arguments);d(this,"message","The server returned an error")}};var U=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)},yt=t=>{let e=t.href.match(/(.*?)\/?(?:\/[dr]{1}\/|login\/?|files\/?)/),r=e&&e[1]?e[1]:t.origin;return b.fromPromise(fetch(r+"/about/config"),n=>new $e(void 0,{cause:U(n)})).andThen(n=>n.ok?b.fromPromise(n.json(),i=>U(i)):G(new Ke(void 0,{context:n.statusText})))},Qt=()=>typeof Deno<"u",on=()=>Qt()||typeof window<"u"&&(window.isSecureContext||window.location.protocol==="https:"),er=t=>Qt()?new URL(`./worker/${t}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${t==="main"?`worker/${t}`:t}.js`)),Ve=async t=>t?Array.from(new Uint8Array(await crypto.subtle.digest("SHA-512",new TextEncoder().encode(t)))).map(e=>e.toString(16).padStart(2,"0")).join(""):"";var me=class{constructor(e){d(this,"events",new tr.default);d(this,"lufiFile");d(this,"status",2);d(this,"tmpFile");d(this,"tmpChunks",[]);d(this,"worker");d(this,"isTerminated",!1);d(this,"complete",()=>{this.status=0,this.events.emit("JOB_TERMINATED")});d(this,"hasFailed",()=>this.status===1);d(this,"onError",e=>(this.worker.onerror=r=>{e(r)},this));d(this,"onMessage",e=>(this.worker.onmessage=r=>{e&&e(r);let n=r.data.event;n&&(n==="FILE_UPDATED"?Object.assign(this.lufiFile,r.data.lufiFile):this.dispatchEvent(n,r.data.error))},this));d(this,"onMessageError",e=>(this.worker.onmessageerror=r=>{e(r)},this));d(this,"onProgress",e=>(this.events.on("CHUNK_UPLOADED",()=>{e()}),this.events.on("CHUNK_DOWNLOADED",()=>{e()}),this));d(this,"requestMessage",(e,r=[])=>(this.worker.postMessage(e,r),this));d(this,"terminate",()=>(this.worker.terminate(),this));d(this,"waitForCompletion",()=>this.isTerminated?this.status===0?q(this):G(U("Job has failed")):b.fromPromise(new Promise((e,r)=>{this.events.once("OPERATION_FAILED",n=>{r(n)}),this.events.once("JOB_TERMINATED",()=>{this.status===0&&e(this)})}),e=>U(e)));d(this,"dispatchEvent",(e,r)=>{this.events.emit(e,r)});this.worker=new Worker(er("main"),{type:"module"}),this.lufiFile=e,this.events.once("JOB_TERMINATED",()=>{this.isTerminated=!0,this.terminate()}),this.events.once("OPERATION_FAILED",r=>{this.status=1,this.lufiFile.uploadStatus=2,this.events.emit("JOB_TERMINATED",r)}),this.onError(r=>console.error(r.error))}};var Le=(r=>(r[r.Sjcl=0]="Sjcl",r[r.WebCrypto=1]="WebCrypto",r))(Le||{});var be=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),i="";for(let o=0;o>2]+this._charset[(n[o]&3)<<4|n[o+1]>>4]+this._charset[(n[o+1]&15)<<2|n[o+2]>>6]+this._charset[n[o+2]&63];return r%3==2?(i=i.substring(0,i.length-1),this._noPadding||(i+="=")):r%3==1&&(i=i.substring(0,i.length-2),this._noPadding||(i+="==")),i}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),i,o,s,a,c=0,u=0;for(;c>4,n[c++]=(o&15)<<4|s>>2,n[c++]=(s&3)<<6|a;return n.buffer}};var Li=new be("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");var fn=new be("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",!0);function dt(t){return fn.Encode(t)}var Et=lt(ar());var le=class extends fe{};var Ce=class extends le{constructor(){super(...arguments);d(this,"message","Unable to decrypt the provided data")}};var fr=()=>{try{return q(Et.default.codec.base64.fromBits(Et.default.random.randomWords(8,10)))}catch(t){return G(new le("Unable to generate a random key",{cause:U(t)}))}};var cr=()=>b.fromPromise(new Promise(t=>crypto.subtle.generateKey({name:"AES-GCM",length:256},!0,["encrypt","decrypt"]).then(e=>crypto.subtle.exportKey("raw",e).then(r=>t(dt(r))).catch(r=>G(new Ce(void 0,{cause:U(r)})))).catch(e=>G(new Ce(void 0,{cause:U(e)})))),t=>new le("Unable to base64 encode the url",{cause:U(t)}));var ur=(t=1)=>t===0?fr():cr();var et=class extends fe{constructor(){super(...arguments);d(this,"message","An error occured while dealing with a file")}};var tt=class extends et{constructor(){super(...arguments);d(this,"message","An error occured while operating on a file")}};var rt=class extends tt{constructor(){super(...arguments);d(this,"message","An error occured while slicing a file")}};var hr={},pn=function(t,e,r,n,i){var o=new Worker(hr[e]||(hr[e]=URL.createObjectURL(new Blob([t+';addEventListener("error",function(e){e=e.error;postMessage({$e$:[e.message,e.code,e.stack]})})'],{type:"text/javascript"}))));return o.onmessage=function(s){var a=s.data,c=a.$e$;if(c){var u=new Error(c[0]);u.code=c[1],u.stack=c[2],i(u,null)}else i(null,a)},o.postMessage(r,n),o},P=Uint8Array,H=Uint16Array,Ne=Int32Array,ke=new P([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),Me=new P([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),_e=new P([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),yr=function(t,e){for(var r=new H(31),n=0;n<31;++n)r[n]=e+=1<>1|(D&21845)<<1,pe=(pe&52428)>>2|(pe&13107)<<2,pe=(pe&61680)>>4|(pe&3855)<<4,je[D]=((pe&65280)>>8|(pe&255)<<8)>>1;var pe,D,te=function(t,e,r){for(var n=t.length,i=0,o=new H(e);i>c]=u}else for(a=new H(n),i=0;i>15-t[i]);return a},ve=new P(288);for(D=0;D<144;++D)ve[D]=8;var D;for(D=144;D<256;++D)ve[D]=9;var D;for(D=256;D<280;++D)ve[D]=7;var D;for(D=280;D<288;++D)ve[D]=8;var D,Pe=new P(32);for(D=0;D<32;++D)Pe[D]=5;var D,Er=te(ve,9,0),xr=te(ve,9,1),Ar=te(Pe,5,0),Lr=te(Pe,5,1),it=function(t){for(var e=t[0],r=1;re&&(e=t[r]);return e},ee=function(t,e,r){var n=e/8|0;return(t[n]|t[n+1]<<8)>>(e&7)&r},ot=function(t,e){var r=e/8|0;return(t[r]|t[r+1]<<8|t[r+2]<<16)>>(e&7)},Je=function(t){return(t+7)/8|0},ye=function(t,e,r){return(e==null||e<0)&&(e=0),(r==null||r>t.length)&&(r=t.length),new P(t.subarray(e,r))};var br=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],_=function(t,e,r){var n=new Error(e||br[t]);if(n.code=t,Error.captureStackTrace&&Error.captureStackTrace(n,_),!r)throw n;return n},Dr=function(t,e,r,n){var i=t.length,o=n?n.length:0;if(!i||e.f&&!e.l)return r||new P(0);var s=!r,a=s||e.i!=2,c=e.i;s&&(r=new P(i*3));var u=function(Ue){var Ie=r.length;if(Ue>Ie){var Ee=new P(Math.max(Ie*2,Ue));Ee.set(r),r=Ee}},h=e.f||0,l=e.p||0,p=e.b||0,v=e.l,m=e.d,g=e.m,w=e.n,A=i*8;do{if(!v){h=ee(t,l,1);var I=ee(t,l+1,3);if(l+=3,I)if(I==1)v=xr,m=Lr,g=9,w=5;else if(I==2){var T=ee(t,l,31)+257,k=ee(t,l+10,15)+4,x=T+ee(t,l+5,31)+1;l+=14;for(var y=new P(x),M=new P(19),O=0;O>4;if(L<16)y[O++]=L;else{var B=0,R=0;for(L==16?(R=3+ee(t,l,3),l+=2,B=y[O-1]):L==17?(R=3+ee(t,l,7),l+=3):L==18&&(R=11+ee(t,l,127),l+=7);R--;)y[O++]=B}}var W=y.subarray(0,T),J=y.subarray(T);g=it(W),w=it(J),v=te(W,g,1),m=te(J,w,1)}else _(1);else{var L=Je(l)+4,E=t[L-4]|t[L-3]<<8,S=L+E;if(S>i){c&&_(0);break}a&&u(p+E),r.set(t.subarray(L,S),p),e.b=p+=E,e.p=l=S*8,e.f=h;continue}if(l>A){c&&_(0);break}}a&&u(p+131072);for(var Re=(1<>4;if(l+=B&15,l>A){c&&_(0);break}if(B||_(2),$<256)r[p++]=$;else if($==256){he=l,v=null;break}else{var K=$-254;if($>264){var O=$-257,F=ke[O];K=ee(t,l,(1<>4;oe||_(3),l+=oe&15;var J=wr[ge];if(ge>3){var F=Me[ge];J+=ot(t,l)&(1<A){c&&_(0);break}a&&u(p+131072);var we=p+K;if(p>8},Oe=function(t,e,r){r<<=e&7;var n=e/8|0;t[n]|=r,t[n+1]|=r>>8,t[n+2]|=r>>16},st=function(t,e){for(var r=[],n=0;np&&(p=o[n].s);var v=new H(p+1),m=ft(r[h-1],v,0);if(m>e){var n=0,g=0,w=m-e,A=1<e)g+=A-(1<>=w;g>0;){var L=o[n].s;v[L]=0&&g;--n){var E=o[n].s;v[E]==e&&(--v[E],++g)}m=e}return{t:new P(v),l:m}},ft=function(t,e,r){return t.s==-1?Math.max(ft(t.l,e,r+1),ft(t.r,e,r+1)):e[t.s]=r},Lt=function(t){for(var e=t.length;e&&!t[--e];);for(var r=new H(++e),n=0,i=t[0],o=1,s=function(c){r[n++]=c},a=1;a<=e;++a)if(t[a]==i&&a!=e)++o;else{if(!i&&o>2){for(;o>138;o-=138)s(32754);o>2&&(s(o>10?o-11<<5|28690:o-3<<5|12305),o=0)}else if(o>3){for(s(i),--o;o>6;o-=6)s(8304);o>2&&(s(o-3<<5|8208),o=0)}for(;o--;)s(i);o=1,i=t[a]}return{c:r.subarray(0,n),n:e}},Se=function(t,e){for(var r=0,n=0;n>8,t[i+2]=t[i]^255,t[i+3]=t[i+1]^255;for(var o=0;o4&&!M[_e[z-1]];--z);var re=u+5<<3,j=Se(i,ve)+Se(o,Pe)+s,N=Se(i,p)+Se(o,g)+s+14+3*z+Se(k,M)+2*k[16]+3*k[17]+7*k[18];if(c>=0&&re<=j&&re<=N)return St(e,h,t.subarray(c,c+u));var B,R,W,J;if(ce(e,h,1+(N15&&(ce(e,h,$[x]>>5&127),h+=$[x]>>12)}}else B=Er,R=ve,W=Ar,J=Pe;for(var x=0;x255){var K=F>>18&31;Oe(e,h,B[K+257]),h+=R[K+257],K>7&&(ce(e,h,F>>23&31),h+=ke[K]);var oe=F&31;Oe(e,h,W[oe]),h+=J[oe],oe>3&&(Oe(e,h,F>>5&8191),h+=Me[oe])}else Oe(e,h,B[F]),h+=R[F]}return Oe(e,h,B[256]),h+R[256]},Cr=new Ne([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),Pt=new P(0),Or=function(t,e,r,n,i,o){var s=o.z||t.length,a=new P(n+s+5*(1+Math.ceil(s/7e3))+i),c=a.subarray(n,a.length-i),u=o.l,h=(o.r||0)&7;if(e){h&&(c[0]=o.r>>3);for(var l=Cr[e-1],p=l>>13,v=l&8191,m=(1<7e3||M>24576)&&(B>423||!u)){h=bt(t,c,0,E,S,T,x,M,z,y-z,h),M=k=x=0,z=y;for(var R=0;R<286;++R)S[R]=0;for(var R=0;R<30;++R)T[R]=0}var W=2,J=0,Re=v,V=j-N&32767;if(B>2&&re==L(y-V))for(var he=Math.min(p,B)-1,$=Math.min(32767,y),K=Math.min(258,B);V<=$&&--Re&&j!=N;){if(t[y+W]==t[y+W-V]){for(var F=0;FW){if(W=F,J=V,F>he)break;for(var oe=Math.min(V,F-2),ge=0,R=0;Rge&&(ge=qe,N=we)}}}j=N,N=g[j],V+=j-N&32767}if(J){E[M++]=268435456|at[W]<<18|At[J];var Ue=at[W]&31,Ie=At[J]&31;x+=ke[Ue]+Me[Ie],++S[257+Ue],++T[Ie],O=y+W,++k}else E[M++]=t[y],++S[t[y]]}}for(y=Math.max(y,O);y=s&&(c[h/8|0]=u,Ee=s),h=St(c,h+1,t.subarray(y,Ee))}o.i=s}return ye(a,0,n+Je(h)+i)},vn=function(){for(var t=new Int32Array(256),e=0;e<256;++e){for(var r=e,n=9;--n;)r=(r&1&&-306674912)^r>>>1;t[e]=r}return t}(),mn=function(){var t=-1;return{p:function(e){for(var r=t,n=0;n>>8;t=r},d:function(){return~t}}};var Sr=function(t,e,r,n,i){if(!i&&(i={l:1},e.dictionary)){var o=e.dictionary.subarray(-32768),s=new P(o.length+t.length);s.set(o),s.set(t,o.length),t=s,i.w=o.length}return Or(t,e.level==null?6:e.level,e.mem==null?i.l?Math.ceil(Math.max(8,Math.min(13,Math.log(t.length)))*1.5):20:12+e.mem,r,n,i)},kt=function(t,e){var r={};for(var n in t)r[n]=t[n];for(var n in e)r[n]=e[n];return r},lr=function(t,e,r){for(var n=t(),i=t.toString(),o=i.slice(i.indexOf("[")+1,i.lastIndexOf("]")).replace(/\s+/g,"").split(","),s=0;s>>0},xt=function(t,e){return ie(t,e)+ie(t,e+4)*4294967296},Z=function(t,e,r){for(;r;++e)t[e]=r,r>>>=8};function En(t,e,r){return r||(r=e,e={}),typeof r!="function"&&_(7),kr(t,e,[wn],function(n){return ut(Mt(n.data[0],n.data[1]))},0,r)}function Mt(t,e){return Sr(t,e||{},0,0)}function xn(t,e,r){return r||(r=e,e={}),typeof r!="function"&&_(7),kr(t,e,[gn],function(n){return ut(Rt(n.data[0],Pr(n.data[1])))},1,r)}function Rt(t,e){return Dr(t,{i:2},e&&e.out,e&&e.dictionary)}var Mr=function(t,e,r,n){for(var i in t){var o=t[i],s=e+i,a=n;Array.isArray(o)&&(a=kt(n,o[1]),o=o[0]),o instanceof P?r[s]=[o,a]:(r[s+="/"]=[new P(0),a],Mr(o,s,r,n))}},pr=typeof TextEncoder<"u"&&new TextEncoder,Dt=typeof TextDecoder<"u"&&new TextDecoder,An=0;try{Dt.decode(Pt,{stream:!0}),An=1}catch{}var Ln=function(t){for(var e="",r=0;;){var n=t[r++],i=(n>127)+(n>223)+(n>239);if(r+i>t.length)return{s:e,r:ye(t,r-1)};i?i==3?(n=((n&15)<<18|(t[r++]&63)<<12|(t[r++]&63)<<6|t[r++]&63)-65536,e+=String.fromCharCode(55296|n>>10,56320|n&1023)):i&1?e+=String.fromCharCode((n&31)<<6|t[r++]&63):e+=String.fromCharCode((n&15)<<12|(t[r++]&63)<<6|t[r++]&63):e+=String.fromCharCode(n)}};function vr(t,e){if(e){for(var r=new P(t.length),n=0;n>1)),s=0,a=function(h){o[s++]=h},n=0;no.length){var c=new P(s+8+(i-n<<1));c.set(o),o=c}var u=t.charCodeAt(n);u<128||e?a(u):u<2048?(a(192|u>>6),a(128|u&63)):u>55295&&u<57344?(u=65536+(u&1047552)|t.charCodeAt(++n)&1023,a(240|u>>18),a(128|u>>12&63),a(128|u>>6&63),a(128|u&63)):(a(224|u>>12),a(128|u>>6&63),a(128|u&63))}return ye(o,0,s)}function bn(t,e){if(e){for(var r="",n=0;n65535&&_(9),e+=n+4}return e},mr=function(t,e,r,n,i,o,s,a){var c=n.length,u=r.extra,h=a&&a.length,l=Ct(u);Z(t,e,s!=null?33639248:67324752),e+=4,s!=null&&(t[e++]=20,t[e++]=r.os),t[e]=20,e+=2,t[e++]=r.flag<<1|(o<0&&8),t[e++]=i&&8,t[e++]=r.compression&255,t[e++]=r.compression>>8;var p=new Date(r.mtime==null?Date.now():r.mtime),v=p.getFullYear()-1980;if((v<0||v>119)&&_(10),Z(t,e,v<<25|p.getMonth()+1<<21|p.getDate()<<16|p.getHours()<<11|p.getMinutes()<<5|p.getSeconds()>>1),e+=4,o!=-1&&(Z(t,e,r.crc),Z(t,e+4,o<0?-o-2:o),Z(t,e+8,r.size)),Z(t,e+12,c),Z(t,e+14,l),e+=16,s!=null&&(Z(t,e,h),Z(t,e+6,r.attrs),Z(t,e+10,s),e+=14),t.set(n,e),e+=c,l)for(var m in u){var g=u[m],w=g.length;Z(t,e,+m),Z(t,e+2,w),t.set(g,e+4),e+=4+w}return h&&(t.set(a,e),e+=h),e},Sn=function(t,e,r,n,i){Z(t,e,101010256),Z(t,e+8,r),Z(t,e+10,r),Z(t,e+12,n),Z(t,e+16,i)};function Rr(t,e,r){r||(r=e,e={}),typeof r!="function"&&_(7);var n={};Mr(t,"",n,e);var i=Object.keys(n),o=i.length,s=0,a=0,c=o,u=new Array(o),h=[],l=function(){for(var w=0;w65535&&j(_(11,0,1),null),!re)j(null,L);else if(T<16e4)try{j(null,Mt(L,E))}catch(N){j(N,null)}else h.push(En(L,E,j))},g=0;g65558)return s(_(13,0,1),null),i;var c=ue(t,a+8);if(c){var u=c,h=ie(t,a+16),l=h==4294967295||u==65535;if(l){var p=ie(t,a-12);l=ie(t,p)==101075792,l&&(u=c=ie(t,p+32),h=ie(t,p+48))}for(var v=e&&e.filter,m=function(w){var A=Cn(t,h,l),I=A[0],L=A[1],E=A[2],S=A[3],T=A[4],k=A[5],x=Dn(t,k);h=T;var y=function(O,z){O?(i(),s(O,null)):(z&&(o[S]=z),--c||s(null,o))};if(!v||v({name:S,size:L,originalSize:E,compression:I}))if(!I)y(null,ye(t,x,x+L));else if(I==8){var M=t.subarray(x,x+L);if(E<524288||L>.8*E)try{y(null,Rt(M,{out:new P(E)}))}catch(O){y(O,null)}else n.push(xn(M,{size:E},y))}else y(_(14,"unknown compression type "+I,1),null);else y(null,null)},g=0;g{t.terminate();let e=new me(t.lufiFile);return b.fromPromise(new Promise((r,n)=>{e.onMessage(i=>{i.data.event==="UPLOAD_CANCELLED"&&(de[e.lufiFile.keys.client].uploadStatus=0,r(e)),i.data.event==="OPERATION_FAILED"&&n(i.data.error)}).requestMessage({action:2,args:{lufiFile:e.lufiFile}})}),r=>U(r))},Tr=(t,e={})=>{let r=async n=>{var i;for(let o of n){let s=((i=o.name.split("/"))==null?void 0:i.pop())||o.name,a=s.split(".").shift(),c=s.split(".").pop(),u=s;if(e[u]!==void 0){let h=1;do u=`${a}_(${h}).${c}`,h++;while(e[u]!==void 0)}It.emit("ARCHIVE_ADDED_FILE",{name:u,size:o.size}),e[u]=await o.bytes()}};return b.fromPromise(r(t),n=>U(n)).andThen(()=>q(e))},zr=(t,e)=>{let r=()=>new Promise((n,i)=>{Rr(t,(o,s)=>{o&&i(o),n(s)})});return b.fromPromise(r(),n=>U(n)).andThen(n=>q(new File([new Blob([n])],e,{type:"application/zip"}))).orElse(n=>G(n))},Mn=t=>{let e=async()=>{let r=await t.bytes();return new Promise((n,i)=>{Ur(r,(o,s)=>{o&&i(o),n(s)})})};return b.fromPromise(e(),r=>U(r)).andThen(r=>{let n=[];for(let i in r)n.push(new File([new Blob([r[i]])],i));return q(n)})},Rn=(t,e)=>{let r;return e?r=yt(t).andThen(n=>n.version.tag>"0.07.0"?b.fromPromise(Ve(e).then(i=>ne.fromDownloadUrl(t,i)),i=>U(i)):q(ne.fromDownloadUrl(t,e))):r=q(ne.fromDownloadUrl(t)),r.andThen(n=>{let i=new me(n);return b.fromPromise(new Promise((o,s)=>i.onMessage(a=>{Fr(o,s,i,a),a.data.event==="CHUNK_DOWNLOADED"&&(i.tmpChunks[a.data.chunk.index]=new Blob([a.data.chunk.buffer])),a.data.event==="DOWNLOAD_COMPLETE"&&(i.tmpFile=new Blob(i.tmpChunks,{type:n.type}),i.tmpChunks=[],i.complete())}).requestMessage({action:3,args:{lufiFile:n}})),o=>U(o))})},Un=(t,e)=>{let r;return e?r=yt(t).andThen(n=>n.version.tag>"0.07.0"?b.fromPromise(Ve(e).then(i=>ne.fromDownloadUrl(t,i)),i=>U(i)):q(ne.fromDownloadUrl(t,e))):r=q(ne.fromDownloadUrl(t)),r.andThen(n=>q(new me(n))).andThen(n=>b.fromPromise(new Promise((i,o)=>{n.onMessage(s=>{s.data.event==="INFOS_RETRIEVED"&&(n.complete(),i(n)),s.data.event==="OPERATION_FAILED"&&o(s.data.error)}).requestMessage({action:4,args:{lufiFile:n.lufiFile}})}),i=>U(i)))},In=t=>(t.status=3,q(t.requestMessage({action:5,args:{lufiFile:t.lufiFile}}))),Tn=(t,e)=>{let r=ne.fromRemoveUrl(t,e),n=new me(r);return b.fromPromise(new Promise((i,o)=>{n.onMessage(s=>{s.data.event==="FILE_REMOVED"&&(n.complete(),i(n)),s.data.event==="OPERATION_FAILED"&&o(s.data.error)}).requestMessage({action:7,args:{lufiFile:r}})}),i=>U(i))},zn=t=>(t.status=2,q(t.requestMessage({action:8,args:{lufiFile:t.lufiFile}}))),Fn=(t,e,r=Pn)=>{let n=Math.ceil(t.size/r);if(de[e].totalChunks=n,n>0){let i=[];for(let o=0;o{let c=[];return i?e.length===1&&e[0].type==="application/zip"?c.push(Ut(t,e[0],r,n,i,s,a)):c.push(Tr(e).andThen(u=>zr(u,o).andThen(h=>(It.emit("ARCHIVE_CREATED",h),Ut(t,h,r,n,i,s,a))))):e.forEach(u=>{c.push(Ut(t,u,r,n,i,s,a))}),b.combine(c)},Ut=(t,e,r,n,i,o,s)=>ur(s).andThen(a=>b.fromPromise(Ve(o).then(c=>(de[a]=new ne(t.toString(),{delay:r,delAtFirstView:n,zipped:i,password:c,name:e.name.split("/").pop(),size:e.size,type:e.type,keys:{client:a,server:""}}),a)),c=>U(c))).andThen(a=>{let c=new me(de[a]);return Fn(e,a).asyncAndThen(u=>{de[a].uploadStatus=4;let h=new Promise((p,v)=>{c.onMessage(m=>{switch(Fr(p,v,c,m),m.data.event){case"UPLOAD_COMPLETE":c.complete(),c.lufiFile.uploadStatus=1;break}})}),l=async p=>{for(let[v,m]of p.entries()){let g=await m.arrayBuffer();c.requestMessage({action:9,args:{chunk:{buffer:g,index:v},lufiFile:de[a],algo:s}},[g])}};return b.fromPromise(l(u),p=>U(p)).andThen(()=>b.fromPromise(h,p=>U(p)))}).orElse(u=>G(u))}),Fr=(t,e,r,n)=>{n.data.event==="SOCKET_OPENED"&&t(r),n.data.event==="OPERATION_FAILED"&&e(n.data.error)},_n=()=>Object.values(de).filter(t=>t.uploadStatus===4),jn=t=>Object.keys(_n()).indexOf(t);export{Le as CryptoAlgorithm,b as ResultAsync,Q as err,G as errAsync,on as isSecureContext,Tt as lufi,ae as ok,q as okAsync}; diff --git a/themes/default/public/js/worker/cancel.js b/themes/default/public/js/worker/cancel.js index ce4d856..3f90bf2 100644 --- a/themes/default/public/js/worker/cancel.js +++ b/themes/default/public/js/worker/cancel.js @@ -1 +1 @@ -var ze=Object.create;var ee=Object.defineProperty;var Ge=Object.getOwnPropertyDescriptor;var He=Object.getOwnPropertyNames;var $e=Object.getPrototypeOf,qe=Object.prototype.hasOwnProperty;var Ve=(e,t,r)=>t in e?ee(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var Ke=(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 ae=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Ye=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of He(t))!qe.call(e,o)&&o!==r&&ee(e,o,{get:()=>t[o],enumerable:!(n=Ge(t,o))||n.enumerable});return e};var fe=(e,t,r)=>(r=e!=null?ze($e(e)):{},Ye(t||!e||!e.__esModule?ee(r,"default",{value:e,enumerable:!0}):r,e));var b=(e,t,r)=>Ve(e,typeof t!="symbol"?t+"":t,r);var Ee=ae((It,te)=>{"use strict";var T=typeof Reflect=="object"?Reflect:null,ue=T&&typeof T.apply=="function"?T.apply:function(t,r,n){return Function.prototype.apply.call(t,r,n)},V;T&&typeof T.ownKeys=="function"?V=T.ownKeys:Object.getOwnPropertySymbols?V=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:V=function(t){return Object.getOwnPropertyNames(t)};function Ze(e){console&&console.warn&&console.warn(e)}var le=Number.isNaN||function(t){return t!==t};function p(){p.init.call(this)}te.exports=p;te.exports.once=rt;p.EventEmitter=p;p.prototype._events=void 0;p.prototype._eventsCount=0;p.prototype._maxListeners=void 0;var he=10;function K(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||le(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||le(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 de(e){return e._maxListeners===void 0?p.defaultMaxListeners:e._maxListeners}p.prototype.getMaxListeners=function(){return de(this)};p.prototype.emit=function(t){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[t];if(f===void 0)return!1;if(typeof f=="function")ue(f,this,r);else for(var u=f.length,l=ve(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(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=s.length,Ze(a)}return e}p.prototype.addListener=function(t,r){return pe(this,t,r,!1)};p.prototype.on=p.prototype.addListener;p.prototype.prependListener=function(t,r){return pe(this,t,r,!0)};function Qe(){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 me(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},o=Qe.bind(n);return o.listener=r,n.wrapFn=o,o}p.prototype.once=function(t,r){return K(r),this.on(t,me(this,t,r)),this};p.prototype.prependOnceListener=function(t,r){return K(r),this.prependListener(t,me(this,t,r)),this};p.prototype.removeListener=function(t,r){var n,o,i,s,a;if(K(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){a=n[s].listener,i=s;break}if(i<0)return this;i===0?n.shift():et(n,i),n.length===1&&(o[t]=n[0]),o.removeListener!==void 0&&this.emit("removeListener",t,a||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?tt(o):ve(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):ge.call(e,t)};p.prototype.listenerCount=ge;function ge(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?V(this._events):[]};function ve(e,t){for(var r=new Array(t),n=0;n{"use strict";var c={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}}};c.cipher.aes=function(e){this.s[0][0][0]||this.O();var t,r,n,o,i=this.s[0][4],s=this.s[1];t=e.length;var a=1;if(t!==4&&t!==6&&t!==8)throw new c.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^a<<24,a=a<<1^283*(a>>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]]};c.cipher.aes.prototype={encrypt:function(e){return Ce(this,e,0)},decrypt:function(e){return Ce(this,e,1)},s:[[[],[],[],[],[]],[[],[],[],[],[]]],O:function(){var e=this.s[0],t=this.s[1],r=e[4],n=t[4],o,i,s,a=[],f=[],u,l,h,d;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(h=s^s<<1^s<<2^s<<3^s<<4,h=h>>8^h&255^99,r[i]=h,n[h]=i,l=a[o=a[u=a[i]]],d=16843009*l^65537*o^257*u^16843008*i,l=257*a[h]^16843008*h,o=0;4>o;o++)e[o][i]=l=l<<24^l>>>8,t[o][h]=d=d<<24^d>>>8;for(o=0;5>o;o++)e[o]=e[o].slice(0),t[o]=t[o].slice(0)}};function Ce(e,t,r){if(t.length!==4)throw new c.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 a,f,u,l=n.length/4-2,h,d=4,y=[0,0,0,0];a=e.s[r],e=a[0];var g=a[1],M=a[2],$=a[3],q=a[4];for(h=0;h>>24]^g[i>>16&255]^M[s>>8&255]^$[t&255]^n[d],f=e[i>>>24]^g[s>>16&255]^M[t>>8&255]^$[o&255]^n[d+1],u=e[s>>>24]^g[t>>16&255]^M[o>>8&255]^$[i&255]^n[d+2],t=e[t>>>24]^g[o>>16&255]^M[i>>8&255]^$[s&255]^n[d+3],d+=4,o=a,i=f,s=u;for(h=0;4>h;h++)y[r?3&-h:h]=q[o>>>24]<<24^q[i>>16&255]<<16^q[s>>8&255]<<8^q[t&255]^n[d++],a=o,o=i,i=s,s=t,t=a;return y}c.bitArray={bitSlice:function(e,t,r){return e=c.bitArray.$(e.slice(t/32),32-(t&31)).slice(1),r===void 0?e:c.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(c.bitArray.bitLength(e)!==c.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=c.bitArray.getPartial(o),n.push(c.bitArray.partial(t+e&31,32>>24|r>>>8&65280|(r&65280)<<8|r<<24;return e}};c.codec.utf8String={fromBits:function(e){var t="",r=c.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>>s)>>>o),sl){if(!t)try{return c.codec.base32hex.toBits(e)}catch{}throw new c.exception.invalid("this isn't "+h+"!")}a>o?(a-=o,i.push(u^l>>>a),u=l<>>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=c.codec.base64.B,s=0,a;for(t&&(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(e){return c.codec.base64.fromBits(e,1,1)},toBits:function(e){return c.codec.base64.toBits(e,1)}};c.hash.sha256=function(e){this.b[0]||this.O(),e?(this.F=e.F.slice(0),this.A=e.A.slice(0),this.l=e.l):this.reset()};c.hash.sha256.hash=function(e){return new c.hash.sha256().update(e).finalize()};c.hash.sha256.prototype={blockSize:512,reset:function(){return this.F=this.Y.slice(0),this.A=[],this.l=0,this},update:function(e){typeof e=="string"&&(e=c.codec.utf8String.toBits(e));var t,r=this.A=c.bitArray.concat(this.A,e);if(t=this.l,e=this.l=t+c.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.Y[t]=e(Math.pow(r,.5))),this.b[t]=e(Math.pow(r,1/3)),t++)}}};function oe(e,t){var r,n,o,i=e.F,s=e.b,a=i[0],f=i[1],u=i[2],l=i[3],h=i[4],d=i[5],y=i[6],g=i[7];for(r=0;64>r;r++)16>r?n=t[r]:(n=t[r+1&15],o=t[r+14&15],n=t[r&15]=(n>>>7^n>>>18^n>>>3^n<<25^n<<14)+(o>>>17^o>>>19^o>>>10^o<<15^o<<13)+t[r&15]+t[r+9&15]|0),n=n+g+(h>>>6^h>>>11^h>>>25^h<<26^h<<21^h<<7)+(y^h&(d^y))+s[r],g=y,y=d,d=h,h=l+n|0,l=u,u=f,f=a,a=n+(f&u^l&(f^u))+(f>>>2^f>>>13^f>>>22^f<<30^f<<19^f<<10)|0;i[0]=i[0]+a|0,i[1]=i[1]+f|0,i[2]=i[2]+u|0,i[3]=i[3]+l|0,i[4]=i[4]+h|0,i[5]=i[5]+d|0,i[6]=i[6]+y|0,i[7]=i[7]+g|0}c.mode.ccm={name:"ccm",G:[],listenProgress:function(e){c.mode.ccm.G.push(e)},unListenProgress:function(e){e=c.mode.ccm.G.indexOf(e),-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)),t=c.mode.ccm.V(e,t,r,n,o,i),s=c.mode.ccm.C(e,s,r,t,o,i),a.concat(s.data,s.tag)},decrypt:function(e,t,r,n,o){o=o||64,n=n||[];var i=c.bitArray,s=i.bitLength(r)/8,u=i.bitLength(t),a=i.clamp(t,u-o),f=i.bitSlice(t,u-o),u=(u-o)/8;if(7>s)throw new c.exception.invalid("ccm: iv must be at least 7 bytes");for(t=2;4>t&&u>>>8*t;t++);if(t<15-s&&(t=15-s),r=i.clamp(r,8*(15-t)),a=c.mode.ccm.C(e,a,r,f,o,t),e=c.mode.ccm.V(e,a.data,r,n,o,t),!i.equal(a.tag,e))throw new c.exception.corrupt("ccm: tag doesn't match");return a.data},na:function(e,t,r,n,o,i){var s=[],a=c.bitArray,f=a.i;if(n=[a.partial(8,(t.length?64:0)|n-2<<2|i-1)],n=a.concat(n,r),n[3]|=o,n=e.encrypt(n),t.length)for(r=a.bitLength(t)/8,65279>=r?s=[a.partial(16,r)]:4294967295>=r&&(s=a.concat([a.partial(16,65534)],[r])),s=a.concat(s,t),t=0;to||16l&&(c.mode.ccm.fa(s/f),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:a.clamp(t,u)}}};c.mode.ocb2={name:"ocb2",encrypt:function(e,t,r,n,o,i){if(c.bitArray.bitLength(r)!==128)throw new c.exception.invalid("ocb iv must be 128 bits");var s,a=c.mode.ocb2.S,f=c.bitArray,u=f.i,l=[0,0,0,0];r=a(e.encrypt(r));var h,d=[];for(n=n||[],o=o||64,s=0;s+4o.bitLength(r)&&(a=i(a,n(a)),r=o.concat(r,[-2147483648,0,0,0])),s=i(s,r),e.encrypt(i(n(i(a,n(a))),s))},S:function(e){return[e[0]<<1^e[1]>>>31,e[1]<<1^e[2]>>>31,e[2]<<1^e[3]>>>31,e[3]<<1^135*(e[0]>>>31)]}};c.mode.gcm={name:"gcm",encrypt:function(e,t,r,n,o){var i=t.slice(0);return t=c.bitArray,n=n||[],e=c.mode.gcm.C(!0,e,i,n,r,o||128),t.concat(e.data,e.tag)},decrypt:function(e,t,r,n,o){var i=t.slice(0),s=c.bitArray,a=s.bitLength(i);if(o=o||128,n=n||[],o<=a?(t=s.bitSlice(i,a-o),i=s.bitSlice(i,0,a-o)):(t=i,i=[]),e=c.mode.gcm.C(!1,e,i,n,r,o),!s.equal(e.tag,t))throw new c.exception.corrupt("gcm: tag doesn't match");return e.data},ka:function(e,t){var r,n,o,i,s,a=c.bitArray.i;for(o=[0,0,0,0],i=t.slice(0),r=0;128>r;r++){for((n=(e[Math.floor(r/32)]&1<<31-r%32)!==0)&&(o=a(o,i)),s=(i[3]&1)!==0,n=3;0>>1|(i[n-1]&1)<<31;i[0]>>>=1,s&&(i[0]^=-520093696)}return o},j:function(e,t,r){var n,o=r.length;for(t=t.slice(0),n=0;no&&(e=t.hash(e)),n=0;nn||0>r)throw new c.exception.invalid("invalid params to pbkdf2");typeof e=="string"&&(e=c.codec.utf8String.toBits(e)),typeof t=="string"&&(t=c.codec.utf8String.toBits(t)),o=o||c.misc.hmac,e=new o(e);var i,s,a,f,u=[],l=c.bitArray;for(f=1;32*u.length<(n||1);f++){for(o=i=e.encrypt(l.concat(t,[f])),s=1;ss;s++)o.push(4294967296*Math.random()|0);for(s=0;s=1<this.o&&(this.o=i),this.P++,this.b=c.hash.sha256.hash(this.b.concat(o)),this.L=new c.cipher.aes(this.b),n=0;4>n&&(this.h[n]=this.h[n]+1|0,!this.h[n]);n++);}for(n=0;n>>1;this.c[s].update([n,this.N++,2,t,i,e.length].concat(e))}break;case"string":t===void 0&&(t=e.length),this.c[s].update([n,this.N++,3,t,i,e.length]),this.c[s].update(e);break;default:f=1}if(f)throw new c.exception.bug("random: addEntropy only supports number, array of numbers or string");this.m[s]+=t,this.f+=t,a===this.u&&(this.isReady()!==this.u&&Re("seeded",Math.max(this.o,this.f)),Re("progress",this.getProgress()))},isReady:function(e){return e=this.T[e!==void 0?e:this.M],this.o&&this.o>=e?this.m[0]>this.ba&&new Date().valueOf()>this.Z?this.J|this.I:this.I:this.f>=e?this.J|this.u:this.u},getProgress:function(e){return e=this.T[e||this.M],this.o>=e||this.f>e?1:this.f/e},startCollectors:function(){if(!this.D){if(this.a={loadTimeCollector:z(this,this.ma),mouseCollector:z(this,this.oa),keyboardCollector:z(this,this.la),accelerometerCollector:z(this,this.ea),touchCollector:z(this,this.qa)},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(e,t){this.K[e][this.ga++]=t},removeEventListener:function(e,t){var r,n,o=this.K[e],i=[];for(n in o)o.hasOwnProperty(n)&&o[n]===t&&i.push(n);for(r=0;rt&&(e.h[t]=e.h[t]+1|0,!e.h[t]);t++);return e.L.encrypt(e.h)}function z(e,t){return function(){t.apply(e,arguments)}}c.random=new c.prng(6);e:try{if(Z=typeof j<"u"&&j.exports){try{Q=Ke("crypto")}catch{Q=null}Z=Y=Q}if(Z&&Y.randomBytes)G=Y.randomBytes(128),G=new Uint32Array(new Uint8Array(G).buffer),c.random.addEntropy(G,1024,"crypto['randomBytes']");else if(typeof window<"u"&&typeof Uint32Array<"u"){if(H=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(H);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(H);else break e;c.random.addEntropy(H,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 G,Y,H,Z,Q;c.json={defaults:{v:1,iter:1e4,ks:128,ts:64,mode:"ccm",adata:"",cipher:"aes"},ja:function(e,t,r,n){r=r||{},n=n||{};var o=c.json,i=o.g({iv:c.random.randomWords(4,0)},o.defaults),s;if(o.g(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 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 I(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 a(l){try{u(n.next(l))}catch(h){s(h)}}function f(l){try{u(n.throw(l))}catch(h){s(h)}}function u(l){l.done?i(l.value):o(l.value).then(a,f)}u((n=n.apply(e,[])).next())})}function Ae(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 R(e){return this instanceof R?(this.v=e,this):new R(e)}function it(e,t,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=r.apply(e,t||[]),o,i=[];return o={},s("next"),s("throw"),s("return"),o[Symbol.asyncIterator]=function(){return this},o;function s(d){n[d]&&(o[d]=function(y){return new Promise(function(g,M){i.push([d,y,g,M])>1||a(d,y)})})}function a(d,y){try{f(n[d](y))}catch(g){h(i[0][3],g)}}function f(d){d.value instanceof R?Promise.resolve(d.value.v).then(u,l):h(i[0][2],d)}function u(d){a("next",d)}function l(d){a("throw",d)}function h(d,y){d(y),i.shift(),i.length&&a(i[0][0],i[0][1])}}function st(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:R(e[o](s)),done:o==="return"}: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 Ae=="function"?Ae(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(a,f){s=e[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 w=class e{constructor(t){this._promise=t}static fromSafePromise(t){let r=t.then(n=>new L(n));return new e(r)}static fromPromise(t,r){let n=t.then(o=>new L(o)).catch(o=>new x(r(o)));return new e(n)}static fromThrowable(t,r){return(...n)=>new e(I(this,void 0,void 0,function*(){try{return new L(yield t(...n))}catch(o){return new x(r?r(o):o)}}))}static combine(t){return at(t)}static combineWithAllErrors(t){return ft(t)}map(t){return new e(this._promise.then(r=>I(this,void 0,void 0,function*(){return r.isErr()?new x(r.error):new L(yield t(r.value))})))}andThrough(t){return new e(this._promise.then(r=>I(this,void 0,void 0,function*(){if(r.isErr())return new x(r.error);let n=yield t(r.value);return n.isErr()?new x(n.error):new L(r.value)})))}andTee(t){return new e(this._promise.then(r=>I(this,void 0,void 0,function*(){if(r.isErr())return new x(r.error);try{yield t(r.value)}catch{}return new L(r.value)})))}mapErr(t){return new e(this._promise.then(r=>I(this,void 0,void 0,function*(){return r.isOk()?new L(r.value):new x(yield t(r.error))})))}andThen(t){return new e(this._promise.then(r=>{if(r.isErr())return new x(r.error);let n=t(r.value);return n instanceof e?n._promise:n}))}orElse(t){return new e(this._promise.then(r=>I(this,void 0,void 0,function*(){return r.isErr()?t(r.error):new L(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 it(this,arguments,function*(){return yield R(yield R(yield*st(ct(yield R(this._promise.then(r=>r.safeUnwrap()))))))})}then(t,r){return this._promise.then(t,r)}},O=e=>new w(Promise.resolve(new L(e))),E=e=>new w(Promise.resolve(new x(e))),Nt=w.fromPromise,jt=w.fromSafePromise,Wt=w.fromThrowable,xe=e=>{let t=C([]);for(let r of e)if(r.isErr()){t=S(r.error);break}else t.map(n=>n.push(r.value));return t},at=e=>w.fromSafePromise(Promise.all(e)).andThen(xe),Oe=e=>{let t=C([]);for(let r of e)r.isErr()&&t.isErr()?t.error.push(r.error):r.isErr()&&t.isOk()?t=S([r.error]):r.isOk()&&t.isOk()&&t.value.push(r.value);return t},ft=e=>w.fromSafePromise(Promise.all(e)).andThen(Oe),re;(function(e){function t(o,i){return(...s)=>{try{let a=o(...s);return C(a)}catch(a){return S(i?i(a):a)}}}e.fromThrowable=t;function r(o){return xe(o)}e.combine=r;function n(o){return Oe(o)}e.combineWithAllErrors=n})(re||(re={}));var C=e=>new L(e);function S(e){return new x(e)}var L=class{constructor(t){this.value=t}isOk(){return!0}isErr(){return!this.isOk()}map(t){return C(t(this.value))}mapErr(t){return C(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 C(this.value)}orElse(t){return C(this.value)}asyncAndThen(t){return t(this.value)}asyncAndThrough(t){return t(this.value).map(()=>this.value)}asyncMap(t){return w.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 Le("Called `_unsafeUnwrapErr` on an Ok",this,t)}},x=class{constructor(t){this.error=t}isOk(){return!1}isErr(){return!this.isOk()}map(t){return S(this.error)}mapErr(t){return S(t(this.error))}andThrough(t){return S(this.error)}andTee(t){return S(this.error)}andThen(t){return S(this.error)}orElse(t){return t(this.error)}asyncAndThen(t){return E(this.error)}asyncAndThrough(t){return E(this.error)}asyncMap(t){return E(this.error)}unwrapOr(t){return t}match(t,r){return r(this.error)}safeUnwrap(){let t=this.error;return function*(){throw yield S(t),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(t){throw Le("Called `_unsafeUnwrap` on an Err",this,t)}_unsafeUnwrapErr(t){return this.error}},Jt=re.fromThrowable;var k=class extends Error{constructor(r,n={}){let{cause:o,context:i}=n;super(r,{cause:o});b(this,"context");this.name=this.constructor.name,this.context=i}};var P=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 ut=()=>typeof Deno<"u";var U=e=>ut()?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 Se.default,v,De=!1;self.onmessage=e=>{lt(e),De||(De=!0,m.once("OPERATION_FAILED",()=>{v&&v.terminate()}))};var B=(e,t)=>(Object.assign(e,t),typeof WorkerGlobalScope<"u"&&self.postMessage({event:"FILE_UPDATED",lufiFile:e}),e);var lt=(e,t)=>{let{action:r}=e.data;if(r===5||r===8)v.postMessage(e.data);else{switch(r){case 2:v=new Worker(U("cancel"),{type:"module"}),v.postMessage(e.data);break;case 3:v=new Worker(U("download"),{type:"module"}),v.postMessage(e.data);break;case 4:v=new Worker(U("infos"),{type:"module"}),v.postMessage(e.data);break;case 7:v=v||new Worker(U("remove"),{type:"module"}),v.postMessage(e.data);break;case 9:v=v||new Worker(U("upload"),{type:"module"}),v.postMessage(e.data);break;default:console.error("Action not found")}v.onmessage=n=>{t&&t(n),self.postMessage(n.data)},v.onerror=n=>{console.error(`Error: ${n.message}`)}}},ke=()=>{m.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),m.once("OPERATION_FAILED",e=>{self.postMessage({event:"OPERATION_FAILED",error:e})})};var D=class extends k{};var J=class extends D{constructor(){super(...arguments);b(this,"message","An error occured while trying to connect to WebSocket")}};var N=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,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 dt=new N("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");function F(e){return dt.Decode(e)}var pt=new N("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",!0);function ne(e){return pt.Decode(e)}var Ie=fe(Me());var _=class extends k{};var W=class extends _{constructor(){super(...arguments);b(this,"message","Unable to decrypt the provided data")}};var Ue=(e,t)=>{try{let r=typeof t=="string"?t:t.data;return O(F(Ie.default.decrypt(e,r)))}catch(r){return E(new W(void 0,{cause:P(r)}))}};var Be=(e,t)=>gt(e).andThen(r=>w.fromPromise(crypto.subtle.decrypt({name:"AES-GCM",iv:t.iv},r,F(t.data)),n=>new W(void 0,{cause:P(n)})));var gt=e=>w.fromPromise(crypto.subtle.importKey("raw",ne(e),{name:"AES-GCM"},!1,["encrypt","decrypt"]),t=>new _("Unable to import cryptography key",{cause:P(t)}));var Ne=(e,t)=>t.algo===void 0||t.algo===0?Ue(e,t):Be(e,t);var A={},je=5,Et=e=>(m.emit("UPLOAD_CANCELLED",e.success),O(void 0)),At=(e,t)=>{let r=e.split("XXMOJOXX"),n=r.shift();if(n!==void 0){let o=JSON.parse(n);if(Ct(o)){let i=r.shift();if(i){let s=JSON.parse(i);return s.iv&&(s.iv=new Uint8Array(Object.values(s.iv))),Ne(t.keys.client,s).andThen(a=>{let f=typeof a=="string"?new TextEncoder().encode(a).buffer:a;return o.part===0?(B(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")):B(t,{chunksReady:t.chunksReady+1}),m.emit("CHUNK_DOWNLOADED",f,o.part),++o.part===o.total?Dt(t).andThen(()=>(m.emit("DOWNLOAD_COMPLETE"),m.emit("SOCKET_OPERATION_TERMINATED"),O(void 0))):O(void 0)})}else{let s=new D("Can't retrieve metadata from data received by the server");return m.emit("OPERATION_FAILED",s),E(s)}}else{let i=new D(o.msg);return m.emit("OPERATION_FAILED",i),E(i)}}else{let o=new D("Can't retrieve metadata from data received by the server");return m.emit("OPERATION_FAILED",o),E(o)}},Lt=(e,t)=>{if(e.success)return e.j===0&&(B(t,{keys:{client:t.keys.client,server:e.short},actionToken:e.token,queueIndex:e.i}),m.emit("UPLOAD_STARTED")),B(t,{chunksReady:t.chunksReady+1,createdAt:e.created_at}),m.emit("CHUNK_UPLOADED"),t.chunksReady===t.totalChunks&&(B(t,{uploadStatus:1}),m.emit("UPLOAD_COMPLETE"),m.emit("SOCKET_OPERATION_TERMINATED")),O(void 0);{let r=new D(e.msg);return m.emit("OPERATION_FAILED",r),E(r)}},xt=(e,t)=>{let r=_t(e.data),n;if(r)if(!r.action&&r.msg){let o=new D(r.msg);return m.emit("OPERATION_FAILED",o),E(o)}else"delay"in r?n=Lt(r,t):n=Et(r);else n=At(e.data,t);return n},Ot=e=>A!==void 0&&A[e]!==void 0&&A[e].readyState===WebSocket.CONNECTING,se=e=>A!==void 0&&A[e]!==void 0&&A[e].readyState===WebSocket.OPEN,We=e=>ce(kt(e),e,`${JSON.stringify({id:e.keys.server,mod_token:e.actionToken,cancel:!0,i:e.queueIndex})}XXMOJOXXuseless`);var Dt=e=>{let t;return e.password?t={ended:!0,file_pwd:e.password}:t={ended:!0},ce(St(e),e,JSON.stringify(t))};var ce=(e,t,r)=>se(e)?(A[e].onmessage=n=>xt(n,t),A[e].send(r),O(void 0)):Je(e).andThen(()=>ce(e,t,r)),Je=(e,t=0)=>(!se(e)&&!Ot(e)&&(A[e]=new WebSocket(e),m.once("SOCKET_OPERATION_TERMINATED",()=>{A[e].close()}),m.once("OPERATION_FAILED",()=>{m.emit("SOCKET_OPERATION_TERMINATED")}),A[e].onopen=()=>{m.emit("SOCKET_OPENED")},A[e].onclose=()=>{},A[e].onerror=()=>++t<=je?(console.error(`An error happened while trying to connect to WebSocket ${e}. Trying again. ${t} / ${je}`),Je(e,t)):(m.emit("SOCKET_ONERROR"),E(new J(`Unable to connect to WebSocket ${e}.`)))),bt(e).andThen(()=>O(e)).orElse(r=>E(r))),bt=e=>w.fromPromise(new Promise((t,r)=>{se(e)?t(void 0):(m.once("SOCKET_OPENED",()=>{t(void 0)}),m.on("SOCKET_ONERROR",()=>{r(new J)}))}),t=>P(t));var Fe=(e,t)=>{let r=new URL(e);return r.protocol=r.protocol==="http:"?"ws:":"wss:",r.pathname+=t,new URL(r.origin+r.pathname)},St=e=>Fe(new URL(e.serverUrl),"download"+`/${e.keys.server}`).toString(),kt=e=>Fe(new URL(e.serverUrl),"upload").toString(),_t=e=>{try{let t=JSON.parse(e);if(t&&typeof t=="object")return t}catch{}return!1},Ct=e=>typeof e=="object"&&e!==null&&!("msg"in e);var Xe=!1;self.onmessage=e=>{Xe||(ke(),Xe=!0),m.on("UPLOAD_CANCELLED",t=>{self.postMessage({event:"UPLOAD_CANCELLED",success:t})}),Pt(e.data).mapErr(t=>{self.postMessage({event:"OPERATION_FAILED",error:t})})};var Pt=e=>We(e.args.lufiFile); +var Ge=Object.create;var ee=Object.defineProperty;var He=Object.getOwnPropertyDescriptor;var $e=Object.getOwnPropertyNames;var qe=Object.getPrototypeOf,Ve=Object.prototype.hasOwnProperty;var Ke=(e,t,r)=>t in e?ee(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var Ye=(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 ae=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Ze=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of $e(t))!Ve.call(e,o)&&o!==r&&ee(e,o,{get:()=>t[o],enumerable:!(n=He(t,o))||n.enumerable});return e};var fe=(e,t,r)=>(r=e!=null?Ge(qe(e)):{},Ze(t||!e||!e.__esModule?ee(r,"default",{value:e,enumerable:!0}):r,e));var _=(e,t,r)=>Ke(e,typeof t!="symbol"?t+"":t,r);var Ee=ae((Tt,te)=>{"use strict";var U=typeof Reflect=="object"?Reflect:null,ue=U&&typeof U.apply=="function"?U.apply:function(t,r,n){return Function.prototype.apply.call(t,r,n)},V;U&&typeof U.ownKeys=="function"?V=U.ownKeys:Object.getOwnPropertySymbols?V=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:V=function(t){return Object.getOwnPropertyNames(t)};function Qe(e){console&&console.warn&&console.warn(e)}var le=Number.isNaN||function(t){return t!==t};function y(){y.init.call(this)}te.exports=y;te.exports.once=nt;y.EventEmitter=y;y.prototype._events=void 0;y.prototype._eventsCount=0;y.prototype._maxListeners=void 0;var he=10;function K(e){if(typeof e!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}Object.defineProperty(y,"defaultMaxListeners",{enumerable:!0,get:function(){return he},set:function(e){if(typeof e!="number"||e<0||le(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");he=e}});y.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};y.prototype.setMaxListeners=function(t){if(typeof t!="number"||t<0||le(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 de(e){return e._maxListeners===void 0?y.defaultMaxListeners:e._maxListeners}y.prototype.getMaxListeners=function(){return de(this)};y.prototype.emit=function(t){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[t];if(f===void 0)return!1;if(typeof f=="function")ue(f,this,r);else for(var u=f.length,l=ve(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(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=s.length,Qe(a)}return e}y.prototype.addListener=function(t,r){return pe(this,t,r,!1)};y.prototype.on=y.prototype.addListener;y.prototype.prependListener=function(t,r){return pe(this,t,r,!0)};function et(){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 me(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},o=et.bind(n);return o.listener=r,n.wrapFn=o,o}y.prototype.once=function(t,r){return K(r),this.on(t,me(this,t,r)),this};y.prototype.prependOnceListener=function(t,r){return K(r),this.prependListener(t,me(this,t,r)),this};y.prototype.removeListener=function(t,r){var n,o,i,s,a;if(K(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){a=n[s].listener,i=s;break}if(i<0)return this;i===0?n.shift():tt(n,i),n.length===1&&(o[t]=n[0]),o.removeListener!==void 0&&this.emit("removeListener",t,a||r)}return this};y.prototype.off=y.prototype.removeListener;y.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?rt(o):ve(o,o.length)}y.prototype.listeners=function(t){return ye(this,t,!0)};y.prototype.rawListeners=function(t){return ye(this,t,!1)};y.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):ge.call(e,t)};y.prototype.listenerCount=ge;function ge(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}y.prototype.eventNames=function(){return this._eventsCount>0?V(this._events):[]};function ve(e,t){for(var r=new Array(t),n=0;n{"use strict";var c={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}}};c.cipher.aes=function(e){this.s[0][0][0]||this.O();var t,r,n,o,i=this.s[0][4],s=this.s[1];t=e.length;var a=1;if(t!==4&&t!==6&&t!==8)throw new c.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^a<<24,a=a<<1^283*(a>>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]]};c.cipher.aes.prototype={encrypt:function(e){return Re(this,e,0)},decrypt:function(e){return Re(this,e,1)},s:[[[],[],[],[],[]],[[],[],[],[],[]]],O:function(){var e=this.s[0],t=this.s[1],r=e[4],n=t[4],o,i,s,a=[],f=[],u,l,h,p;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(h=s^s<<1^s<<2^s<<3^s<<4,h=h>>8^h&255^99,r[i]=h,n[h]=i,l=a[o=a[u=a[i]]],p=16843009*l^65537*o^257*u^16843008*i,l=257*a[h]^16843008*h,o=0;4>o;o++)e[o][i]=l=l<<24^l>>>8,t[o][h]=p=p<<24^p>>>8;for(o=0;5>o;o++)e[o]=e[o].slice(0),t[o]=t[o].slice(0)}};function Re(e,t,r){if(t.length!==4)throw new c.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 a,f,u,l=n.length/4-2,h,p=4,d=[0,0,0,0];a=e.s[r],e=a[0];var m=a[1],S=a[2],I=a[3],T=a[4];for(h=0;h>>24]^m[i>>16&255]^S[s>>8&255]^I[t&255]^n[p],f=e[i>>>24]^m[s>>16&255]^S[t>>8&255]^I[o&255]^n[p+1],u=e[s>>>24]^m[t>>16&255]^S[o>>8&255]^I[i&255]^n[p+2],t=e[t>>>24]^m[o>>16&255]^S[i>>8&255]^I[s&255]^n[p+3],p+=4,o=a,i=f,s=u;for(h=0;4>h;h++)d[r?3&-h:h]=T[o>>>24]<<24^T[i>>16&255]<<16^T[s>>8&255]<<8^T[t&255]^n[p++],a=o,o=i,i=s,s=t,t=a;return d}c.bitArray={bitSlice:function(e,t,r){return e=c.bitArray.$(e.slice(t/32),32-(t&31)).slice(1),r===void 0?e:c.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(c.bitArray.bitLength(e)!==c.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=c.bitArray.getPartial(o),n.push(c.bitArray.partial(t+e&31,32>>24|r>>>8&65280|(r&65280)<<8|r<<24;return e}};c.codec.utf8String={fromBits:function(e){var t="",r=c.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>>s)>>>o),sl){if(!t)try{return c.codec.base32hex.toBits(e)}catch{}throw new c.exception.invalid("this isn't "+h+"!")}a>o?(a-=o,i.push(u^l>>>a),u=l<>>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=c.codec.base64.B,s=0,a;for(t&&(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(e){return c.codec.base64.fromBits(e,1,1)},toBits:function(e){return c.codec.base64.toBits(e,1)}};c.hash.sha256=function(e){this.b[0]||this.O(),e?(this.F=e.F.slice(0),this.A=e.A.slice(0),this.l=e.l):this.reset()};c.hash.sha256.hash=function(e){return new c.hash.sha256().update(e).finalize()};c.hash.sha256.prototype={blockSize:512,reset:function(){return this.F=this.Y.slice(0),this.A=[],this.l=0,this},update:function(e){typeof e=="string"&&(e=c.codec.utf8String.toBits(e));var t,r=this.A=c.bitArray.concat(this.A,e);if(t=this.l,e=this.l=t+c.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.Y[t]=e(Math.pow(r,.5))),this.b[t]=e(Math.pow(r,1/3)),t++)}}};function oe(e,t){var r,n,o,i=e.F,s=e.b,a=i[0],f=i[1],u=i[2],l=i[3],h=i[4],p=i[5],d=i[6],m=i[7];for(r=0;64>r;r++)16>r?n=t[r]:(n=t[r+1&15],o=t[r+14&15],n=t[r&15]=(n>>>7^n>>>18^n>>>3^n<<25^n<<14)+(o>>>17^o>>>19^o>>>10^o<<15^o<<13)+t[r&15]+t[r+9&15]|0),n=n+m+(h>>>6^h>>>11^h>>>25^h<<26^h<<21^h<<7)+(d^h&(p^d))+s[r],m=d,d=p,p=h,h=l+n|0,l=u,u=f,f=a,a=n+(f&u^l&(f^u))+(f>>>2^f>>>13^f>>>22^f<<30^f<<19^f<<10)|0;i[0]=i[0]+a|0,i[1]=i[1]+f|0,i[2]=i[2]+u|0,i[3]=i[3]+l|0,i[4]=i[4]+h|0,i[5]=i[5]+p|0,i[6]=i[6]+d|0,i[7]=i[7]+m|0}c.mode.ccm={name:"ccm",G:[],listenProgress:function(e){c.mode.ccm.G.push(e)},unListenProgress:function(e){e=c.mode.ccm.G.indexOf(e),-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)),t=c.mode.ccm.V(e,t,r,n,o,i),s=c.mode.ccm.C(e,s,r,t,o,i),a.concat(s.data,s.tag)},decrypt:function(e,t,r,n,o){o=o||64,n=n||[];var i=c.bitArray,s=i.bitLength(r)/8,u=i.bitLength(t),a=i.clamp(t,u-o),f=i.bitSlice(t,u-o),u=(u-o)/8;if(7>s)throw new c.exception.invalid("ccm: iv must be at least 7 bytes");for(t=2;4>t&&u>>>8*t;t++);if(t<15-s&&(t=15-s),r=i.clamp(r,8*(15-t)),a=c.mode.ccm.C(e,a,r,f,o,t),e=c.mode.ccm.V(e,a.data,r,n,o,t),!i.equal(a.tag,e))throw new c.exception.corrupt("ccm: tag doesn't match");return a.data},na:function(e,t,r,n,o,i){var s=[],a=c.bitArray,f=a.i;if(n=[a.partial(8,(t.length?64:0)|n-2<<2|i-1)],n=a.concat(n,r),n[3]|=o,n=e.encrypt(n),t.length)for(r=a.bitLength(t)/8,65279>=r?s=[a.partial(16,r)]:4294967295>=r&&(s=a.concat([a.partial(16,65534)],[r])),s=a.concat(s,t),t=0;to||16l&&(c.mode.ccm.fa(s/f),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:a.clamp(t,u)}}};c.mode.ocb2={name:"ocb2",encrypt:function(e,t,r,n,o,i){if(c.bitArray.bitLength(r)!==128)throw new c.exception.invalid("ocb iv must be 128 bits");var s,a=c.mode.ocb2.S,f=c.bitArray,u=f.i,l=[0,0,0,0];r=a(e.encrypt(r));var h,p=[];for(n=n||[],o=o||64,s=0;s+4o.bitLength(r)&&(a=i(a,n(a)),r=o.concat(r,[-2147483648,0,0,0])),s=i(s,r),e.encrypt(i(n(i(a,n(a))),s))},S:function(e){return[e[0]<<1^e[1]>>>31,e[1]<<1^e[2]>>>31,e[2]<<1^e[3]>>>31,e[3]<<1^135*(e[0]>>>31)]}};c.mode.gcm={name:"gcm",encrypt:function(e,t,r,n,o){var i=t.slice(0);return t=c.bitArray,n=n||[],e=c.mode.gcm.C(!0,e,i,n,r,o||128),t.concat(e.data,e.tag)},decrypt:function(e,t,r,n,o){var i=t.slice(0),s=c.bitArray,a=s.bitLength(i);if(o=o||128,n=n||[],o<=a?(t=s.bitSlice(i,a-o),i=s.bitSlice(i,0,a-o)):(t=i,i=[]),e=c.mode.gcm.C(!1,e,i,n,r,o),!s.equal(e.tag,t))throw new c.exception.corrupt("gcm: tag doesn't match");return e.data},ka:function(e,t){var r,n,o,i,s,a=c.bitArray.i;for(o=[0,0,0,0],i=t.slice(0),r=0;128>r;r++){for((n=(e[Math.floor(r/32)]&1<<31-r%32)!==0)&&(o=a(o,i)),s=(i[3]&1)!==0,n=3;0>>1|(i[n-1]&1)<<31;i[0]>>>=1,s&&(i[0]^=-520093696)}return o},j:function(e,t,r){var n,o=r.length;for(t=t.slice(0),n=0;no&&(e=t.hash(e)),n=0;nn||0>r)throw new c.exception.invalid("invalid params to pbkdf2");typeof e=="string"&&(e=c.codec.utf8String.toBits(e)),typeof t=="string"&&(t=c.codec.utf8String.toBits(t)),o=o||c.misc.hmac,e=new o(e);var i,s,a,f,u=[],l=c.bitArray;for(f=1;32*u.length<(n||1);f++){for(o=i=e.encrypt(l.concat(t,[f])),s=1;ss;s++)o.push(4294967296*Math.random()|0);for(s=0;s=1<this.o&&(this.o=i),this.P++,this.b=c.hash.sha256.hash(this.b.concat(o)),this.L=new c.cipher.aes(this.b),n=0;4>n&&(this.h[n]=this.h[n]+1|0,!this.h[n]);n++);}for(n=0;n>>1;this.c[s].update([n,this.N++,2,t,i,e.length].concat(e))}break;case"string":t===void 0&&(t=e.length),this.c[s].update([n,this.N++,3,t,i,e.length]),this.c[s].update(e);break;default:f=1}if(f)throw new c.exception.bug("random: addEntropy only supports number, array of numbers or string");this.m[s]+=t,this.f+=t,a===this.u&&(this.isReady()!==this.u&&Pe("seeded",Math.max(this.o,this.f)),Pe("progress",this.getProgress()))},isReady:function(e){return e=this.T[e!==void 0?e:this.M],this.o&&this.o>=e?this.m[0]>this.ba&&new Date().valueOf()>this.Z?this.J|this.I:this.I:this.f>=e?this.J|this.u:this.u},getProgress:function(e){return e=this.T[e||this.M],this.o>=e||this.f>e?1:this.f/e},startCollectors:function(){if(!this.D){if(this.a={loadTimeCollector:H(this,this.ma),mouseCollector:H(this,this.oa),keyboardCollector:H(this,this.la),accelerometerCollector:H(this,this.ea),touchCollector:H(this,this.qa)},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(e,t){this.K[e][this.ga++]=t},removeEventListener:function(e,t){var r,n,o=this.K[e],i=[];for(n in o)o.hasOwnProperty(n)&&o[n]===t&&i.push(n);for(r=0;rt&&(e.h[t]=e.h[t]+1|0,!e.h[t]);t++);return e.L.encrypt(e.h)}function H(e,t){return function(){t.apply(e,arguments)}}c.random=new c.prng(6);e:try{if(Z=typeof J<"u"&&J.exports){try{Q=Ye("crypto")}catch{Q=null}Z=Y=Q}if(Z&&Y.randomBytes)$=Y.randomBytes(128),$=new Uint32Array(new Uint8Array($).buffer),c.random.addEntropy($,1024,"crypto['randomBytes']");else if(typeof window<"u"&&typeof Uint32Array<"u"){if(q=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(q);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(q);else break e;c.random.addEntropy(q,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 $,Y,q,Z,Q;c.json={defaults:{v:1,iter:1e4,ks:128,ts:64,mode:"ccm",adata:"",cipher:"aes"},ja:function(e,t,r,n){r=r||{},n=n||{};var o=c.json,i=o.g({iv:c.random.randomWords(4,0)},o.defaults),s;if(o.g(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 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 B(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 a(l){try{u(n.next(l))}catch(h){s(h)}}function f(l){try{u(n.throw(l))}catch(h){s(h)}}function u(l){l.done?i(l.value):o(l.value).then(a,f)}u((n=n.apply(e,t||[])).next())})}function Ae(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 O(e){return this instanceof O?(this.v=e,this):new O(e)}function Le(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),a("next"),a("throw"),a("return",s),o[Symbol.asyncIterator]=function(){return this},o;function s(d){return function(m){return Promise.resolve(m).then(d,h)}}function a(d,m){n[d]&&(o[d]=function(S){return new Promise(function(I,T){i.push([d,S,I,T])>1||f(d,S)})},m&&(o[d]=m(o[d])))}function f(d,m){try{u(n[d](m))}catch(S){p(i[0][3],S)}}function u(d){d.value instanceof O?Promise.resolve(d.value.v).then(l,h):p(i[0][2],d)}function l(d){f("next",d)}function h(d){f("throw",d)}function p(d,m){d(m),i.shift(),i.length&&f(i[0][0],i[0][1])}}function st(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:O(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 Ae=="function"?Ae(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(a,f){s=e[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 E=class e{constructor(t){this._promise=t}static fromSafePromise(t){let r=t.then(n=>new L(n));return new e(r)}static fromPromise(t,r){let n=t.then(o=>new L(o)).catch(o=>new x(r(o)));return new e(n)}static fromThrowable(t,r){return(...n)=>new e(B(this,void 0,void 0,function*(){try{return new L(yield t(...n))}catch(o){return new x(r?r(o):o)}}))}static combine(t){return at(t)}static combineWithAllErrors(t){return ft(t)}map(t){return new e(this._promise.then(r=>B(this,void 0,void 0,function*(){return r.isErr()?new x(r.error):new L(yield t(r.value))})))}andThrough(t){return new e(this._promise.then(r=>B(this,void 0,void 0,function*(){if(r.isErr())return new x(r.error);let n=yield t(r.value);return n.isErr()?new x(n.error):new L(r.value)})))}andTee(t){return new e(this._promise.then(r=>B(this,void 0,void 0,function*(){if(r.isErr())return new x(r.error);try{yield t(r.value)}catch{}return new L(r.value)})))}mapErr(t){return new e(this._promise.then(r=>B(this,void 0,void 0,function*(){return r.isOk()?new L(r.value):new x(yield t(r.error))})))}andThen(t){return new e(this._promise.then(r=>{if(r.isErr())return new x(r.error);let n=t(r.value);return n instanceof e?n._promise:n}))}orElse(t){return new e(this._promise.then(r=>B(this,void 0,void 0,function*(){return r.isErr()?t(r.error):new L(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 Le(this,arguments,function*(){return yield O(yield O(yield*st(ct(yield O(this._promise.then(r=>r.safeUnwrap()))))))})}then(t,r){return this._promise.then(t,r)}[Symbol.asyncIterator](){return Le(this,arguments,function*(){let r=yield O(this._promise);return r.isErr()&&(yield yield O(w(r.error))),yield O(r.value)})}},D=e=>new E(Promise.resolve(new L(e))),w=e=>new E(Promise.resolve(new x(e))),Nt=E.fromPromise,jt=E.fromSafePromise,Wt=E.fromThrowable,Oe=e=>{let t=P([]);for(let r of e)if(r.isErr()){t=k(r.error);break}else t.map(n=>n.push(r.value));return t},at=e=>E.fromSafePromise(Promise.all(e)).andThen(Oe),De=e=>{let t=P([]);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},ft=e=>E.fromSafePromise(Promise.all(e)).andThen(De),re;(function(e){function t(o,i){return(...s)=>{try{let a=o(...s);return P(a)}catch(a){return k(i?i(a):a)}}}e.fromThrowable=t;function r(o){return Oe(o)}e.combine=r;function n(o){return De(o)}e.combineWithAllErrors=n})(re||(re={}));var P=e=>new L(e);function k(e){return new x(e)}var L=class{constructor(t){this.value=t}isOk(){return!0}isErr(){return!this.isOk()}map(t){return P(t(this.value))}mapErr(t){return P(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 P(this.value)}orElse(t){return P(this.value)}asyncAndThen(t){return t(this.value)}asyncAndThrough(t){return t(this.value).map(()=>this.value)}asyncMap(t){return E.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 xe("Called `_unsafeUnwrapErr` on an Ok",this,t)}*[Symbol.iterator](){return this.value}},x=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 w(this.error)}asyncAndThrough(t){return w(this.error)}asyncMap(t){return w(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 xe("Called `_unsafeUnwrap` on an Err",this,t)}_unsafeUnwrapErr(t){return this.error}*[Symbol.iterator](){let t=this;return yield t,t}},Jt=re.fromThrowable;var C=class extends Error{constructor(r,n={}){let{cause:o,context:i}=n;super(r,{cause:o});_(this,"context");this.name=this.constructor.name,this.context=i}};var M=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 ut=()=>typeof Deno<"u";var N=e=>ut()?new URL(`./worker/${e}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${e==="main"?`worker/${e}`:e}.js`));var g=new _e.default,v,be=!1;self.onmessage=e=>{lt(e),be||(be=!0,g.once("OPERATION_FAILED",()=>{v&&v.terminate()}))};var j=(e,t)=>(Object.assign(e,t),typeof WorkerGlobalScope<"u"&&self.postMessage({event:"FILE_UPDATED",lufiFile:e}),e);var lt=(e,t)=>{let{action:r}=e.data;if(r===5||r===8)v.postMessage(e.data);else{switch(r){case 2:v=new Worker(N("cancel"),{type:"module"}),v.postMessage(e.data);break;case 3:v=new Worker(N("download"),{type:"module"}),v.postMessage(e.data);break;case 4:v=new Worker(N("infos"),{type:"module"}),v.postMessage(e.data);break;case 7:v=v||new Worker(N("remove"),{type:"module"}),v.postMessage(e.data);break;case 9:v=v||new Worker(N("upload"),{type:"module"}),v.postMessage(e.data);break;default:console.error("Action not found")}v.onmessage=n=>{t&&t(n),self.postMessage(n.data)},v.onerror=n=>{console.error(`Error: ${n.message}`)}}},ke=()=>{g.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),g.once("OPERATION_FAILED",e=>{self.postMessage({event:"OPERATION_FAILED",error:e})})};var b=class extends C{};var X=class extends b{constructor(){super(...arguments);_(this,"message","An error occured while trying to connect to WebSocket")}};var W=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,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 dt=new W("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");function z(e){return dt.Decode(e)}var pt=new W("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",!0);function ne(e){return pt.Decode(e)}var Ue=fe(Ie());var R=class extends C{};var F=class extends R{constructor(){super(...arguments);_(this,"message","Unable to decrypt the provided data")}};var Be=(e,t)=>{try{let r=typeof t=="string"?t:t.data;return D(z(Ue.default.decrypt(e,r)))}catch(r){return w(new F(void 0,{cause:M(r)}))}};var Ne=(e,t)=>gt(e).andThen(r=>E.fromPromise(crypto.subtle.decrypt({name:"AES-GCM",iv:t.iv},r,z(t.data)),n=>new F(void 0,{cause:M(n)})));var gt=e=>E.fromPromise(crypto.subtle.importKey("raw",ne(e),{name:"AES-GCM"},!1,["encrypt","decrypt"]),t=>new R("Unable to import cryptography key",{cause:M(t)}));var je=(e,t)=>t.algo===void 0||t.algo===0?Be(e,t):Ne(e,t);var A={},We=5,Et=e=>(g.emit("UPLOAD_CANCELLED",e.success),D(void 0)),At=(e,t)=>{let r=e.split("XXMOJOXX"),n=r.shift();if(n!==void 0){let o=JSON.parse(n);if(Ct(o)){let i=r.shift();if(i){let s=JSON.parse(i);return s.iv&&(s.iv=new Uint8Array(Object.values(s.iv))),je(t.keys.client,s).andThen(a=>{let f=typeof a=="string"?new TextEncoder().encode(a).buffer:a;return o.part===0?(j(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")):j(t,{chunksReady:t.chunksReady+1}),g.emit("CHUNK_DOWNLOADED",f,o.part),++o.part===o.total?Dt(t).andThen(()=>(g.emit("DOWNLOAD_COMPLETE"),g.emit("SOCKET_OPERATION_TERMINATED"),D(void 0))):D(void 0)})}else{let s=new b("Can't retrieve metadata from data received by the server");return g.emit("OPERATION_FAILED",s),w(s)}}else{let i=new b(o.msg);return g.emit("OPERATION_FAILED",i),w(i)}}else{let o=new b("Can't retrieve metadata from data received by the server");return g.emit("OPERATION_FAILED",o),w(o)}},Lt=(e,t)=>{if(e.success)return e.j===0&&(j(t,{keys:{client:t.keys.client,server:e.short},actionToken:e.token,queueIndex:e.i}),g.emit("UPLOAD_STARTED")),j(t,{chunksReady:t.chunksReady+1,createdAt:e.created_at}),g.emit("CHUNK_UPLOADED"),t.chunksReady===t.totalChunks&&(j(t,{uploadStatus:1}),g.emit("UPLOAD_COMPLETE"),g.emit("SOCKET_OPERATION_TERMINATED")),D(void 0);{let r=new b(e.msg);return g.emit("OPERATION_FAILED",r),w(r)}},xt=(e,t)=>{let r=kt(e.data),n;if(r)if(!r.action&&r.msg){let o=new b(r.msg);return g.emit("OPERATION_FAILED",o),w(o)}else"delay"in r?n=Lt(r,t):n=Et(r);else n=At(e.data,t);return n},Ot=e=>A!==void 0&&A[e]!==void 0&&A[e].readyState===WebSocket.CONNECTING,se=e=>A!==void 0&&A[e]!==void 0&&A[e].readyState===WebSocket.OPEN,Je=e=>ce(_t(e),e,`${JSON.stringify({id:e.keys.server,mod_token:e.actionToken,cancel:!0,i:e.queueIndex})}XXMOJOXXuseless`);var Dt=e=>{let t;return e.password?t={ended:!0,file_pwd:e.password}:t={ended:!0},ce(St(e),e,JSON.stringify(t))};var ce=(e,t,r)=>se(e)?(A[e].onmessage=n=>xt(n,t),A[e].send(r),D(void 0)):Fe(e).andThen(()=>ce(e,t,r)),Fe=(e,t=0)=>(!se(e)&&!Ot(e)&&(A[e]=new WebSocket(e),g.once("SOCKET_OPERATION_TERMINATED",()=>{A[e].close()}),g.once("OPERATION_FAILED",()=>{g.emit("SOCKET_OPERATION_TERMINATED")}),A[e].onopen=()=>{g.emit("SOCKET_OPENED")},A[e].onclose=()=>{},A[e].onerror=()=>++t<=We?(console.error(`An error happened while trying to connect to WebSocket ${e}. Trying again. ${t} / ${We}`),Fe(e,t)):(g.emit("SOCKET_ONERROR"),w(new X(`Unable to connect to WebSocket ${e}.`)))),bt(e).andThen(()=>D(e)).orElse(r=>w(r))),bt=e=>E.fromPromise(new Promise((t,r)=>{se(e)?t(void 0):(g.once("SOCKET_OPENED",()=>{t(void 0)}),g.on("SOCKET_ONERROR",()=>{r(new X)}))}),t=>M(t));var Xe=(e,t)=>{let r=new URL(e);return r.protocol=r.protocol==="http:"?"ws:":"wss:",r.pathname+=t,new URL(r.origin+r.pathname)},St=e=>Xe(new URL(e.serverUrl),"download"+`/${e.keys.server}`).toString(),_t=e=>Xe(new URL(e.serverUrl),"upload").toString(),kt=e=>{try{let t=JSON.parse(e);if(t&&typeof t=="object")return t}catch{}return!1},Ct=e=>typeof e=="object"&&e!==null&&!("msg"in e);var ze=!1;self.onmessage=e=>{ze||(ke(),ze=!0),g.on("UPLOAD_CANCELLED",t=>{self.postMessage({event:"UPLOAD_CANCELLED",success:t})}),Pt(e.data).mapErr(t=>{self.postMessage({event:"OPERATION_FAILED",error:t})})};var Pt=e=>Je(e.args.lufiFile); diff --git a/themes/default/public/js/worker/download.js b/themes/default/public/js/worker/download.js index 9ce6315..a16a4e5 100644 --- a/themes/default/public/js/worker/download.js +++ b/themes/default/public/js/worker/download.js @@ -1 +1 @@ -var $t=Object.create;var Re=Object.defineProperty;var Ht=Object.getOwnPropertyDescriptor;var Xt=Object.getOwnPropertyNames;var Gt=Object.getPrototypeOf,Vt=Object.prototype.hasOwnProperty;var et=t=>{throw TypeError(t)};var Yt=(t,e,r)=>e in t?Re(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var Kt=(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 Qt=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Xt(e))!Vt.call(t,o)&&o!==r&&Re(t,o,{get:()=>e[o],enumerable:!(n=Ht(e,o))||n.enumerable});return t};var Ne=(t,e,r)=>(r=t!=null?$t(Gt(t)):{},Qt(e||!t||!t.__esModule?Re(r,"default",{value:t,enumerable:!0}):r,t));var R=(t,e,r)=>Yt(t,typeof e!="symbol"?e+"":e,r),Ue=(t,e,r)=>e.has(t)||et("Cannot "+r);var p=(t,e,r)=>(Ue(t,e,"read from private field"),r?r.call(t):e.get(t)),A=(t,e,r)=>e.has(t)?et("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),E=(t,e,r,n)=>(Ue(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),x=(t,e,r)=>(Ue(t,e,"access private method"),r);var Ae=(t,e,r,n)=>({set _(o){E(t,e,o,r)},get _(){return p(t,e,n)}});var ht=Me((jr,Be)=>{"use strict";var G=typeof Reflect=="object"?Reflect:null,tt=G&&typeof G.apply=="function"?G.apply:function(e,r,n){return Function.prototype.apply.call(e,r,n)},xe;G&&typeof G.ownKeys=="function"?xe=G.ownKeys:Object.getOwnPropertySymbols?xe=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:xe=function(e){return Object.getOwnPropertyNames(e)};function Zt(t){console&&console.warn&&console.warn(t)}var nt=Number.isNaN||function(e){return e!==e};function g(){g.init.call(this)}Be.exports=g;Be.exports.once=nr;g.EventEmitter=g;g.prototype._events=void 0;g.prototype._eventsCount=0;g.prototype._maxListeners=void 0;var rt=10;function Le(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 rt},set:function(t){if(typeof t!="number"||t<0||nt(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");rt=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||nt(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 ot(t){return t._maxListeners===void 0?g.defaultMaxListeners:t._maxListeners}g.prototype.getMaxListeners=function(){return ot(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")tt(u,this,r);else for(var f=u.length,l=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,Zt(c)}return t}g.prototype.addListener=function(e,r){return it(this,e,r,!1)};g.prototype.on=g.prototype.addListener;g.prototype.prependListener=function(e,r){return it(this,e,r,!0)};function er(){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 st(t,e,r){var n={fired:!1,wrapFn:void 0,target:t,type:e,listener:r},o=er.bind(n);return o.listener=r,n.wrapFn=o,o}g.prototype.once=function(e,r){return Le(r),this.on(e,st(this,e,r)),this};g.prototype.prependOnceListener=function(e,r){return Le(r),this.prependListener(e,st(this,e,r)),this};g.prototype.removeListener=function(e,r){var n,o,i,s,c;if(Le(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():tr(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 at(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?rr(o):ut(o,o.length)}g.prototype.listeners=function(e){return at(this,e,!0)};g.prototype.rawListeners=function(e){return at(this,e,!1)};g.listenerCount=function(t,e){return typeof t.listenerCount=="function"?t.listenerCount(e):ct.call(t,e)};g.prototype.listenerCount=ct;function ct(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?xe(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.s[0][0][0]||this.O();var e,r,n,o,i=this.s[0][4],s=this.s[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 xt(this,t,0)},decrypt:function(t){return xt(this,t,1)},s:[[[],[],[],[],[]],[[],[],[],[],[]]],O:function(){var t=this.s[0],e=this.s[1],r=t[4],n=e[4],o,i,s,c=[],u=[],f,l,h,d;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]]],d=16843009*l^65537*o^257*f^16843008*i,l=257*c[h]^16843008*h,o=0;4>o;o++)t[o][i]=l=l<<24^l>>>8,e[o][h]=d=d<<24^d>>>8;for(o=0;5>o;o++)t[o]=t[o].slice(0),e[o]=e[o].slice(0)}};function xt(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,l=n.length/4-2,h,d=4,m=[0,0,0,0];c=t.s[r],t=c[0];var w=c[1],X=c[2],we=c[3],Ee=c[4];for(h=0;h>>24]^w[i>>16&255]^X[s>>8&255]^we[e&255]^n[d],u=t[i>>>24]^w[s>>16&255]^X[e>>8&255]^we[o&255]^n[d+1],f=t[s>>>24]^w[e>>16&255]^X[o>>8&255]^we[i&255]^n[d+2],e=t[e>>>24]^w[o>>16&255]^X[i>>8&255]^we[s&255]^n[d+3],d+=4,o=c,i=u,s=f;for(h=0;4>h;h++)m[r?3&-h:h]=Ee[o>>>24]<<24^Ee[i>>16&255]<<16^Ee[s>>8&255]<<8^Ee[e&255]^n[d++],c=o,o=i,i=s,s=e,e=c;return m}a.bitArray={bitSlice:function(t,e,r){return t=a.bitArray.$(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>>s)>>>o),sl){if(!e)try{return a.codec.base32hex.toBits(t)}catch{}throw new a.exception.invalid("this isn't "+h+"!")}c>o?(c-=o,i.push(f^l>>>c),f=l<>>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.B,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.O(),t?(this.F=t.F.slice(0),this.A=t.A.slice(0),this.l=t.l):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.F=this.Y.slice(0),this.A=[],this.l=0,this},update:function(t){typeof t=="string"&&(t=a.codec.utf8String.toBits(t));var e,r=this.A=a.bitArray.concat(this.A,t);if(e=this.l,t=this.l=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.Y[e]=t(Math.pow(r,.5))),this.b[e]=t(Math.pow(r,1/3)),e++)}}};function Fe(t,e){var r,n,o,i=t.F,s=t.b,c=i[0],u=i[1],f=i[2],l=i[3],h=i[4],d=i[5],m=i[6],w=i[7];for(r=0;64>r;r++)16>r?n=e[r]:(n=e[r+1&15],o=e[r+14&15],n=e[r&15]=(n>>>7^n>>>18^n>>>3^n<<25^n<<14)+(o>>>17^o>>>19^o>>>10^o<<15^o<<13)+e[r&15]+e[r+9&15]|0),n=n+w+(h>>>6^h>>>11^h>>>25^h<<26^h<<21^h<<7)+(m^h&(d^m))+s[r],w=m,m=d,d=h,h=l+n|0,l=f,f=u,u=c,c=n+(u&f^l&(u^f))+(u>>>2^u>>>13^u>>>22^u<<30^u<<19^u<<10)|0;i[0]=i[0]+c|0,i[1]=i[1]+u|0,i[2]=i[2]+f|0,i[3]=i[3]+l|0,i[4]=i[4]+h|0,i[5]=i[5]+d|0,i[6]=i[6]+m|0,i[7]=i[7]+w|0}a.mode.ccm={name:"ccm",G:[],listenProgress:function(t){a.mode.ccm.G.push(t)},unListenProgress:function(t){t=a.mode.ccm.G.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.V(t,e,r,n,o,i),s=a.mode.ccm.C(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.C(t,c,r,u,o,e),t=a.mode.ccm.V(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},na:function(t,e,r,n,o,i){var s=[],c=a.bitArray,u=c.i;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||16l&&(a.mode.ccm.fa(s/u),l+=h),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.mode.ocb2={name:"ocb2",encrypt:function(t,e,r,n,o,i){if(a.bitArray.bitLength(r)!==128)throw new a.exception.invalid("ocb iv must be 128 bits");var s,c=a.mode.ocb2.S,u=a.bitArray,f=u.i,l=[0,0,0,0];r=c(t.encrypt(r));var h,d=[];for(n=n||[],o=o||64,s=0;s+4o.bitLength(r)&&(c=i(c,n(c)),r=o.concat(r,[-2147483648,0,0,0])),s=i(s,r),t.encrypt(i(n(i(c,n(c))),s))},S:function(t){return[t[0]<<1^t[1]>>>31,t[1]<<1^t[2]>>>31,t[2]<<1^t[3]>>>31,t[3]<<1^135*(t[0]>>>31)]}};a.mode.gcm={name:"gcm",encrypt:function(t,e,r,n,o){var i=e.slice(0);return e=a.bitArray,n=n||[],t=a.mode.gcm.C(!0,t,i,n,r,o||128),e.concat(t.data,t.tag)},decrypt:function(t,e,r,n,o){var i=e.slice(0),s=a.bitArray,c=s.bitLength(i);if(o=o||128,n=n||[],o<=c?(e=s.bitSlice(i,c-o),i=s.bitSlice(i,0,c-o)):(e=i,i=[]),t=a.mode.gcm.C(!1,t,i,n,r,o),!s.equal(t.tag,e))throw new a.exception.corrupt("gcm: tag doesn't match");return t.data},ka:function(t,e){var r,n,o,i,s,c=a.bitArray.i;for(o=[0,0,0,0],i=e.slice(0),r=0;128>r;r++){for((n=(t[Math.floor(r/32)]&1<<31-r%32)!==0)&&(o=c(o,i)),s=(i[3]&1)!==0,n=3;0>>1|(i[n-1]&1)<<31;i[0]>>>=1,s&&(i[0]^=-520093696)}return o},j:function(t,e,r){var n,o=r.length;for(e=e.slice(0),n=0;no&&(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=[],l=a.bitArray;for(u=1;32*f.length<(n||1);u++){for(o=i=t.encrypt(l.concat(e,[u])),s=1;ss;s++)o.push(4294967296*Math.random()|0);for(s=0;s=1<this.o&&(this.o=i),this.P++,this.b=a.hash.sha256.hash(this.b.concat(o)),this.L=new a.cipher.aes(this.b),n=0;4>n&&(this.h[n]=this.h[n]+1|0,!this.h[n]);n++);}for(n=0;n>>1;this.c[s].update([n,this.N++,2,e,i,t.length].concat(t))}break;case"string":e===void 0&&(e=t.length),this.c[s].update([n,this.N++,3,e,i,t.length]),this.c[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.m[s]+=e,this.f+=e,c===this.u&&(this.isReady()!==this.u&&Lt("seeded",Math.max(this.o,this.f)),Lt("progress",this.getProgress()))},isReady:function(t){return t=this.T[t!==void 0?t:this.M],this.o&&this.o>=t?this.m[0]>this.ba&&new Date().valueOf()>this.Z?this.J|this.I:this.I:this.f>=t?this.J|this.u:this.u},getProgress:function(t){return t=this.T[t||this.M],this.o>=t||this.f>t?1:this.f/t},startCollectors:function(){if(!this.D){if(this.a={loadTimeCollector:ce(this,this.ma),mouseCollector:ce(this,this.oa),keyboardCollector:ce(this,this.la),accelerometerCollector:ce(this,this.ea),touchCollector:ce(this,this.qa)},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.K[t][this.ga++]=e},removeEventListener:function(t,e){var r,n,o=this.K[t],i=[];for(n in o)o.hasOwnProperty(n)&&o[n]===e&&i.push(n);for(r=0;re&&(t.h[e]=t.h[e]+1|0,!t.h[e]);e++);return t.L.encrypt(t.h)}function ce(t,e){return function(){e.apply(t,arguments)}}a.random=new a.prng(6);e:try{if(be=typeof Q<"u"&&Q.exports){try{_e=Kt("crypto")}catch{_e=null}be=Oe=_e}if(be&&Oe.randomBytes)ue=Oe.randomBytes(128),ue=new Uint32Array(new Uint8Array(ue).buffer),a.random.addEntropy(ue,1024,"crypto['randomBytes']");else if(typeof window<"u"&&typeof Uint32Array<"u"){if(fe=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(fe);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(fe);else break e;a.random.addEntropy(fe,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 ue,Oe,fe,be,_e;a.json={defaults:{v:1,iter:1e4,ks:128,ts:64,mode:"ccm",adata:"",cipher:"aes"},ja:function(t,e,r,n){r=r||{},n=n||{};var o=a.json,i=o.g({iv:a.random.randomWords(4,0)},o.defaults),s;if(o.g(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 Tr=Object.prototype.hasOwnProperty,D="~";function he(){}Object.create&&(he.prototype=Object.create(null),new he().__proto__||(D=!1));function Rr(t,e,r){this.fn=t,this.context=e,this.once=r||!1}function Rt(t,e,r,n,o){if(typeof r!="function")throw new TypeError("The listener must be a function");var i=new Rr(r,n||t,o),s=D?D+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 De(t,e){--t._eventsCount===0?t._events=new he:delete t._events[e]}function b(){this._events=new he,this._eventsCount=0}b.prototype.eventNames=function(){var e=[],r,n;if(this._eventsCount===0)return e;for(n in r=this._events)Tr.call(r,n)&&e.push(D?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(r)):e};b.prototype.listeners=function(e){var r=D?D+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 V(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(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(t,[])).next())})}function lt(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 sr(t,e,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=r.apply(t,e||[]),o,i=[];return o={},s("next"),s("throw"),s("return"),o[Symbol.asyncIterator]=function(){return this},o;function s(d){n[d]&&(o[d]=function(m){return new Promise(function(w,X){i.push([d,m,w,X])>1||c(d,m)})})}function c(d,m){try{u(n[d](m))}catch(w){h(i[0][3],w)}}function u(d){d.value instanceof $?Promise.resolve(d.value.v).then(f,l):h(i[0][2],d)}function f(d){c("next",d)}function l(d){c("throw",d)}function h(d,m){d(m),i.shift(),i.length&&c(i[0][0],i[0][1])}}function ar(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:o==="return"}:i?i(s):s}:i}}function cr(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 lt=="function"?lt(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 O=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 P(r(o)));return new t(n)}static fromThrowable(e,r){return(...n)=>new t(V(this,void 0,void 0,function*(){try{return new k(yield e(...n))}catch(o){return new P(r?r(o):o)}}))}static combine(e){return ur(e)}static combineWithAllErrors(e){return fr(e)}map(e){return new t(this._promise.then(r=>V(this,void 0,void 0,function*(){return r.isErr()?new P(r.error):new k(yield e(r.value))})))}andThrough(e){return new t(this._promise.then(r=>V(this,void 0,void 0,function*(){if(r.isErr())return new P(r.error);let n=yield e(r.value);return n.isErr()?new P(n.error):new k(r.value)})))}andTee(e){return new t(this._promise.then(r=>V(this,void 0,void 0,function*(){if(r.isErr())return new P(r.error);try{yield e(r.value)}catch{}return new k(r.value)})))}mapErr(e){return new t(this._promise.then(r=>V(this,void 0,void 0,function*(){return r.isOk()?new k(r.value):new P(yield e(r.error))})))}andThen(e){return new t(this._promise.then(r=>{if(r.isErr())return new P(r.error);let n=e(r.value);return n instanceof t?n._promise:n}))}orElse(e){return new t(this._promise.then(r=>V(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 sr(this,arguments,function*(){return yield $(yield $(yield*ar(cr(yield $(this._promise.then(r=>r.safeUnwrap()))))))})}then(e,r){return this._promise.then(e,r)}},M=t=>new O(Promise.resolve(new k(t))),_=t=>new O(Promise.resolve(new P(t))),Jr=O.fromPromise,zr=O.fromSafePromise,qr=O.fromThrowable,pt=t=>{let e=q([]);for(let r of t)if(r.isErr()){e=B(r.error);break}else e.map(n=>n.push(r.value));return e},ur=t=>O.fromSafePromise(Promise.all(t)).andThen(pt),mt=t=>{let e=q([]);for(let r of t)r.isErr()&&e.isErr()?e.error.push(r.error):r.isErr()&&e.isOk()?e=B([r.error]):r.isOk()&&e.isOk()&&e.value.push(r.value);return e},fr=t=>O.fromSafePromise(Promise.all(t)).andThen(mt),je;(function(t){function e(o,i){return(...s)=>{try{let c=o(...s);return q(c)}catch(c){return B(i?i(c):c)}}}t.fromThrowable=e;function r(o){return pt(o)}t.combine=r;function n(o){return mt(o)}t.combineWithAllErrors=n})(je||(je={}));var q=t=>new k(t);function B(t){return new P(t)}var k=class{constructor(e){this.value=e}isOk(){return!0}isErr(){return!this.isOk()}map(e){return q(e(this.value))}mapErr(e){return q(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 q(this.value)}orElse(e){return q(this.value)}asyncAndThen(e){return e(this.value)}asyncAndThrough(e){return e(this.value).map(()=>this.value)}asyncMap(e){return O.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 dt("Called `_unsafeUnwrapErr` on an Ok",this,e)}},P=class{constructor(e){this.error=e}isOk(){return!1}isErr(){return!this.isOk()}map(e){return B(this.error)}mapErr(e){return B(e(this.error))}andThrough(e){return B(this.error)}andTee(e){return B(this.error)}andThen(e){return B(this.error)}orElse(e){return e(this.error)}asyncAndThen(e){return _(this.error)}asyncAndThrough(e){return _(this.error)}asyncMap(e){return _(this.error)}unwrapOr(e){return e}match(e,r){return r(this.error)}safeUnwrap(){let e=this.error;return function*(){throw yield B(e),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(e){throw dt("Called `_unsafeUnwrap` on an Err",this,e)}_unsafeUnwrapErr(e){return this.error}},$r=je.fromThrowable;var F=class extends Error{constructor(r,n={}){let{cause:o,context:i}=n;super(r,{cause:o});R(this,"context");this.name=this.constructor.name,this.context=i}};var H=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 hr=()=>typeof Deno<"u";var Y=t=>hr()?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 gt.default,L,yt=!1;self.onmessage=t=>{pr(t),yt||(yt=!0,v.once("OPERATION_FAILED",()=>{L&&L.terminate()}))};var j=(t,e)=>(Object.assign(t,e),typeof WorkerGlobalScope<"u"&&self.postMessage({event:"FILE_UPDATED",lufiFile:t}),t),wt=(t,e)=>{j(t,{uploadStatus:2}),self.postMessage({event:"OPERATION_FAILED",error:e})},pr=(t,e)=>{let{action:r}=t.data;if(r===5||r===8)L.postMessage(t.data);else{switch(r){case 2:L=new Worker(Y("cancel"),{type:"module"}),L.postMessage(t.data);break;case 3:L=new Worker(Y("download"),{type:"module"}),L.postMessage(t.data);break;case 4:L=new Worker(Y("infos"),{type:"module"}),L.postMessage(t.data);break;case 7:L=L||new Worker(Y("remove"),{type:"module"}),L.postMessage(t.data);break;case 9:L=L||new Worker(Y("upload"),{type:"module"}),L.postMessage(t.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}`)}}},Et=()=>{v.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),v.once("OPERATION_FAILED",t=>{self.postMessage({event:"OPERATION_FAILED",error:t})})};var N=class extends F{};var ie=class extends N{constructor(){super(...arguments);R(this,"message","An error occured while trying to connect to WebSocket")}};var K=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 mr=new K("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");function se(t){return mr.Decode(t)}var yr=new K("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",!0);function We(t){return yr.Decode(t)}var Dt=Ne(bt());var J=class extends F{};var Z=class extends J{constructor(){super(...arguments);R(this,"message","Unable to decrypt the provided data")}};var Ct=(t,e)=>{try{let r=typeof e=="string"?e:e.data;return M(se(Dt.default.decrypt(t,r)))}catch(r){return _(new Z(void 0,{cause:H(r)}))}};var St=(t,e)=>wr(t).andThen(r=>O.fromPromise(crypto.subtle.decrypt({name:"AES-GCM",iv:e.iv},r,se(e.data)),n=>new Z(void 0,{cause:H(n)})));var wr=t=>O.fromPromise(crypto.subtle.importKey("raw",We(t),{name:"AES-GCM"},!1,["encrypt","decrypt"]),e=>new J("Unable to import cryptography key",{cause:H(e)}));var kt=(t,e)=>e.algo===void 0||e.algo===0?Ct(t,e):St(t,e);var S={},Pt=5,xr=t=>(v.emit("UPLOAD_CANCELLED",t.success),M(void 0)),Lr=(t,e)=>{let r=t.split("XXMOJOXX"),n=r.shift();if(n!==void 0){let o=JSON.parse(n);if(Pr(o)){let i=r.shift();if(i){let s=JSON.parse(i);return s.iv&&(s.iv=new Uint8Array(Object.values(s.iv))),kt(e.keys.client,s).andThen(c=>{let u=typeof c=="string"?new TextEncoder().encode(c).buffer:c;return o.part===0?(j(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")):j(e,{chunksReady:e.chunksReady+1}),v.emit("CHUNK_DOWNLOADED",u,o.part),++o.part===o.total?Dr(e).andThen(()=>(v.emit("DOWNLOAD_COMPLETE"),v.emit("SOCKET_OPERATION_TERMINATED"),M(void 0))):M(void 0)})}else{let s=new N("Can't retrieve metadata from data received by the server");return v.emit("OPERATION_FAILED",s),_(s)}}else{let i=new N(o.msg);return v.emit("OPERATION_FAILED",i),_(i)}}else{let o=new N("Can't retrieve metadata from data received by the server");return v.emit("OPERATION_FAILED",o),_(o)}},Or=(t,e)=>{if(t.success)return t.j===0&&(j(e,{keys:{client:e.keys.client,server:t.short},actionToken:t.token,queueIndex:t.i}),v.emit("UPLOAD_STARTED")),j(e,{chunksReady:e.chunksReady+1,createdAt:t.created_at}),v.emit("CHUNK_UPLOADED"),e.chunksReady===e.totalChunks&&(j(e,{uploadStatus:1}),v.emit("UPLOAD_COMPLETE"),v.emit("SOCKET_OPERATION_TERMINATED")),M(void 0);{let r=new N(t.msg);return v.emit("OPERATION_FAILED",r),_(r)}},br=(t,e)=>{let r=kr(t.data),n;if(r)if(!r.action&&r.msg){let o=new N(r.msg);return v.emit("OPERATION_FAILED",o),_(o)}else"delay"in r?n=Or(r,e):n=xr(r);else n=Lr(t.data,e);return n},_r=t=>S!==void 0&&S[t]!==void 0&&S[t].readyState===WebSocket.CONNECTING,ze=t=>S!==void 0&&S[t]!==void 0&&S[t].readyState===WebSocket.OPEN;var qe=(t,e)=>{let r;return t.password?r={part:e,file_pwd:t.password}:r={part:e},$e(Tt(t),t,JSON.stringify(r))},Dr=t=>{let e;return t.password?e={ended:!0,file_pwd:t.password}:e={ended:!0},$e(Tt(t),t,JSON.stringify(e))};var $e=(t,e,r)=>ze(t)?(S[t].onmessage=n=>br(n,e),S[t].send(r),M(void 0)):It(t).andThen(()=>$e(t,e,r)),It=(t,e=0)=>(!ze(t)&&!_r(t)&&(S[t]=new WebSocket(t),v.once("SOCKET_OPERATION_TERMINATED",()=>{S[t].close()}),v.once("OPERATION_FAILED",()=>{v.emit("SOCKET_OPERATION_TERMINATED")}),S[t].onopen=()=>{v.emit("SOCKET_OPENED")},S[t].onclose=()=>{},S[t].onerror=()=>++e<=Pt?(console.error(`An error happened while trying to connect to WebSocket ${t}. Trying again. ${e} / ${Pt}`),It(t,e)):(v.emit("SOCKET_ONERROR"),_(new ie(`Unable to connect to WebSocket ${t}.`)))),Cr(t).andThen(()=>M(t)).orElse(r=>_(r))),Cr=t=>O.fromPromise(new Promise((e,r)=>{ze(t)?e(void 0):(v.once("SOCKET_OPENED",()=>{e(void 0)}),v.on("SOCKET_ONERROR",()=>{r(new ie)}))}),e=>H(e));var Sr=(t,e)=>{let r=new URL(t);return r.protocol=r.protocol==="http:"?"ws:":"wss:",r.pathname+=e,new URL(r.origin+r.pathname)},Tt=t=>Sr(new URL(t.serverUrl),"download"+`/${t.keys.server}`).toString();var kr=t=>{try{let e=JSON.parse(t);if(e&&typeof e=="object")return e}catch{}return!1},Pr=t=>typeof t=="object"&&t!==null&&!("msg"in t);var Xe=Ne(Mt(),1);var le=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},Ge=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},Nt=t=>globalThis.DOMException===void 0?new Ge(t):new DOMException(t),Ut=t=>{let e=t.reason===void 0?Nt("This operation was aborted."):t.reason;return e instanceof Error?e:Nt(e)};function Ve(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout}}=e,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(e.signal){let{signal:d}=e;d.aborted&&l(Ut(d));let m=()=>{l(Ut(d))};d.addEventListener("abort",m,{once:!0}),t.finally(()=>{d.removeEventListener("abort",m)})}if(r===Number.POSITIVE_INFINITY){t.then(f,l);return}let h=new le;s=i.setTimeout.call(void 0,()=>{if(n){try{f(n())}catch(d){l(d)}return}typeof t.cancel=="function"&&t.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 t)}catch(d){l(d)}})()}).finally(()=>{u.clear()});return u.clear=()=>{i.clearTimeout.call(void 0,s),s=void 0},u}function Ye(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 U,de=class{constructor(){A(this,U,[])}enqueue(e,r){r={priority:0,...r};let n={priority:r.priority,run:e};if(this.size&&p(this,U)[this.size-1].priority>=r.priority){p(this,U).push(n);return}let o=Ye(p(this,U),n,(i,s)=>s.priority-i.priority);p(this,U).splice(o,0,n)}dequeue(){let e=p(this,U).shift();return e==null?void 0:e.run}filter(e){return p(this,U).filter(r=>r.priority===e.priority).map(r=>r.run)}get size(){return p(this,U).length}};U=new WeakMap;var ee,te,z,me,re,ye,I,ne,C,ve,T,oe,W,ge,y,Bt,jt,Wt,Ft,Jt,Ce,Ke,Qe,Se,zt,ke,pe=class extends Xe.default{constructor(r){var n,o,i,s;super();A(this,y);A(this,ee);A(this,te);A(this,z,0);A(this,me);A(this,re);A(this,ye,0);A(this,I);A(this,ne);A(this,C);A(this,ve);A(this,T,0);A(this,oe);A(this,W);A(this,ge);R(this,"timeout");if(r={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:de,...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,ee,r.carryoverConcurrencyCount),E(this,te,r.intervalCap===Number.POSITIVE_INFINITY||r.interval===0),E(this,me,r.intervalCap),E(this,re,r.interval),E(this,C,new r.queueClass),E(this,ve,r.queueClass),this.concurrency=r.concurrency,this.timeout=r.timeout,E(this,ge,r.throwOnTimeout===!0),E(this,W,r.autoStart===!1)}get concurrency(){return p(this,oe)}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,oe,r),x(this,y,Se).call(this)}async add(r,n={}){return n={timeout:this.timeout,throwOnTimeout:p(this,ge),...n},new Promise((o,i)=>{p(this,C).enqueue(async()=>{var s;Ae(this,T)._++,Ae(this,z)._++;try{(s=n.signal)==null||s.throwIfAborted();let c=r({signal:n.signal});n.timeout&&(c=Ve(Promise.resolve(c),{milliseconds:n.timeout})),n.signal&&(c=Promise.race([c,x(this,y,zt).call(this,n.signal)]));let u=await c;o(u),this.emit("completed",u)}catch(c){if(c instanceof le&&!n.throwOnTimeout){o();return}i(c),this.emit("error",c)}finally{x(this,y,Wt).call(this)}},n),this.emit("add"),x(this,y,Ce).call(this)})}async addAll(r,n){return Promise.all(r.map(async o=>this.add(o,n)))}start(){return p(this,W)?(E(this,W,!1),x(this,y,Se).call(this),this):this}pause(){E(this,W,!0)}clear(){E(this,C,new(p(this,ve)))}async onEmpty(){p(this,C).size!==0&&await x(this,y,ke).call(this,"empty")}async onSizeLessThan(r){p(this,C).sizep(this,C).size{x(this,y,Ft).call(this)},n)),!0}return!1},Ce=function(){if(p(this,C).size===0)return p(this,I)&&clearInterval(p(this,I)),E(this,I,void 0),this.emit("empty"),p(this,T)===0&&this.emit("idle"),!1;if(!p(this,W)){let r=!p(this,y,Jt);if(p(this,y,Bt)&&p(this,y,jt)){let n=p(this,C).dequeue();return n?(this.emit("active"),n(),r&&x(this,y,Ke).call(this),!0):!1}}return!1},Ke=function(){p(this,te)||p(this,I)!==void 0||(E(this,I,setInterval(()=>{x(this,y,Qe).call(this)},p(this,re))),E(this,ye,Date.now()+p(this,re)))},Qe=function(){p(this,z)===0&&p(this,T)===0&&p(this,I)&&(clearInterval(p(this,I)),E(this,I,void 0)),E(this,z,p(this,ee)?p(this,T):0),x(this,y,Se).call(this)},Se=function(){for(;x(this,y,Ce).call(this););},zt=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 Mr=[],Ze=navigator.hardwareConcurrency||4,Pe=new pe({concurrency:Ze,autoStart:!1}),Ie=0,qt=!1,Te=!1;self.onmessage=t=>{qt||(Et(),qt=!0);let e=t.data;switch(e.action){case 5:Te=!0,self.postMessage({event:"JOB_PAUSED"});break;case 8:Te=!1,self.postMessage({event:"JOB_RESUMED"});break;default:v.once("DOWNLOAD_COMPLETE",()=>{self.postMessage({event:"DOWNLOAD_COMPLETE"})}),v.on("FILE_UPDATED",j),v.on("CHUNK_DOWNLOADED",(r,n)=>{self.postMessage({event:"CHUNK_DOWNLOADED",chunk:{buffer:r,index:n}})}),Nr(e).mapErr(r=>{wt(e.args.lufiFile,r)})}};var Nr=t=>{let{lufiFile:e}=t.args;return v.on("CHUNK_DOWNLOADED",(r,n)=>{Mr[n]=r,Ie--,!Te&&Ie{for(let r=1;r{await qe(e,r),Ie++,(Te||Ie===Ze)&&Pe.pause()});Pe.start()}),qe(e,0)};export{Ze as QUEUE_CONCURRENCY_LIMIT,Ie as itemsInQueue,Pe as queue}; +var Ht=Object.create;var Te=Object.defineProperty;var Xt=Object.getOwnPropertyDescriptor;var Gt=Object.getOwnPropertyNames;var Vt=Object.getPrototypeOf,Yt=Object.prototype.hasOwnProperty;var et=t=>{throw TypeError(t)};var Kt=(t,e,r)=>e in t?Te(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var Qt=(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 Zt=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Gt(e))!Yt.call(t,o)&&o!==r&&Te(t,o,{get:()=>e[o],enumerable:!(n=Xt(e,o))||n.enumerable});return t};var Ne=(t,e,r)=>(r=t!=null?Ht(Vt(t)):{},Zt(e||!t||!t.__esModule?Te(r,"default",{value:t,enumerable:!0}):r,t));var T=(t,e,r)=>Kt(t,typeof e!="symbol"?e+"":e,r),Ue=(t,e,r)=>e.has(t)||et("Cannot "+r);var d=(t,e,r)=>(Ue(t,e,"read from private field"),r?r.call(t):e.get(t)),A=(t,e,r)=>e.has(t)?et("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),E=(t,e,r,n)=>(Ue(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),x=(t,e,r)=>(Ue(t,e,"access private method"),r);var Ae=(t,e,r,n)=>({set _(o){E(t,e,o,r)},get _(){return d(t,e,n)}});var ht=Me((jr,Be)=>{"use strict";var Y=typeof Reflect=="object"?Reflect:null,tt=Y&&typeof Y.apply=="function"?Y.apply:function(e,r,n){return Function.prototype.apply.call(e,r,n)},xe;Y&&typeof Y.ownKeys=="function"?xe=Y.ownKeys:Object.getOwnPropertySymbols?xe=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:xe=function(e){return Object.getOwnPropertyNames(e)};function er(t){console&&console.warn&&console.warn(t)}var nt=Number.isNaN||function(e){return e!==e};function w(){w.init.call(this)}Be.exports=w;Be.exports.once=or;w.EventEmitter=w;w.prototype._events=void 0;w.prototype._eventsCount=0;w.prototype._maxListeners=void 0;var rt=10;function Le(t){if(typeof t!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t)}Object.defineProperty(w,"defaultMaxListeners",{enumerable:!0,get:function(){return rt},set:function(t){if(typeof t!="number"||t<0||nt(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");rt=t}});w.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};w.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||nt(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 ot(t){return t._maxListeners===void 0?w.defaultMaxListeners:t._maxListeners}w.prototype.getMaxListeners=function(){return ot(this)};w.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")tt(u,this,r);else for(var f=u.length,l=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,er(c)}return t}w.prototype.addListener=function(e,r){return it(this,e,r,!1)};w.prototype.on=w.prototype.addListener;w.prototype.prependListener=function(e,r){return it(this,e,r,!0)};function tr(){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 st(t,e,r){var n={fired:!1,wrapFn:void 0,target:t,type:e,listener:r},o=tr.bind(n);return o.listener=r,n.wrapFn=o,o}w.prototype.once=function(e,r){return Le(r),this.on(e,st(this,e,r)),this};w.prototype.prependOnceListener=function(e,r){return Le(r),this.prependListener(e,st(this,e,r)),this};w.prototype.removeListener=function(e,r){var n,o,i,s,c;if(Le(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():rr(n,i),n.length===1&&(o[e]=n[0]),o.removeListener!==void 0&&this.emit("removeListener",e,c||r)}return this};w.prototype.off=w.prototype.removeListener;w.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 at(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?nr(o):ut(o,o.length)}w.prototype.listeners=function(e){return at(this,e,!0)};w.prototype.rawListeners=function(e){return at(this,e,!1)};w.listenerCount=function(t,e){return typeof t.listenerCount=="function"?t.listenerCount(e):ct.call(t,e)};w.prototype.listenerCount=ct;function ct(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}w.prototype.eventNames=function(){return this._eventsCount>0?xe(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.s[0][0][0]||this.O();var e,r,n,o,i=this.s[0][4],s=this.s[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 Lt(this,t,0)},decrypt:function(t){return Lt(this,t,1)},s:[[[],[],[],[],[]],[[],[],[],[],[]]],O:function(){var t=this.s[0],e=this.s[1],r=t[4],n=e[4],o,i,s,c=[],u=[],f,l,h,p;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]]],p=16843009*l^65537*o^257*f^16843008*i,l=257*c[h]^16843008*h,o=0;4>o;o++)t[o][i]=l=l<<24^l>>>8,e[o][h]=p=p<<24^p>>>8;for(o=0;5>o;o++)t[o]=t[o].slice(0),e[o]=e[o].slice(0)}};function Lt(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,l=n.length/4-2,h,p=4,m=[0,0,0,0];c=t.s[r],t=c[0];var g=c[1],j=c[2],G=c[3],V=c[4];for(h=0;h>>24]^g[i>>16&255]^j[s>>8&255]^G[e&255]^n[p],u=t[i>>>24]^g[s>>16&255]^j[e>>8&255]^G[o&255]^n[p+1],f=t[s>>>24]^g[e>>16&255]^j[o>>8&255]^G[i&255]^n[p+2],e=t[e>>>24]^g[o>>16&255]^j[i>>8&255]^G[s&255]^n[p+3],p+=4,o=c,i=u,s=f;for(h=0;4>h;h++)m[r?3&-h:h]=V[o>>>24]<<24^V[i>>16&255]<<16^V[s>>8&255]<<8^V[e&255]^n[p++],c=o,o=i,i=s,s=e,e=c;return m}a.bitArray={bitSlice:function(t,e,r){return t=a.bitArray.$(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>>s)>>>o),sl){if(!e)try{return a.codec.base32hex.toBits(t)}catch{}throw new a.exception.invalid("this isn't "+h+"!")}c>o?(c-=o,i.push(f^l>>>c),f=l<>>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.B,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.O(),t?(this.F=t.F.slice(0),this.A=t.A.slice(0),this.l=t.l):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.F=this.Y.slice(0),this.A=[],this.l=0,this},update:function(t){typeof t=="string"&&(t=a.codec.utf8String.toBits(t));var e,r=this.A=a.bitArray.concat(this.A,t);if(e=this.l,t=this.l=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.Y[e]=t(Math.pow(r,.5))),this.b[e]=t(Math.pow(r,1/3)),e++)}}};function Fe(t,e){var r,n,o,i=t.F,s=t.b,c=i[0],u=i[1],f=i[2],l=i[3],h=i[4],p=i[5],m=i[6],g=i[7];for(r=0;64>r;r++)16>r?n=e[r]:(n=e[r+1&15],o=e[r+14&15],n=e[r&15]=(n>>>7^n>>>18^n>>>3^n<<25^n<<14)+(o>>>17^o>>>19^o>>>10^o<<15^o<<13)+e[r&15]+e[r+9&15]|0),n=n+g+(h>>>6^h>>>11^h>>>25^h<<26^h<<21^h<<7)+(m^h&(p^m))+s[r],g=m,m=p,p=h,h=l+n|0,l=f,f=u,u=c,c=n+(u&f^l&(u^f))+(u>>>2^u>>>13^u>>>22^u<<30^u<<19^u<<10)|0;i[0]=i[0]+c|0,i[1]=i[1]+u|0,i[2]=i[2]+f|0,i[3]=i[3]+l|0,i[4]=i[4]+h|0,i[5]=i[5]+p|0,i[6]=i[6]+m|0,i[7]=i[7]+g|0}a.mode.ccm={name:"ccm",G:[],listenProgress:function(t){a.mode.ccm.G.push(t)},unListenProgress:function(t){t=a.mode.ccm.G.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.V(t,e,r,n,o,i),s=a.mode.ccm.C(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.C(t,c,r,u,o,e),t=a.mode.ccm.V(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},na:function(t,e,r,n,o,i){var s=[],c=a.bitArray,u=c.i;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||16l&&(a.mode.ccm.fa(s/u),l+=h),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.mode.ocb2={name:"ocb2",encrypt:function(t,e,r,n,o,i){if(a.bitArray.bitLength(r)!==128)throw new a.exception.invalid("ocb iv must be 128 bits");var s,c=a.mode.ocb2.S,u=a.bitArray,f=u.i,l=[0,0,0,0];r=c(t.encrypt(r));var h,p=[];for(n=n||[],o=o||64,s=0;s+4o.bitLength(r)&&(c=i(c,n(c)),r=o.concat(r,[-2147483648,0,0,0])),s=i(s,r),t.encrypt(i(n(i(c,n(c))),s))},S:function(t){return[t[0]<<1^t[1]>>>31,t[1]<<1^t[2]>>>31,t[2]<<1^t[3]>>>31,t[3]<<1^135*(t[0]>>>31)]}};a.mode.gcm={name:"gcm",encrypt:function(t,e,r,n,o){var i=e.slice(0);return e=a.bitArray,n=n||[],t=a.mode.gcm.C(!0,t,i,n,r,o||128),e.concat(t.data,t.tag)},decrypt:function(t,e,r,n,o){var i=e.slice(0),s=a.bitArray,c=s.bitLength(i);if(o=o||128,n=n||[],o<=c?(e=s.bitSlice(i,c-o),i=s.bitSlice(i,0,c-o)):(e=i,i=[]),t=a.mode.gcm.C(!1,t,i,n,r,o),!s.equal(t.tag,e))throw new a.exception.corrupt("gcm: tag doesn't match");return t.data},ka:function(t,e){var r,n,o,i,s,c=a.bitArray.i;for(o=[0,0,0,0],i=e.slice(0),r=0;128>r;r++){for((n=(t[Math.floor(r/32)]&1<<31-r%32)!==0)&&(o=c(o,i)),s=(i[3]&1)!==0,n=3;0>>1|(i[n-1]&1)<<31;i[0]>>>=1,s&&(i[0]^=-520093696)}return o},j:function(t,e,r){var n,o=r.length;for(e=e.slice(0),n=0;no&&(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=[],l=a.bitArray;for(u=1;32*f.length<(n||1);u++){for(o=i=t.encrypt(l.concat(e,[u])),s=1;ss;s++)o.push(4294967296*Math.random()|0);for(s=0;s=1<this.o&&(this.o=i),this.P++,this.b=a.hash.sha256.hash(this.b.concat(o)),this.L=new a.cipher.aes(this.b),n=0;4>n&&(this.h[n]=this.h[n]+1|0,!this.h[n]);n++);}for(n=0;n>>1;this.c[s].update([n,this.N++,2,e,i,t.length].concat(t))}break;case"string":e===void 0&&(e=t.length),this.c[s].update([n,this.N++,3,e,i,t.length]),this.c[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.m[s]+=e,this.f+=e,c===this.u&&(this.isReady()!==this.u&&Ot("seeded",Math.max(this.o,this.f)),Ot("progress",this.getProgress()))},isReady:function(t){return t=this.T[t!==void 0?t:this.M],this.o&&this.o>=t?this.m[0]>this.ba&&new Date().valueOf()>this.Z?this.J|this.I:this.I:this.f>=t?this.J|this.u:this.u},getProgress:function(t){return t=this.T[t||this.M],this.o>=t||this.f>t?1:this.f/t},startCollectors:function(){if(!this.D){if(this.a={loadTimeCollector:fe(this,this.ma),mouseCollector:fe(this,this.oa),keyboardCollector:fe(this,this.la),accelerometerCollector:fe(this,this.ea),touchCollector:fe(this,this.qa)},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.K[t][this.ga++]=e},removeEventListener:function(t,e){var r,n,o=this.K[t],i=[];for(n in o)o.hasOwnProperty(n)&&o[n]===e&&i.push(n);for(r=0;re&&(t.h[e]=t.h[e]+1|0,!t.h[e]);e++);return t.L.encrypt(t.h)}function fe(t,e){return function(){e.apply(t,arguments)}}a.random=new a.prng(6);e:try{if(be=typeof ee<"u"&&ee.exports){try{_e=Qt("crypto")}catch{_e=null}be=Oe=_e}if(be&&Oe.randomBytes)he=Oe.randomBytes(128),he=new Uint32Array(new Uint8Array(he).buffer),a.random.addEntropy(he,1024,"crypto['randomBytes']");else if(typeof window<"u"&&typeof Uint32Array<"u"){if(le=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(le);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(le);else break e;a.random.addEntropy(le,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 he,Oe,le,be,_e;a.json={defaults:{v:1,iter:1e4,ks:128,ts:64,mode:"ccm",adata:"",cipher:"aes"},ja:function(t,e,r,n){r=r||{},n=n||{};var o=a.json,i=o.g({iv:a.random.randomWords(4,0)},o.defaults),s;if(o.g(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 Rr=Object.prototype.hasOwnProperty,D="~";function de(){}Object.create&&(de.prototype=Object.create(null),new de().__proto__||(D=!1));function Tr(t,e,r){this.fn=t,this.context=e,this.once=r||!1}function Mt(t,e,r,n,o){if(typeof r!="function")throw new TypeError("The listener must be a function");var i=new Tr(r,n||t,o),s=D?D+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 De(t,e){--t._eventsCount===0?t._events=new de:delete t._events[e]}function _(){this._events=new de,this._eventsCount=0}_.prototype.eventNames=function(){var e=[],r,n;if(this._eventsCount===0)return e;for(n in r=this._events)Rr.call(r,n)&&e.push(D?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(r)):e};_.prototype.listeners=function(e){var r=D?D+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 K(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(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(t,e||[])).next())})}function lt(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 dt(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(m){return function(g){return Promise.resolve(g).then(m,h)}}function c(m,g){n[m]&&(o[m]=function(j){return new Promise(function(G,V){i.push([m,j,G,V])>1||u(m,j)})},g&&(o[m]=g(o[m])))}function u(m,g){try{f(n[m](g))}catch(j){p(i[0][3],j)}}function f(m){m.value instanceof M?Promise.resolve(m.value.v).then(l,h):p(i[0][2],m)}function l(m){u("next",m)}function h(m){u("throw",m)}function p(m,g){m(g),i.shift(),i.length&&u(i[0][0],i[0][1])}}function ar(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 cr(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 lt=="function"?lt(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 b=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 P(r(o)));return new t(n)}static fromThrowable(e,r){return(...n)=>new t(K(this,void 0,void 0,function*(){try{return new k(yield e(...n))}catch(o){return new P(r?r(o):o)}}))}static combine(e){return ur(e)}static combineWithAllErrors(e){return fr(e)}map(e){return new t(this._promise.then(r=>K(this,void 0,void 0,function*(){return r.isErr()?new P(r.error):new k(yield e(r.value))})))}andThrough(e){return new t(this._promise.then(r=>K(this,void 0,void 0,function*(){if(r.isErr())return new P(r.error);let n=yield e(r.value);return n.isErr()?new P(n.error):new k(r.value)})))}andTee(e){return new t(this._promise.then(r=>K(this,void 0,void 0,function*(){if(r.isErr())return new P(r.error);try{yield e(r.value)}catch{}return new k(r.value)})))}mapErr(e){return new t(this._promise.then(r=>K(this,void 0,void 0,function*(){return r.isOk()?new k(r.value):new P(yield e(r.error))})))}andThen(e){return new t(this._promise.then(r=>{if(r.isErr())return new P(r.error);let n=e(r.value);return n instanceof t?n._promise:n}))}orElse(e){return new t(this._promise.then(r=>K(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 dt(this,arguments,function*(){return yield M(yield M(yield*ar(cr(yield M(this._promise.then(r=>r.safeUnwrap()))))))})}then(e,r){return this._promise.then(e,r)}[Symbol.asyncIterator](){return dt(this,arguments,function*(){let r=yield M(this._promise);return r.isErr()&&(yield yield M(O(r.error))),yield M(r.value)})}},N=t=>new b(Promise.resolve(new k(t))),O=t=>new b(Promise.resolve(new P(t))),Jr=b.fromPromise,zr=b.fromSafePromise,qr=b.fromThrowable,mt=t=>{let e=H([]);for(let r of t)if(r.isErr()){e=W(r.error);break}else e.map(n=>n.push(r.value));return e},ur=t=>b.fromSafePromise(Promise.all(t)).andThen(mt),yt=t=>{let e=H([]);for(let r of t)r.isErr()&&e.isErr()?e.error.push(r.error):r.isErr()&&e.isOk()?e=W([r.error]):r.isOk()&&e.isOk()&&e.value.push(r.value);return e},fr=t=>b.fromSafePromise(Promise.all(t)).andThen(yt),je;(function(t){function e(o,i){return(...s)=>{try{let c=o(...s);return H(c)}catch(c){return W(i?i(c):c)}}}t.fromThrowable=e;function r(o){return mt(o)}t.combine=r;function n(o){return yt(o)}t.combineWithAllErrors=n})(je||(je={}));var H=t=>new k(t);function W(t){return new P(t)}var k=class{constructor(e){this.value=e}isOk(){return!0}isErr(){return!this.isOk()}map(e){return H(e(this.value))}mapErr(e){return H(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 H(this.value)}orElse(e){return H(this.value)}asyncAndThen(e){return e(this.value)}asyncAndThrough(e){return e(this.value).map(()=>this.value)}asyncMap(e){return b.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 pt("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 W(this.error)}mapErr(e){return W(e(this.error))}andThrough(e){return W(this.error)}andTee(e){return W(this.error)}andThen(e){return W(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,r){return r(this.error)}safeUnwrap(){let e=this.error;return function*(){throw yield W(e),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(e){throw pt("Called `_unsafeUnwrap` on an Err",this,e)}_unsafeUnwrapErr(e){return this.error}*[Symbol.iterator](){let e=this;return yield e,e}},$r=je.fromThrowable;var z=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 X=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 hr=()=>typeof Deno<"u";var Q=t=>hr()?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 wt.default,L,vt=!1;self.onmessage=t=>{pr(t),vt||(vt=!0,v.once("OPERATION_FAILED",()=>{L&&L.terminate()}))};var F=(t,e)=>(Object.assign(t,e),typeof WorkerGlobalScope<"u"&&self.postMessage({event:"FILE_UPDATED",lufiFile:t}),t),Et=(t,e)=>{F(t,{uploadStatus:2}),self.postMessage({event:"OPERATION_FAILED",error:e})},pr=(t,e)=>{let{action:r}=t.data;if(r===5||r===8)L.postMessage(t.data);else{switch(r){case 2:L=new Worker(Q("cancel"),{type:"module"}),L.postMessage(t.data);break;case 3:L=new Worker(Q("download"),{type:"module"}),L.postMessage(t.data);break;case 4:L=new Worker(Q("infos"),{type:"module"}),L.postMessage(t.data);break;case 7:L=L||new Worker(Q("remove"),{type:"module"}),L.postMessage(t.data);break;case 9:L=L||new Worker(Q("upload"),{type:"module"}),L.postMessage(t.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}`)}}},At=()=>{v.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),v.once("OPERATION_FAILED",t=>{self.postMessage({event:"OPERATION_FAILED",error:t})})};var U=class extends z{};var ae=class extends U{constructor(){super(...arguments);T(this,"message","An error occured while trying to connect to WebSocket")}};var Z=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 mr=new Z("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");function ce(t){return mr.Decode(t)}var yr=new Z("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",!0);function We(t){return yr.Decode(t)}var St=Ne(_t());var q=class extends z{};var te=class extends q{constructor(){super(...arguments);T(this,"message","Unable to decrypt the provided data")}};var Ct=(t,e)=>{try{let r=typeof e=="string"?e:e.data;return N(ce(St.default.decrypt(t,r)))}catch(r){return O(new te(void 0,{cause:X(r)}))}};var kt=(t,e)=>wr(t).andThen(r=>b.fromPromise(crypto.subtle.decrypt({name:"AES-GCM",iv:e.iv},r,ce(e.data)),n=>new te(void 0,{cause:X(n)})));var wr=t=>b.fromPromise(crypto.subtle.importKey("raw",We(t),{name:"AES-GCM"},!1,["encrypt","decrypt"]),e=>new q("Unable to import cryptography key",{cause:X(e)}));var Pt=(t,e)=>e.algo===void 0||e.algo===0?Ct(t,e):kt(t,e);var C={},It=5,xr=t=>(v.emit("UPLOAD_CANCELLED",t.success),N(void 0)),Lr=(t,e)=>{let r=t.split("XXMOJOXX"),n=r.shift();if(n!==void 0){let o=JSON.parse(n);if(Pr(o)){let i=r.shift();if(i){let s=JSON.parse(i);return s.iv&&(s.iv=new Uint8Array(Object.values(s.iv))),Pt(e.keys.client,s).andThen(c=>{let u=typeof c=="string"?new TextEncoder().encode(c).buffer:c;return o.part===0?(F(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")):F(e,{chunksReady:e.chunksReady+1}),v.emit("CHUNK_DOWNLOADED",u,o.part),++o.part===o.total?Dr(e).andThen(()=>(v.emit("DOWNLOAD_COMPLETE"),v.emit("SOCKET_OPERATION_TERMINATED"),N(void 0))):N(void 0)})}else{let s=new U("Can't retrieve metadata from data received by the server");return v.emit("OPERATION_FAILED",s),O(s)}}else{let i=new U(o.msg);return v.emit("OPERATION_FAILED",i),O(i)}}else{let o=new U("Can't retrieve metadata from data received by the server");return v.emit("OPERATION_FAILED",o),O(o)}},Or=(t,e)=>{if(t.success)return t.j===0&&(F(e,{keys:{client:e.keys.client,server:t.short},actionToken:t.token,queueIndex:t.i}),v.emit("UPLOAD_STARTED")),F(e,{chunksReady:e.chunksReady+1,createdAt:t.created_at}),v.emit("CHUNK_UPLOADED"),e.chunksReady===e.totalChunks&&(F(e,{uploadStatus:1}),v.emit("UPLOAD_COMPLETE"),v.emit("SOCKET_OPERATION_TERMINATED")),N(void 0);{let r=new U(t.msg);return v.emit("OPERATION_FAILED",r),O(r)}},br=(t,e)=>{let r=kr(t.data),n;if(r)if(!r.action&&r.msg){let o=new U(r.msg);return v.emit("OPERATION_FAILED",o),O(o)}else"delay"in r?n=Or(r,e):n=xr(r);else n=Lr(t.data,e);return n},_r=t=>C!==void 0&&C[t]!==void 0&&C[t].readyState===WebSocket.CONNECTING,ze=t=>C!==void 0&&C[t]!==void 0&&C[t].readyState===WebSocket.OPEN;var qe=(t,e)=>{let r;return t.password?r={part:e,file_pwd:t.password}:r={part:e},$e(Tt(t),t,JSON.stringify(r))},Dr=t=>{let e;return t.password?e={ended:!0,file_pwd:t.password}:e={ended:!0},$e(Tt(t),t,JSON.stringify(e))};var $e=(t,e,r)=>ze(t)?(C[t].onmessage=n=>br(n,e),C[t].send(r),N(void 0)):Rt(t).andThen(()=>$e(t,e,r)),Rt=(t,e=0)=>(!ze(t)&&!_r(t)&&(C[t]=new WebSocket(t),v.once("SOCKET_OPERATION_TERMINATED",()=>{C[t].close()}),v.once("OPERATION_FAILED",()=>{v.emit("SOCKET_OPERATION_TERMINATED")}),C[t].onopen=()=>{v.emit("SOCKET_OPENED")},C[t].onclose=()=>{},C[t].onerror=()=>++e<=It?(console.error(`An error happened while trying to connect to WebSocket ${t}. Trying again. ${e} / ${It}`),Rt(t,e)):(v.emit("SOCKET_ONERROR"),O(new ae(`Unable to connect to WebSocket ${t}.`)))),Sr(t).andThen(()=>N(t)).orElse(r=>O(r))),Sr=t=>b.fromPromise(new Promise((e,r)=>{ze(t)?e(void 0):(v.once("SOCKET_OPENED",()=>{e(void 0)}),v.on("SOCKET_ONERROR",()=>{r(new ae)}))}),e=>X(e));var Cr=(t,e)=>{let r=new URL(t);return r.protocol=r.protocol==="http:"?"ws:":"wss:",r.pathname+=e,new URL(r.origin+r.pathname)},Tt=t=>Cr(new URL(t.serverUrl),"download"+`/${t.keys.server}`).toString();var kr=t=>{try{let e=JSON.parse(t);if(e&&typeof e=="object")return e}catch{}return!1},Pr=t=>typeof t=="object"&&t!==null&&!("msg"in t);var Xe=Ne(Nt(),1);var pe=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},Ge=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},Ut=t=>globalThis.DOMException===void 0?new Ge(t):new DOMException(t),Bt=t=>{let e=t.reason===void 0?Ut("This operation was aborted."):t.reason;return e instanceof Error?e:Ut(e)};function Ve(t,e){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout}}=e,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(e.signal){let{signal:p}=e;p.aborted&&l(Bt(p));let m=()=>{l(Bt(p))};p.addEventListener("abort",m,{once:!0}),t.finally(()=>{p.removeEventListener("abort",m)})}if(r===Number.POSITIVE_INFINITY){t.then(f,l);return}let h=new pe;s=i.setTimeout.call(void 0,()=>{if(n){try{f(n())}catch(p){l(p)}return}typeof t.cancel=="function"&&t.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 t)}catch(p){l(p)}})()}).finally(()=>{u.clear()});return u.clear=()=>{i.clearTimeout.call(void 0,s),s=void 0},u}function Ye(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 B,me=class{constructor(){A(this,B,[])}enqueue(e,r){r={priority:0,...r};let n={priority:r.priority,run:e};if(this.size&&d(this,B)[this.size-1].priority>=r.priority){d(this,B).push(n);return}let o=Ye(d(this,B),n,(i,s)=>s.priority-i.priority);d(this,B).splice(o,0,n)}dequeue(){let e=d(this,B).shift();return e==null?void 0:e.run}filter(e){return d(this,B).filter(r=>r.priority===e.priority).map(r=>r.run)}get size(){return d(this,B).length}};B=new WeakMap;var re,ne,$,ve,oe,ge,I,ie,S,we,R,se,J,Ee,y,jt,Wt,Ft,Jt,zt,Se,Ke,Qe,Ce,qt,ke,ye=class extends Xe.default{constructor(r){var n,o,i,s;super();A(this,y);A(this,re);A(this,ne);A(this,$,0);A(this,ve);A(this,oe);A(this,ge,0);A(this,I);A(this,ie);A(this,S);A(this,we);A(this,R,0);A(this,se);A(this,J);A(this,Ee);T(this,"timeout");if(r={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:me,...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,re,r.carryoverConcurrencyCount),E(this,ne,r.intervalCap===Number.POSITIVE_INFINITY||r.interval===0),E(this,ve,r.intervalCap),E(this,oe,r.interval),E(this,S,new r.queueClass),E(this,we,r.queueClass),this.concurrency=r.concurrency,this.timeout=r.timeout,E(this,Ee,r.throwOnTimeout===!0),E(this,J,r.autoStart===!1)}get concurrency(){return d(this,se)}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,se,r),x(this,y,Ce).call(this)}async add(r,n={}){return n={timeout:this.timeout,throwOnTimeout:d(this,Ee),...n},new Promise((o,i)=>{d(this,S).enqueue(async()=>{var s;Ae(this,R)._++,Ae(this,$)._++;try{(s=n.signal)==null||s.throwIfAborted();let c=r({signal:n.signal});n.timeout&&(c=Ve(Promise.resolve(c),{milliseconds:n.timeout})),n.signal&&(c=Promise.race([c,x(this,y,qt).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,Ft).call(this)}},n),this.emit("add"),x(this,y,Se).call(this)})}async addAll(r,n){return Promise.all(r.map(async o=>this.add(o,n)))}start(){return d(this,J)?(E(this,J,!1),x(this,y,Ce).call(this),this):this}pause(){E(this,J,!0)}clear(){E(this,S,new(d(this,we)))}async onEmpty(){d(this,S).size!==0&&await x(this,y,ke).call(this,"empty")}async onSizeLessThan(r){d(this,S).sized(this,S).size{x(this,y,Jt).call(this)},n)),!0}return!1},Se=function(){if(d(this,S).size===0)return d(this,I)&&clearInterval(d(this,I)),E(this,I,void 0),this.emit("empty"),d(this,R)===0&&this.emit("idle"),!1;if(!d(this,J)){let r=!d(this,y,zt);if(d(this,y,jt)&&d(this,y,Wt)){let n=d(this,S).dequeue();return n?(this.emit("active"),n(),r&&x(this,y,Ke).call(this),!0):!1}}return!1},Ke=function(){d(this,ne)||d(this,I)!==void 0||(E(this,I,setInterval(()=>{x(this,y,Qe).call(this)},d(this,oe))),E(this,ge,Date.now()+d(this,oe)))},Qe=function(){d(this,$)===0&&d(this,R)===0&&d(this,I)&&(clearInterval(d(this,I)),E(this,I,void 0)),E(this,$,d(this,re)?d(this,R):0),x(this,y,Ce).call(this)},Ce=function(){for(;x(this,y,Se).call(this););},qt=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 Mr=[],Ze=navigator.hardwareConcurrency||4,Pe=new ye({concurrency:Ze,autoStart:!1}),Ie=0,$t=!1,Re=!1;self.onmessage=t=>{$t||(At(),$t=!0);let e=t.data;switch(e.action){case 5:Re=!0,self.postMessage({event:"JOB_PAUSED"});break;case 8:Re=!1,self.postMessage({event:"JOB_RESUMED"});break;default:v.once("DOWNLOAD_COMPLETE",()=>{self.postMessage({event:"DOWNLOAD_COMPLETE"})}),v.on("FILE_UPDATED",F),v.on("CHUNK_DOWNLOADED",(r,n)=>{self.postMessage({event:"CHUNK_DOWNLOADED",chunk:{buffer:r,index:n}})}),Nr(e).mapErr(r=>{Et(e.args.lufiFile,r)})}};var Nr=t=>{let{lufiFile:e}=t.args;return v.on("CHUNK_DOWNLOADED",(r,n)=>{Mr[n]=r,Ie--,!Re&&Ie{for(let r=1;r{await qe(e,r),Ie++,(Re||Ie===Ze)&&Pe.pause()});Pe.start()}),qe(e,0)};export{Ze as QUEUE_CONCURRENCY_LIMIT,Ie as itemsInQueue,Pe as queue}; diff --git a/themes/default/public/js/worker/encrypt.js b/themes/default/public/js/worker/encrypt.js index 4fdd22e..baff491 100644 --- a/themes/default/public/js/worker/encrypt.js +++ b/themes/default/public/js/worker/encrypt.js @@ -1 +1 @@ -var Be=Object.create;var Y=Object.defineProperty;var Ie=Object.getOwnPropertyDescriptor;var Re=Object.getOwnPropertyNames;var je=Object.getPrototypeOf,Ue=Object.prototype.hasOwnProperty;var Te=(t,e,r)=>e in t?Y(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var Fe=(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 re=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var Ne=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Re(e))!Ue.call(t,o)&&o!==r&&Y(t,o,{get:()=>e[o],enumerable:!(n=Ie(e,o))||n.enumerable});return t};var ne=(t,e,r)=>(r=t!=null?Be(je(t)):{},Ne(e||!t||!t.__esModule?Y(r,"default",{value:t,enumerable:!0}):r,t));var L=(t,e,r)=>Te(t,typeof e!="symbol"?e+"":e,r);var le=re((kt,P)=>{"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.s[0][0][0]||this.O();var e,r,n,o,i=this.s[0][4],s=this.s[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 fe(this,t,0)},decrypt:function(t){return fe(this,t,1)},s:[[[],[],[],[],[]],[[],[],[],[],[]]],O:function(){var t=this.s[0],e=this.s[1],r=t[4],n=e[4],o,i,s,a=[],f=[],u,l,h,p;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(h=s^s<<1^s<<2^s<<3^s<<4,h=h>>8^h&255^99,r[i]=h,n[h]=i,l=a[o=a[u=a[i]]],p=16843009*l^65537*o^257*u^16843008*i,l=257*a[h]^16843008*h,o=0;4>o;o++)t[o][i]=l=l<<24^l>>>8,e[o][h]=p=p<<24^p>>>8;for(o=0;5>o;o++)t[o]=t[o].slice(0),e[o]=e[o].slice(0)}};function fe(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,l=n.length/4-2,h,p=4,m=[0,0,0,0];a=t.s[r],t=a[0];var y=a[1],O=a[2],N=a[3],W=a[4];for(h=0;h>>24]^y[i>>16&255]^O[s>>8&255]^N[e&255]^n[p],f=t[i>>>24]^y[s>>16&255]^O[e>>8&255]^N[o&255]^n[p+1],u=t[s>>>24]^y[e>>16&255]^O[o>>8&255]^N[i&255]^n[p+2],e=t[e>>>24]^y[o>>16&255]^O[i>>8&255]^N[s&255]^n[p+3],p+=4,o=a,i=f,s=u;for(h=0;4>h;h++)m[r?3&-h:h]=W[o>>>24]<<24^W[i>>16&255]<<16^W[s>>8&255]<<8^W[e&255]^n[p++],a=o,o=i,i=s,s=e,e=a;return m}c.bitArray={bitSlice:function(t,e,r){return t=c.bitArray.$(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>>s)>>>o),sl){if(!e)try{return c.codec.base32hex.toBits(t)}catch{}throw new c.exception.invalid("this isn't "+h+"!")}a>o?(a-=o,i.push(u^l>>>a),u=l<>>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.B,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.O(),t?(this.F=t.F.slice(0),this.A=t.A.slice(0),this.l=t.l):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.F=this.Y.slice(0),this.A=[],this.l=0,this},update:function(t){typeof t=="string"&&(t=c.codec.utf8String.toBits(t));var e,r=this.A=c.bitArray.concat(this.A,t);if(e=this.l,t=this.l=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.Y[e]=t(Math.pow(r,.5))),this.b[e]=t(Math.pow(r,1/3)),e++)}}};function Z(t,e){var r,n,o,i=t.F,s=t.b,a=i[0],f=i[1],u=i[2],l=i[3],h=i[4],p=i[5],m=i[6],y=i[7];for(r=0;64>r;r++)16>r?n=e[r]:(n=e[r+1&15],o=e[r+14&15],n=e[r&15]=(n>>>7^n>>>18^n>>>3^n<<25^n<<14)+(o>>>17^o>>>19^o>>>10^o<<15^o<<13)+e[r&15]+e[r+9&15]|0),n=n+y+(h>>>6^h>>>11^h>>>25^h<<26^h<<21^h<<7)+(m^h&(p^m))+s[r],y=m,m=p,p=h,h=l+n|0,l=u,u=f,f=a,a=n+(f&u^l&(f^u))+(f>>>2^f>>>13^f>>>22^f<<30^f<<19^f<<10)|0;i[0]=i[0]+a|0,i[1]=i[1]+f|0,i[2]=i[2]+u|0,i[3]=i[3]+l|0,i[4]=i[4]+h|0,i[5]=i[5]+p|0,i[6]=i[6]+m|0,i[7]=i[7]+y|0}c.mode.ccm={name:"ccm",G:[],listenProgress:function(t){c.mode.ccm.G.push(t)},unListenProgress:function(t){t=c.mode.ccm.G.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.V(t,e,r,n,o,i),s=c.mode.ccm.C(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.C(t,a,r,f,o,e),t=c.mode.ccm.V(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},na:function(t,e,r,n,o,i){var s=[],a=c.bitArray,f=a.i;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||16l&&(c.mode.ccm.fa(s/f),l+=h),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.mode.ocb2={name:"ocb2",encrypt:function(t,e,r,n,o,i){if(c.bitArray.bitLength(r)!==128)throw new c.exception.invalid("ocb iv must be 128 bits");var s,a=c.mode.ocb2.S,f=c.bitArray,u=f.i,l=[0,0,0,0];r=a(t.encrypt(r));var h,p=[];for(n=n||[],o=o||64,s=0;s+4o.bitLength(r)&&(a=i(a,n(a)),r=o.concat(r,[-2147483648,0,0,0])),s=i(s,r),t.encrypt(i(n(i(a,n(a))),s))},S:function(t){return[t[0]<<1^t[1]>>>31,t[1]<<1^t[2]>>>31,t[2]<<1^t[3]>>>31,t[3]<<1^135*(t[0]>>>31)]}};c.mode.gcm={name:"gcm",encrypt:function(t,e,r,n,o){var i=e.slice(0);return e=c.bitArray,n=n||[],t=c.mode.gcm.C(!0,t,i,n,r,o||128),e.concat(t.data,t.tag)},decrypt:function(t,e,r,n,o){var i=e.slice(0),s=c.bitArray,a=s.bitLength(i);if(o=o||128,n=n||[],o<=a?(e=s.bitSlice(i,a-o),i=s.bitSlice(i,0,a-o)):(e=i,i=[]),t=c.mode.gcm.C(!1,t,i,n,r,o),!s.equal(t.tag,e))throw new c.exception.corrupt("gcm: tag doesn't match");return t.data},ka:function(t,e){var r,n,o,i,s,a=c.bitArray.i;for(o=[0,0,0,0],i=e.slice(0),r=0;128>r;r++){for((n=(t[Math.floor(r/32)]&1<<31-r%32)!==0)&&(o=a(o,i)),s=(i[3]&1)!==0,n=3;0>>1|(i[n-1]&1)<<31;i[0]>>>=1,s&&(i[0]^=-520093696)}return o},j:function(t,e,r){var n,o=r.length;for(e=e.slice(0),n=0;no&&(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=[],l=c.bitArray;for(f=1;32*u.length<(n||1);f++){for(o=i=t.encrypt(l.concat(e,[f])),s=1;ss;s++)o.push(4294967296*Math.random()|0);for(s=0;s=1<this.o&&(this.o=i),this.P++,this.b=c.hash.sha256.hash(this.b.concat(o)),this.L=new c.cipher.aes(this.b),n=0;4>n&&(this.h[n]=this.h[n]+1|0,!this.h[n]);n++);}for(n=0;n>>1;this.c[s].update([n,this.N++,2,e,i,t.length].concat(t))}break;case"string":e===void 0&&(e=t.length),this.c[s].update([n,this.N++,3,e,i,t.length]),this.c[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.m[s]+=e,this.f+=e,a===this.u&&(this.isReady()!==this.u&&ue("seeded",Math.max(this.o,this.f)),ue("progress",this.getProgress()))},isReady:function(t){return t=this.T[t!==void 0?t:this.M],this.o&&this.o>=t?this.m[0]>this.ba&&new Date().valueOf()>this.Z?this.J|this.I:this.I:this.f>=t?this.J|this.u:this.u},getProgress:function(t){return t=this.T[t||this.M],this.o>=t||this.f>t?1:this.f/t},startCollectors:function(){if(!this.D){if(this.a={loadTimeCollector:U(this,this.ma),mouseCollector:U(this,this.oa),keyboardCollector:U(this,this.la),accelerometerCollector:U(this,this.ea),touchCollector:U(this,this.qa)},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.K[t][this.ga++]=e},removeEventListener:function(t,e){var r,n,o=this.K[t],i=[];for(n in o)o.hasOwnProperty(n)&&o[n]===e&&i.push(n);for(r=0;re&&(t.h[e]=t.h[e]+1|0,!t.h[e]);e++);return t.L.encrypt(t.h)}function U(t,e){return function(){e.apply(t,arguments)}}c.random=new c.prng(6);e:try{if(K=typeof P<"u"&&P.exports){try{z=Fe("crypto")}catch{z=null}K=G=z}if(K&&G.randomBytes)T=G.randomBytes(128),T=new Uint32Array(new Uint8Array(T).buffer),c.random.addEntropy(T,1024,"crypto['randomBytes']");else if(typeof window<"u"&&typeof Uint32Array<"u"){if(F=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(F);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(F);else break e;c.random.addEntropy(F,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 T,G,F,K,z;c.json={defaults:{v:1,iter:1e4,ks:128,ts:64,mode:"ccm",adata:"",cipher:"aes"},ja:function(t,e,r,n){r=r||{},n=n||{};var o=c.json,i=o.g({iv:c.random.randomWords(4,0)},o.defaults),s;if(o.g(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 I=typeof Reflect=="object"?Reflect:null,ve=I&&typeof I.apply=="function"?I.apply:function(e,r,n){return Function.prototype.apply.call(e,r,n)},q;I&&typeof I.ownKeys=="function"?q=I.ownKeys:Object.getOwnPropertySymbols?q=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:q=function(e){return Object.getOwnPropertyNames(e)};function rt(t){console&&console.warn&&console.warn(t)}var Ee=Number.isNaN||function(e){return e!==e};function d(){d.init.call(this)}ee.exports=d;ee.exports.once=st;d.EventEmitter=d;d.prototype._events=void 0;d.prototype._eventsCount=0;d.prototype._maxListeners=void 0;var we=10;function $(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 we},set:function(t){if(typeof t!="number"||t<0||Ee(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");we=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||Ee(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 Ae(t){return t._maxListeners===void 0?d.defaultMaxListeners:t._maxListeners}d.prototype.getMaxListeners=function(){return Ae(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")ve(f,this,r);else for(var u=f.length,l=De(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,rt(a)}return t}d.prototype.addListener=function(e,r){return xe(this,e,r,!1)};d.prototype.on=d.prototype.addListener;d.prototype.prependListener=function(e,r){return xe(this,e,r,!0)};function nt(){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 Le(t,e,r){var n={fired:!1,wrapFn:void 0,target:t,type:e,listener:r},o=nt.bind(n);return o.listener=r,n.wrapFn=o,o}d.prototype.once=function(e,r){return $(r),this.on(e,Le(this,e,r)),this};d.prototype.prependOnceListener=function(e,r){return $(r),this.prependListener(e,Le(this,e,r)),this};d.prototype.removeListener=function(e,r){var n,o,i,s,a;if($(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():ot(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 be(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?it(o):De(o,o.length)}d.prototype.listeners=function(e){return be(this,e,!0)};d.prototype.rawListeners=function(e){return be(this,e,!1)};d.listenerCount=function(t,e){return typeof t.listenerCount=="function"?t.listenerCount(e):ke.call(t,e)};d.prototype.listenerCount=ke;function ke(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?q(this._events):[]};function De(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 We=new C("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");function R(t){return We.Encode(t)}var Je=new C("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",!0);function X(t){return Je.Decode(t)}var Ke={withStackTrace:!1},se=(t,e,r=Ke)=>{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 S(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(l){try{u(n.next(l))}catch(h){s(h)}}function f(l){try{u(n.throw(l))}catch(h){s(h)}}function u(l){l.done?i(l.value):o(l.value).then(a,f)}u((n=n.apply(t,[])).next())})}function ie(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 k(t){return this instanceof k?(this.v=t,this):new k(t)}function ze(t,e,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=r.apply(t,e||[]),o,i=[];return o={},s("next"),s("throw"),s("return"),o[Symbol.asyncIterator]=function(){return this},o;function s(p){n[p]&&(o[p]=function(m){return new Promise(function(y,O){i.push([p,m,y,O])>1||a(p,m)})})}function a(p,m){try{f(n[p](m))}catch(y){h(i[0][3],y)}}function f(p){p.value instanceof k?Promise.resolve(p.value.v).then(u,l):h(i[0][2],p)}function u(p){a("next",p)}function l(p){a("throw",p)}function h(p,m){p(m),i.shift(),i.length&&a(i[0][0],i[0][1])}}function He(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:k(t[o](s)),done:o==="return"}:i?i(s):s}:i}}function qe(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 ie=="function"?ie(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 v=class t{constructor(e){this._promise=e}static fromSafePromise(e){let r=e.then(n=>new w(n));return new t(r)}static fromPromise(e,r){let n=e.then(o=>new w(o)).catch(o=>new E(r(o)));return new t(n)}static fromThrowable(e,r){return(...n)=>new t(S(this,void 0,void 0,function*(){try{return new w(yield e(...n))}catch(o){return new E(r?r(o):o)}}))}static combine(e){return $e(e)}static combineWithAllErrors(e){return Ye(e)}map(e){return new t(this._promise.then(r=>S(this,void 0,void 0,function*(){return r.isErr()?new E(r.error):new w(yield e(r.value))})))}andThrough(e){return new t(this._promise.then(r=>S(this,void 0,void 0,function*(){if(r.isErr())return new E(r.error);let n=yield e(r.value);return n.isErr()?new E(n.error):new w(r.value)})))}andTee(e){return new t(this._promise.then(r=>S(this,void 0,void 0,function*(){if(r.isErr())return new E(r.error);try{yield e(r.value)}catch{}return new w(r.value)})))}mapErr(e){return new t(this._promise.then(r=>S(this,void 0,void 0,function*(){return r.isOk()?new w(r.value):new E(yield e(r.error))})))}andThen(e){return new t(this._promise.then(r=>{if(r.isErr())return new E(r.error);let n=e(r.value);return n instanceof t?n._promise:n}))}orElse(e){return new t(this._promise.then(r=>S(this,void 0,void 0,function*(){return r.isErr()?e(r.error):new w(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 ze(this,arguments,function*(){return yield k(yield k(yield*He(qe(yield k(this._promise.then(r=>r.safeUnwrap()))))))})}then(e,r){return this._promise.then(e,r)}},J=t=>new v(Promise.resolve(new w(t))),D=t=>new v(Promise.resolve(new E(t))),Et=v.fromPromise,At=v.fromSafePromise,xt=v.fromThrowable,ce=t=>{let e=b([]);for(let r of t)if(r.isErr()){e=A(r.error);break}else e.map(n=>n.push(r.value));return e},$e=t=>v.fromSafePromise(Promise.all(t)).andThen(ce),ae=t=>{let e=b([]);for(let r of t)r.isErr()&&e.isErr()?e.error.push(r.error):r.isErr()&&e.isOk()?e=A([r.error]):r.isOk()&&e.isOk()&&e.value.push(r.value);return e},Ye=t=>v.fromSafePromise(Promise.all(t)).andThen(ae),V;(function(t){function e(o,i){return(...s)=>{try{let a=o(...s);return b(a)}catch(a){return A(i?i(a):a)}}}t.fromThrowable=e;function r(o){return ce(o)}t.combine=r;function n(o){return ae(o)}t.combineWithAllErrors=n})(V||(V={}));var b=t=>new w(t);function A(t){return new E(t)}var w=class{constructor(e){this.value=e}isOk(){return!0}isErr(){return!this.isOk()}map(e){return b(e(this.value))}mapErr(e){return b(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 b(this.value)}orElse(e){return b(this.value)}asyncAndThen(e){return e(this.value)}asyncAndThrough(e){return e(this.value).map(()=>this.value)}asyncMap(e){return v.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 se("Called `_unsafeUnwrapErr` on an Ok",this,e)}},E=class{constructor(e){this.error=e}isOk(){return!1}isErr(){return!this.isOk()}map(e){return A(this.error)}mapErr(e){return A(e(this.error))}andThrough(e){return A(this.error)}andTee(e){return A(this.error)}andThen(e){return A(this.error)}orElse(e){return e(this.error)}asyncAndThen(e){return D(this.error)}asyncAndThrough(e){return D(this.error)}asyncMap(e){return D(this.error)}unwrapOr(e){return e}match(e,r){return r(this.error)}safeUnwrap(){let e=this.error;return function*(){throw yield A(e),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(e){throw se("Called `_unsafeUnwrap` on an Err",this,e)}_unsafeUnwrapErr(e){return this.error}},Lt=V.fromThrowable;var de=ne(le());var M=class extends Error{constructor(r,n={}){let{cause:o,context:i}=n;super(r,{cause:o});L(this,"context");this.name=this.constructor.name,this.context=i}};var x=class extends M{};var H=class extends x{constructor(){super(...arguments);L(this,"message","Unable to encrypt the provided data")}};var _=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 Xe=()=>typeof Deno<"u";var B=t=>Xe()?new URL(`./worker/${t}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${t==="main"?`worker/${t}`:t}.js`));var me=(t,e)=>{try{let r=de.default.encrypt(t,R(e));return J({algo:0,data:r,iv:JSON.parse(r).iv})}catch(r){return D(new H(void 0,{cause:_(r)}))}};var ye=(t,e)=>Qe(t).andThen(r=>{let n=crypto.getRandomValues(new Uint8Array(12));return v.fromPromise(crypto.subtle.encrypt({name:"AES-GCM",iv:n},r,e),o=>_(o)).andThen(o=>J({algo:1,data:R(o),iv:n}))}),Qe=t=>v.fromPromise(crypto.subtle.importKey("raw",X(t),{name:"AES-GCM"},!1,["encrypt","decrypt"]),e=>new x("Unable to import cryptography key",{cause:_(e)}));var ge=(t,e,r)=>{let n;return r===0?n=me(t,e):(typeof e=="string"&&(e=new TextEncoder().encode(e).buffer),n=ye(t,e)),n};var Se=ne(Oe());var te=new Se.default,g,Ce=!1;self.onmessage=t=>{ft(t),Ce||(Ce=!0,te.once("OPERATION_FAILED",()=>{g&&g.terminate()}))};var ft=(t,e)=>{let{action:r}=t.data;if(r===5||r===8)g.postMessage(t.data);else{switch(r){case 2:g=new Worker(B("cancel"),{type:"module"}),g.postMessage(t.data);break;case 3:g=new Worker(B("download"),{type:"module"}),g.postMessage(t.data);break;case 4:g=new Worker(B("infos"),{type:"module"}),g.postMessage(t.data);break;case 7:g=g||new Worker(B("remove"),{type:"module"}),g.postMessage(t.data);break;case 9:g=g||new Worker(B("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}`)}}},Pe=()=>{te.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),te.once("OPERATION_FAILED",t=>{self.postMessage({event:"OPERATION_FAILED",error:t})})};var Me=!1;self.onmessage=t=>{Me||(Pe(),Me=!0);let{lufiFile:e,chunk:r,algo:n}=t.data.args;r&&typeof n<"u"?e.uploadStatus!==2?ge(e.keys.client,r.buffer,n).map(o=>{self.postMessage({encryptedData:o,chunkIndex:r.index})}).mapErr(o=>{self.postMessage({error:o})}):self.postMessage({error:"File upload already failed"}):self.postMessage({error:_("Buffer cannot be undefined")})}; +var Ie=Object.create;var Y=Object.defineProperty;var Re=Object.getOwnPropertyDescriptor;var je=Object.getOwnPropertyNames;var Ue=Object.getPrototypeOf,Te=Object.prototype.hasOwnProperty;var Fe=(t,e,r)=>e in t?Y(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var Ne=(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 re=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var We=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of je(e))!Te.call(t,o)&&o!==r&&Y(t,o,{get:()=>e[o],enumerable:!(n=Re(e,o))||n.enumerable});return t};var ne=(t,e,r)=>(r=t!=null?Ie(Ue(t)):{},We(e||!t||!t.__esModule?Y(r,"default",{value:t,enumerable:!0}):r,t));var D=(t,e,r)=>Fe(t,typeof e!="symbol"?e+"":e,r);var pe=re((kt,B)=>{"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.s[0][0][0]||this.O();var e,r,n,o,i=this.s[0][4],s=this.s[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 ue(this,t,0)},decrypt:function(t){return ue(this,t,1)},s:[[[],[],[],[],[]],[[],[],[],[],[]]],O:function(){var t=this.s[0],e=this.s[1],r=t[4],n=e[4],o,i,s,a=[],f=[],u,l,h,d;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(h=s^s<<1^s<<2^s<<3^s<<4,h=h>>8^h&255^99,r[i]=h,n[h]=i,l=a[o=a[u=a[i]]],d=16843009*l^65537*o^257*u^16843008*i,l=257*a[h]^16843008*h,o=0;4>o;o++)t[o][i]=l=l<<24^l>>>8,e[o][h]=d=d<<24^d>>>8;for(o=0;5>o;o++)t[o]=t[o].slice(0),e[o]=e[o].slice(0)}};function ue(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,l=n.length/4-2,h,d=4,p=[0,0,0,0];a=t.s[r],t=a[0];var m=a[1],x=a[2],S=a[3],C=a[4];for(h=0;h>>24]^m[i>>16&255]^x[s>>8&255]^S[e&255]^n[d],f=t[i>>>24]^m[s>>16&255]^x[e>>8&255]^S[o&255]^n[d+1],u=t[s>>>24]^m[e>>16&255]^x[o>>8&255]^S[i&255]^n[d+2],e=t[e>>>24]^m[o>>16&255]^x[i>>8&255]^S[s&255]^n[d+3],d+=4,o=a,i=f,s=u;for(h=0;4>h;h++)p[r?3&-h:h]=C[o>>>24]<<24^C[i>>16&255]<<16^C[s>>8&255]<<8^C[e&255]^n[d++],a=o,o=i,i=s,s=e,e=a;return p}c.bitArray={bitSlice:function(t,e,r){return t=c.bitArray.$(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>>s)>>>o),sl){if(!e)try{return c.codec.base32hex.toBits(t)}catch{}throw new c.exception.invalid("this isn't "+h+"!")}a>o?(a-=o,i.push(u^l>>>a),u=l<>>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.B,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.O(),t?(this.F=t.F.slice(0),this.A=t.A.slice(0),this.l=t.l):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.F=this.Y.slice(0),this.A=[],this.l=0,this},update:function(t){typeof t=="string"&&(t=c.codec.utf8String.toBits(t));var e,r=this.A=c.bitArray.concat(this.A,t);if(e=this.l,t=this.l=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.Y[e]=t(Math.pow(r,.5))),this.b[e]=t(Math.pow(r,1/3)),e++)}}};function Z(t,e){var r,n,o,i=t.F,s=t.b,a=i[0],f=i[1],u=i[2],l=i[3],h=i[4],d=i[5],p=i[6],m=i[7];for(r=0;64>r;r++)16>r?n=e[r]:(n=e[r+1&15],o=e[r+14&15],n=e[r&15]=(n>>>7^n>>>18^n>>>3^n<<25^n<<14)+(o>>>17^o>>>19^o>>>10^o<<15^o<<13)+e[r&15]+e[r+9&15]|0),n=n+m+(h>>>6^h>>>11^h>>>25^h<<26^h<<21^h<<7)+(p^h&(d^p))+s[r],m=p,p=d,d=h,h=l+n|0,l=u,u=f,f=a,a=n+(f&u^l&(f^u))+(f>>>2^f>>>13^f>>>22^f<<30^f<<19^f<<10)|0;i[0]=i[0]+a|0,i[1]=i[1]+f|0,i[2]=i[2]+u|0,i[3]=i[3]+l|0,i[4]=i[4]+h|0,i[5]=i[5]+d|0,i[6]=i[6]+p|0,i[7]=i[7]+m|0}c.mode.ccm={name:"ccm",G:[],listenProgress:function(t){c.mode.ccm.G.push(t)},unListenProgress:function(t){t=c.mode.ccm.G.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.V(t,e,r,n,o,i),s=c.mode.ccm.C(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.C(t,a,r,f,o,e),t=c.mode.ccm.V(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},na:function(t,e,r,n,o,i){var s=[],a=c.bitArray,f=a.i;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||16l&&(c.mode.ccm.fa(s/f),l+=h),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.mode.ocb2={name:"ocb2",encrypt:function(t,e,r,n,o,i){if(c.bitArray.bitLength(r)!==128)throw new c.exception.invalid("ocb iv must be 128 bits");var s,a=c.mode.ocb2.S,f=c.bitArray,u=f.i,l=[0,0,0,0];r=a(t.encrypt(r));var h,d=[];for(n=n||[],o=o||64,s=0;s+4o.bitLength(r)&&(a=i(a,n(a)),r=o.concat(r,[-2147483648,0,0,0])),s=i(s,r),t.encrypt(i(n(i(a,n(a))),s))},S:function(t){return[t[0]<<1^t[1]>>>31,t[1]<<1^t[2]>>>31,t[2]<<1^t[3]>>>31,t[3]<<1^135*(t[0]>>>31)]}};c.mode.gcm={name:"gcm",encrypt:function(t,e,r,n,o){var i=e.slice(0);return e=c.bitArray,n=n||[],t=c.mode.gcm.C(!0,t,i,n,r,o||128),e.concat(t.data,t.tag)},decrypt:function(t,e,r,n,o){var i=e.slice(0),s=c.bitArray,a=s.bitLength(i);if(o=o||128,n=n||[],o<=a?(e=s.bitSlice(i,a-o),i=s.bitSlice(i,0,a-o)):(e=i,i=[]),t=c.mode.gcm.C(!1,t,i,n,r,o),!s.equal(t.tag,e))throw new c.exception.corrupt("gcm: tag doesn't match");return t.data},ka:function(t,e){var r,n,o,i,s,a=c.bitArray.i;for(o=[0,0,0,0],i=e.slice(0),r=0;128>r;r++){for((n=(t[Math.floor(r/32)]&1<<31-r%32)!==0)&&(o=a(o,i)),s=(i[3]&1)!==0,n=3;0>>1|(i[n-1]&1)<<31;i[0]>>>=1,s&&(i[0]^=-520093696)}return o},j:function(t,e,r){var n,o=r.length;for(e=e.slice(0),n=0;no&&(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=[],l=c.bitArray;for(f=1;32*u.length<(n||1);f++){for(o=i=t.encrypt(l.concat(e,[f])),s=1;ss;s++)o.push(4294967296*Math.random()|0);for(s=0;s=1<this.o&&(this.o=i),this.P++,this.b=c.hash.sha256.hash(this.b.concat(o)),this.L=new c.cipher.aes(this.b),n=0;4>n&&(this.h[n]=this.h[n]+1|0,!this.h[n]);n++);}for(n=0;n>>1;this.c[s].update([n,this.N++,2,e,i,t.length].concat(t))}break;case"string":e===void 0&&(e=t.length),this.c[s].update([n,this.N++,3,e,i,t.length]),this.c[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.m[s]+=e,this.f+=e,a===this.u&&(this.isReady()!==this.u&&he("seeded",Math.max(this.o,this.f)),he("progress",this.getProgress()))},isReady:function(t){return t=this.T[t!==void 0?t:this.M],this.o&&this.o>=t?this.m[0]>this.ba&&new Date().valueOf()>this.Z?this.J|this.I:this.I:this.f>=t?this.J|this.u:this.u},getProgress:function(t){return t=this.T[t||this.M],this.o>=t||this.f>t?1:this.f/t},startCollectors:function(){if(!this.D){if(this.a={loadTimeCollector:F(this,this.ma),mouseCollector:F(this,this.oa),keyboardCollector:F(this,this.la),accelerometerCollector:F(this,this.ea),touchCollector:F(this,this.qa)},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.K[t][this.ga++]=e},removeEventListener:function(t,e){var r,n,o=this.K[t],i=[];for(n in o)o.hasOwnProperty(n)&&o[n]===e&&i.push(n);for(r=0;re&&(t.h[e]=t.h[e]+1|0,!t.h[e]);e++);return t.L.encrypt(t.h)}function F(t,e){return function(){e.apply(t,arguments)}}c.random=new c.prng(6);e:try{if(K=typeof B<"u"&&B.exports){try{z=Ne("crypto")}catch{z=null}K=G=z}if(K&&G.randomBytes)N=G.randomBytes(128),N=new Uint32Array(new Uint8Array(N).buffer),c.random.addEntropy(N,1024,"crypto['randomBytes']");else if(typeof window<"u"&&typeof Uint32Array<"u"){if(W=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(W);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(W);else break e;c.random.addEntropy(W,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 N,G,W,K,z;c.json={defaults:{v:1,iter:1e4,ks:128,ts:64,mode:"ccm",adata:"",cipher:"aes"},ja:function(t,e,r,n){r=r||{},n=n||{};var o=c.json,i=o.g({iv:c.random.randomWords(4,0)},o.defaults),s;if(o.g(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 j=typeof Reflect=="object"?Reflect:null,we=j&&typeof j.apply=="function"?j.apply:function(e,r,n){return Function.prototype.apply.call(e,r,n)},q;j&&typeof j.ownKeys=="function"?q=j.ownKeys:Object.getOwnPropertySymbols?q=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:q=function(e){return Object.getOwnPropertyNames(e)};function rt(t){console&&console.warn&&console.warn(t)}var Ae=Number.isNaN||function(e){return e!==e};function y(){y.init.call(this)}ee.exports=y;ee.exports.once=st;y.EventEmitter=y;y.prototype._events=void 0;y.prototype._eventsCount=0;y.prototype._maxListeners=void 0;var Ee=10;function $(t){if(typeof t!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t)}Object.defineProperty(y,"defaultMaxListeners",{enumerable:!0,get:function(){return Ee},set:function(t){if(typeof t!="number"||t<0||Ae(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");Ee=t}});y.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};y.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||Ae(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 xe(t){return t._maxListeners===void 0?y.defaultMaxListeners:t._maxListeners}y.prototype.getMaxListeners=function(){return xe(this)};y.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")we(f,this,r);else for(var u=f.length,l=_e(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,rt(a)}return t}y.prototype.addListener=function(e,r){return Le(this,e,r,!1)};y.prototype.on=y.prototype.addListener;y.prototype.prependListener=function(e,r){return Le(this,e,r,!0)};function nt(){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 be(t,e,r){var n={fired:!1,wrapFn:void 0,target:t,type:e,listener:r},o=nt.bind(n);return o.listener=r,n.wrapFn=o,o}y.prototype.once=function(e,r){return $(r),this.on(e,be(this,e,r)),this};y.prototype.prependOnceListener=function(e,r){return $(r),this.prependListener(e,be(this,e,r)),this};y.prototype.removeListener=function(e,r){var n,o,i,s,a;if($(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():ot(n,i),n.length===1&&(o[e]=n[0]),o.removeListener!==void 0&&this.emit("removeListener",e,a||r)}return this};y.prototype.off=y.prototype.removeListener;y.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 ke(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?it(o):_e(o,o.length)}y.prototype.listeners=function(e){return ke(this,e,!0)};y.prototype.rawListeners=function(e){return ke(this,e,!1)};y.listenerCount=function(t,e){return typeof t.listenerCount=="function"?t.listenerCount(e):De.call(t,e)};y.prototype.listenerCount=De;function De(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}y.prototype.eventNames=function(){return this._eventsCount>0?q(this._events):[]};function _e(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 Je=new P("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");function U(t){return Je.Encode(t)}var Ge=new P("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",!0);function X(t){return Ge.Decode(t)}var ze={withStackTrace:!1},ce=(t,e,r=ze)=>{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 M(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(l){try{u(n.next(l))}catch(h){s(h)}}function f(l){try{u(n.throw(l))}catch(h){s(h)}}function u(l){l.done?i(l.value):o(l.value).then(a,f)}u((n=n.apply(t,e||[])).next())})}function ie(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 A(t){return this instanceof A?(this.v=t,this):new A(t)}function se(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(m){return Promise.resolve(m).then(p,h)}}function a(p,m){n[p]&&(o[p]=function(x){return new Promise(function(S,C){i.push([p,x,S,C])>1||f(p,x)})},m&&(o[p]=m(o[p])))}function f(p,m){try{u(n[p](m))}catch(x){d(i[0][3],x)}}function u(p){p.value instanceof A?Promise.resolve(p.value.v).then(l,h):d(i[0][2],p)}function l(p){f("next",p)}function h(p){f("throw",p)}function d(p,m){p(m),i.shift(),i.length&&f(i[0][0],i[0][1])}}function He(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:A(t[o](s)),done:!1}:i?i(s):s}:i}}function qe(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 ie=="function"?ie(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 v=class t{constructor(e){this._promise=e}static fromSafePromise(e){let r=e.then(n=>new w(n));return new t(r)}static fromPromise(e,r){let n=e.then(o=>new w(o)).catch(o=>new E(r(o)));return new t(n)}static fromThrowable(e,r){return(...n)=>new t(M(this,void 0,void 0,function*(){try{return new w(yield e(...n))}catch(o){return new E(r?r(o):o)}}))}static combine(e){return $e(e)}static combineWithAllErrors(e){return Ye(e)}map(e){return new t(this._promise.then(r=>M(this,void 0,void 0,function*(){return r.isErr()?new E(r.error):new w(yield e(r.value))})))}andThrough(e){return new t(this._promise.then(r=>M(this,void 0,void 0,function*(){if(r.isErr())return new E(r.error);let n=yield e(r.value);return n.isErr()?new E(n.error):new w(r.value)})))}andTee(e){return new t(this._promise.then(r=>M(this,void 0,void 0,function*(){if(r.isErr())return new E(r.error);try{yield e(r.value)}catch{}return new w(r.value)})))}mapErr(e){return new t(this._promise.then(r=>M(this,void 0,void 0,function*(){return r.isOk()?new w(r.value):new E(yield e(r.error))})))}andThen(e){return new t(this._promise.then(r=>{if(r.isErr())return new E(r.error);let n=e(r.value);return n instanceof t?n._promise:n}))}orElse(e){return new t(this._promise.then(r=>M(this,void 0,void 0,function*(){return r.isErr()?e(r.error):new w(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 se(this,arguments,function*(){return yield A(yield A(yield*He(qe(yield A(this._promise.then(r=>r.safeUnwrap()))))))})}then(e,r){return this._promise.then(e,r)}[Symbol.asyncIterator](){return se(this,arguments,function*(){let r=yield A(this._promise);return r.isErr()&&(yield yield A(b(r.error))),yield A(r.value)})}},J=t=>new v(Promise.resolve(new w(t))),b=t=>new v(Promise.resolve(new E(t))),Et=v.fromPromise,At=v.fromSafePromise,xt=v.fromThrowable,ae=t=>{let e=_([]);for(let r of t)if(r.isErr()){e=L(r.error);break}else e.map(n=>n.push(r.value));return e},$e=t=>v.fromSafePromise(Promise.all(t)).andThen(ae),fe=t=>{let e=_([]);for(let r of t)r.isErr()&&e.isErr()?e.error.push(r.error):r.isErr()&&e.isOk()?e=L([r.error]):r.isOk()&&e.isOk()&&e.value.push(r.value);return e},Ye=t=>v.fromSafePromise(Promise.all(t)).andThen(fe),V;(function(t){function e(o,i){return(...s)=>{try{let a=o(...s);return _(a)}catch(a){return L(i?i(a):a)}}}t.fromThrowable=e;function r(o){return ae(o)}t.combine=r;function n(o){return fe(o)}t.combineWithAllErrors=n})(V||(V={}));var _=t=>new w(t);function L(t){return new E(t)}var w=class{constructor(e){this.value=e}isOk(){return!0}isErr(){return!this.isOk()}map(e){return _(e(this.value))}mapErr(e){return _(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 _(this.value)}orElse(e){return _(this.value)}asyncAndThen(e){return e(this.value)}asyncAndThrough(e){return e(this.value).map(()=>this.value)}asyncMap(e){return v.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 ce("Called `_unsafeUnwrapErr` on an Ok",this,e)}*[Symbol.iterator](){return this.value}},E=class{constructor(e){this.error=e}isOk(){return!1}isErr(){return!this.isOk()}map(e){return L(this.error)}mapErr(e){return L(e(this.error))}andThrough(e){return L(this.error)}andTee(e){return L(this.error)}andThen(e){return L(this.error)}orElse(e){return e(this.error)}asyncAndThen(e){return b(this.error)}asyncAndThrough(e){return b(this.error)}asyncMap(e){return b(this.error)}unwrapOr(e){return e}match(e,r){return r(this.error)}safeUnwrap(){let e=this.error;return function*(){throw yield L(e),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(e){throw ce("Called `_unsafeUnwrap` on an Err",this,e)}_unsafeUnwrapErr(e){return this.error}*[Symbol.iterator](){let e=this;return yield e,e}},Lt=V.fromThrowable;var me=ne(pe());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 k=class extends I{};var H=class extends k{constructor(){super(...arguments);D(this,"message","Unable to encrypt the provided data")}};var O=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 Xe=()=>typeof Deno<"u";var R=t=>Xe()?new URL(`./worker/${t}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${t==="main"?`worker/${t}`:t}.js`));var ye=(t,e)=>{try{let r=me.default.encrypt(t,U(e));return J({algo:0,data:r,iv:JSON.parse(r).iv})}catch(r){return b(new H(void 0,{cause:O(r)}))}};var ge=(t,e)=>Qe(t).andThen(r=>{let n=crypto.getRandomValues(new Uint8Array(12));return v.fromPromise(crypto.subtle.encrypt({name:"AES-GCM",iv:n},r,e),o=>O(o)).andThen(o=>J({algo:1,data:U(o),iv:n}))}),Qe=t=>v.fromPromise(crypto.subtle.importKey("raw",X(t),{name:"AES-GCM"},!1,["encrypt","decrypt"]),e=>new k("Unable to import cryptography key",{cause:O(e)}));var ve=(t,e,r)=>{let n;return r===0?n=ye(t,e):(typeof e=="string"&&(e=new TextEncoder().encode(e).buffer),n=ge(t,e)),n};var Pe=ne(Se());var te=new Pe.default,g,Ce=!1;self.onmessage=t=>{ft(t),Ce||(Ce=!0,te.once("OPERATION_FAILED",()=>{g&&g.terminate()}))};var ft=(t,e)=>{let{action:r}=t.data;if(r===5||r===8)g.postMessage(t.data);else{switch(r){case 2:g=new Worker(R("cancel"),{type:"module"}),g.postMessage(t.data);break;case 3:g=new Worker(R("download"),{type:"module"}),g.postMessage(t.data);break;case 4:g=new Worker(R("infos"),{type:"module"}),g.postMessage(t.data);break;case 7:g=g||new Worker(R("remove"),{type:"module"}),g.postMessage(t.data);break;case 9:g=g||new Worker(R("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}`)}}},Me=()=>{te.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),te.once("OPERATION_FAILED",t=>{self.postMessage({event:"OPERATION_FAILED",error:t})})};var Be=!1;self.onmessage=t=>{Be||(Me(),Be=!0);let{lufiFile:e,chunk:r,algo:n}=t.data.args;r&&typeof n<"u"?e.uploadStatus!==2?ve(e.keys.client,r.buffer,n).map(o=>{self.postMessage({encryptedData:o,chunkIndex:r.index})}).mapErr(o=>{self.postMessage({error:o})}):self.postMessage({error:"File upload already failed"}):self.postMessage({error:O("Buffer cannot be undefined")})}; diff --git a/themes/default/public/js/worker/infos.js b/themes/default/public/js/worker/infos.js index f22af70..4646b28 100644 --- a/themes/default/public/js/worker/infos.js +++ b/themes/default/public/js/worker/infos.js @@ -1 +1 @@ -var ze=Object.create;var te=Object.defineProperty;var Ge=Object.getOwnPropertyDescriptor;var He=Object.getOwnPropertyNames;var $e=Object.getPrototypeOf,qe=Object.prototype.hasOwnProperty;var Ve=(e,t,r)=>t in e?te(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var Ke=(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 fe=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Ye=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of He(t))!qe.call(e,o)&&o!==r&&te(e,o,{get:()=>t[o],enumerable:!(n=Ge(t,o))||n.enumerable});return e};var ue=(e,t,r)=>(r=e!=null?ze($e(e)):{},Ye(t||!e||!e.__esModule?te(r,"default",{value:e,enumerable:!0}):r,e));var b=(e,t,r)=>Ve(e,typeof t!="symbol"?t+"":t,r);var De=fe((sr,ne)=>{"use strict";var U=typeof Reflect=="object"?Reflect:null,me=U&&typeof U.apply=="function"?U.apply:function(t,r,n){return Function.prototype.apply.call(t,r,n)},V;U&&typeof U.ownKeys=="function"?V=U.ownKeys:Object.getOwnPropertySymbols?V=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:V=function(t){return Object.getOwnPropertyNames(t)};function it(e){console&&console.warn&&console.warn(e)}var ge=Number.isNaN||function(t){return t!==t};function p(){p.init.call(this)}ne.exports=p;ne.exports.once=ft;p.EventEmitter=p;p.prototype._events=void 0;p.prototype._eventsCount=0;p.prototype._maxListeners=void 0;var ye=10;function K(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 ye},set:function(e){if(typeof e!="number"||e<0||ge(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");ye=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||ge(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 ve(e){return e._maxListeners===void 0?p.defaultMaxListeners:e._maxListeners}p.prototype.getMaxListeners=function(){return ve(this)};p.prototype.emit=function(t){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[t];if(f===void 0)return!1;if(typeof f=="function")me(f,this,r);else for(var u=f.length,l=xe(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(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=s.length,it(a)}return e}p.prototype.addListener=function(t,r){return we(this,t,r,!1)};p.prototype.on=p.prototype.addListener;p.prototype.prependListener=function(t,r){return we(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 Ee(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 K(r),this.on(t,Ee(this,t,r)),this};p.prototype.prependOnceListener=function(t,r){return K(r),this.prependListener(t,Ee(this,t,r)),this};p.prototype.removeListener=function(t,r){var n,o,i,s,a;if(K(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){a=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,a||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 Ae(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?at(o):xe(o,o.length)}p.prototype.listeners=function(t){return Ae(this,t,!0)};p.prototype.rawListeners=function(t){return Ae(this,t,!1)};p.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):Le.call(e,t)};p.prototype.listenerCount=Le;function Le(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?V(this._events):[]};function xe(e,t){for(var r=new Array(t),n=0;n{"use strict";var c={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}}};c.cipher.aes=function(e){this.s[0][0][0]||this.O();var t,r,n,o,i=this.s[0][4],s=this.s[1];t=e.length;var a=1;if(t!==4&&t!==6&&t!==8)throw new c.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^a<<24,a=a<<1^283*(a>>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]]};c.cipher.aes.prototype={encrypt:function(e){return Re(this,e,0)},decrypt:function(e){return Re(this,e,1)},s:[[[],[],[],[],[]],[[],[],[],[],[]]],O:function(){var e=this.s[0],t=this.s[1],r=e[4],n=t[4],o,i,s,a=[],f=[],u,l,h,d;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(h=s^s<<1^s<<2^s<<3^s<<4,h=h>>8^h&255^99,r[i]=h,n[h]=i,l=a[o=a[u=a[i]]],d=16843009*l^65537*o^257*u^16843008*i,l=257*a[h]^16843008*h,o=0;4>o;o++)e[o][i]=l=l<<24^l>>>8,t[o][h]=d=d<<24^d>>>8;for(o=0;5>o;o++)e[o]=e[o].slice(0),t[o]=t[o].slice(0)}};function Re(e,t,r){if(t.length!==4)throw new c.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 a,f,u,l=n.length/4-2,h,d=4,y=[0,0,0,0];a=e.s[r],e=a[0];var g=a[1],M=a[2],$=a[3],q=a[4];for(h=0;h>>24]^g[i>>16&255]^M[s>>8&255]^$[t&255]^n[d],f=e[i>>>24]^g[s>>16&255]^M[t>>8&255]^$[o&255]^n[d+1],u=e[s>>>24]^g[t>>16&255]^M[o>>8&255]^$[i&255]^n[d+2],t=e[t>>>24]^g[o>>16&255]^M[i>>8&255]^$[s&255]^n[d+3],d+=4,o=a,i=f,s=u;for(h=0;4>h;h++)y[r?3&-h:h]=q[o>>>24]<<24^q[i>>16&255]<<16^q[s>>8&255]<<8^q[t&255]^n[d++],a=o,o=i,i=s,s=t,t=a;return y}c.bitArray={bitSlice:function(e,t,r){return e=c.bitArray.$(e.slice(t/32),32-(t&31)).slice(1),r===void 0?e:c.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(c.bitArray.bitLength(e)!==c.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=c.bitArray.getPartial(o),n.push(c.bitArray.partial(t+e&31,32>>24|r>>>8&65280|(r&65280)<<8|r<<24;return e}};c.codec.utf8String={fromBits:function(e){var t="",r=c.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>>s)>>>o),sl){if(!t)try{return c.codec.base32hex.toBits(e)}catch{}throw new c.exception.invalid("this isn't "+h+"!")}a>o?(a-=o,i.push(u^l>>>a),u=l<>>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=c.codec.base64.B,s=0,a;for(t&&(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(e){return c.codec.base64.fromBits(e,1,1)},toBits:function(e){return c.codec.base64.toBits(e,1)}};c.hash.sha256=function(e){this.b[0]||this.O(),e?(this.F=e.F.slice(0),this.A=e.A.slice(0),this.l=e.l):this.reset()};c.hash.sha256.hash=function(e){return new c.hash.sha256().update(e).finalize()};c.hash.sha256.prototype={blockSize:512,reset:function(){return this.F=this.Y.slice(0),this.A=[],this.l=0,this},update:function(e){typeof e=="string"&&(e=c.codec.utf8String.toBits(e));var t,r=this.A=c.bitArray.concat(this.A,e);if(t=this.l,e=this.l=t+c.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.Y[t]=e(Math.pow(r,.5))),this.b[t]=e(Math.pow(r,1/3)),t++)}}};function ie(e,t){var r,n,o,i=e.F,s=e.b,a=i[0],f=i[1],u=i[2],l=i[3],h=i[4],d=i[5],y=i[6],g=i[7];for(r=0;64>r;r++)16>r?n=t[r]:(n=t[r+1&15],o=t[r+14&15],n=t[r&15]=(n>>>7^n>>>18^n>>>3^n<<25^n<<14)+(o>>>17^o>>>19^o>>>10^o<<15^o<<13)+t[r&15]+t[r+9&15]|0),n=n+g+(h>>>6^h>>>11^h>>>25^h<<26^h<<21^h<<7)+(y^h&(d^y))+s[r],g=y,y=d,d=h,h=l+n|0,l=u,u=f,f=a,a=n+(f&u^l&(f^u))+(f>>>2^f>>>13^f>>>22^f<<30^f<<19^f<<10)|0;i[0]=i[0]+a|0,i[1]=i[1]+f|0,i[2]=i[2]+u|0,i[3]=i[3]+l|0,i[4]=i[4]+h|0,i[5]=i[5]+d|0,i[6]=i[6]+y|0,i[7]=i[7]+g|0}c.mode.ccm={name:"ccm",G:[],listenProgress:function(e){c.mode.ccm.G.push(e)},unListenProgress:function(e){e=c.mode.ccm.G.indexOf(e),-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)),t=c.mode.ccm.V(e,t,r,n,o,i),s=c.mode.ccm.C(e,s,r,t,o,i),a.concat(s.data,s.tag)},decrypt:function(e,t,r,n,o){o=o||64,n=n||[];var i=c.bitArray,s=i.bitLength(r)/8,u=i.bitLength(t),a=i.clamp(t,u-o),f=i.bitSlice(t,u-o),u=(u-o)/8;if(7>s)throw new c.exception.invalid("ccm: iv must be at least 7 bytes");for(t=2;4>t&&u>>>8*t;t++);if(t<15-s&&(t=15-s),r=i.clamp(r,8*(15-t)),a=c.mode.ccm.C(e,a,r,f,o,t),e=c.mode.ccm.V(e,a.data,r,n,o,t),!i.equal(a.tag,e))throw new c.exception.corrupt("ccm: tag doesn't match");return a.data},na:function(e,t,r,n,o,i){var s=[],a=c.bitArray,f=a.i;if(n=[a.partial(8,(t.length?64:0)|n-2<<2|i-1)],n=a.concat(n,r),n[3]|=o,n=e.encrypt(n),t.length)for(r=a.bitLength(t)/8,65279>=r?s=[a.partial(16,r)]:4294967295>=r&&(s=a.concat([a.partial(16,65534)],[r])),s=a.concat(s,t),t=0;to||16l&&(c.mode.ccm.fa(s/f),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:a.clamp(t,u)}}};c.mode.ocb2={name:"ocb2",encrypt:function(e,t,r,n,o,i){if(c.bitArray.bitLength(r)!==128)throw new c.exception.invalid("ocb iv must be 128 bits");var s,a=c.mode.ocb2.S,f=c.bitArray,u=f.i,l=[0,0,0,0];r=a(e.encrypt(r));var h,d=[];for(n=n||[],o=o||64,s=0;s+4o.bitLength(r)&&(a=i(a,n(a)),r=o.concat(r,[-2147483648,0,0,0])),s=i(s,r),e.encrypt(i(n(i(a,n(a))),s))},S:function(e){return[e[0]<<1^e[1]>>>31,e[1]<<1^e[2]>>>31,e[2]<<1^e[3]>>>31,e[3]<<1^135*(e[0]>>>31)]}};c.mode.gcm={name:"gcm",encrypt:function(e,t,r,n,o){var i=t.slice(0);return t=c.bitArray,n=n||[],e=c.mode.gcm.C(!0,e,i,n,r,o||128),t.concat(e.data,e.tag)},decrypt:function(e,t,r,n,o){var i=t.slice(0),s=c.bitArray,a=s.bitLength(i);if(o=o||128,n=n||[],o<=a?(t=s.bitSlice(i,a-o),i=s.bitSlice(i,0,a-o)):(t=i,i=[]),e=c.mode.gcm.C(!1,e,i,n,r,o),!s.equal(e.tag,t))throw new c.exception.corrupt("gcm: tag doesn't match");return e.data},ka:function(e,t){var r,n,o,i,s,a=c.bitArray.i;for(o=[0,0,0,0],i=t.slice(0),r=0;128>r;r++){for((n=(e[Math.floor(r/32)]&1<<31-r%32)!==0)&&(o=a(o,i)),s=(i[3]&1)!==0,n=3;0>>1|(i[n-1]&1)<<31;i[0]>>>=1,s&&(i[0]^=-520093696)}return o},j:function(e,t,r){var n,o=r.length;for(t=t.slice(0),n=0;no&&(e=t.hash(e)),n=0;nn||0>r)throw new c.exception.invalid("invalid params to pbkdf2");typeof e=="string"&&(e=c.codec.utf8String.toBits(e)),typeof t=="string"&&(t=c.codec.utf8String.toBits(t)),o=o||c.misc.hmac,e=new o(e);var i,s,a,f,u=[],l=c.bitArray;for(f=1;32*u.length<(n||1);f++){for(o=i=e.encrypt(l.concat(t,[f])),s=1;ss;s++)o.push(4294967296*Math.random()|0);for(s=0;s=1<this.o&&(this.o=i),this.P++,this.b=c.hash.sha256.hash(this.b.concat(o)),this.L=new c.cipher.aes(this.b),n=0;4>n&&(this.h[n]=this.h[n]+1|0,!this.h[n]);n++);}for(n=0;n>>1;this.c[s].update([n,this.N++,2,t,i,e.length].concat(e))}break;case"string":t===void 0&&(t=e.length),this.c[s].update([n,this.N++,3,t,i,e.length]),this.c[s].update(e);break;default:f=1}if(f)throw new c.exception.bug("random: addEntropy only supports number, array of numbers or string");this.m[s]+=t,this.f+=t,a===this.u&&(this.isReady()!==this.u&&Pe("seeded",Math.max(this.o,this.f)),Pe("progress",this.getProgress()))},isReady:function(e){return e=this.T[e!==void 0?e:this.M],this.o&&this.o>=e?this.m[0]>this.ba&&new Date().valueOf()>this.Z?this.J|this.I:this.I:this.f>=e?this.J|this.u:this.u},getProgress:function(e){return e=this.T[e||this.M],this.o>=e||this.f>e?1:this.f/e},startCollectors:function(){if(!this.D){if(this.a={loadTimeCollector:z(this,this.ma),mouseCollector:z(this,this.oa),keyboardCollector:z(this,this.la),accelerometerCollector:z(this,this.ea),touchCollector:z(this,this.qa)},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(e,t){this.K[e][this.ga++]=t},removeEventListener:function(e,t){var r,n,o=this.K[e],i=[];for(n in o)o.hasOwnProperty(n)&&o[n]===t&&i.push(n);for(r=0;rt&&(e.h[t]=e.h[t]+1|0,!e.h[t]);t++);return e.L.encrypt(e.h)}function z(e,t){return function(){t.apply(e,arguments)}}c.random=new c.prng(6);e:try{if(Z=typeof j<"u"&&j.exports){try{Q=Ke("crypto")}catch{Q=null}Z=Y=Q}if(Z&&Y.randomBytes)G=Y.randomBytes(128),G=new Uint32Array(new Uint8Array(G).buffer),c.random.addEntropy(G,1024,"crypto['randomBytes']");else if(typeof window<"u"&&typeof Uint32Array<"u"){if(H=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(H);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(H);else break e;c.random.addEntropy(H,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 G,Y,H,Z,Q;c.json={defaults:{v:1,iter:1e4,ks:128,ts:64,mode:"ccm",adata:"",cipher:"aes"},ja:function(e,t,r,n){r=r||{},n=n||{};var o=c.json,i=o.g({iv:c.random.randomWords(4,0)},o.defaults),s;if(o.g(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 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 T(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 a(l){try{u(n.next(l))}catch(h){s(h)}}function f(l){try{u(n.throw(l))}catch(h){s(h)}}function u(l){l.done?i(l.value):o(l.value).then(a,f)}u((n=n.apply(e,[])).next())})}function he(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 R(e){return this instanceof R?(this.v=e,this):new R(e)}function Qe(e,t,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=r.apply(e,t||[]),o,i=[];return o={},s("next"),s("throw"),s("return"),o[Symbol.asyncIterator]=function(){return this},o;function s(d){n[d]&&(o[d]=function(y){return new Promise(function(g,M){i.push([d,y,g,M])>1||a(d,y)})})}function a(d,y){try{f(n[d](y))}catch(g){h(i[0][3],g)}}function f(d){d.value instanceof R?Promise.resolve(d.value.v).then(u,l):h(i[0][2],d)}function u(d){a("next",d)}function l(d){a("throw",d)}function h(d,y){d(y),i.shift(),i.length&&a(i[0][0],i[0][1])}}function et(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:R(e[o](s)),done:o==="return"}:i?i(s):s}:i}}function tt(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 he=="function"?he(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(a,f){s=e[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 w=class e{constructor(t){this._promise=t}static fromSafePromise(t){let r=t.then(n=>new L(n));return new e(r)}static fromPromise(t,r){let n=t.then(o=>new L(o)).catch(o=>new x(r(o)));return new e(n)}static fromThrowable(t,r){return(...n)=>new e(T(this,void 0,void 0,function*(){try{return new L(yield t(...n))}catch(o){return new x(r?r(o):o)}}))}static combine(t){return rt(t)}static combineWithAllErrors(t){return nt(t)}map(t){return new e(this._promise.then(r=>T(this,void 0,void 0,function*(){return r.isErr()?new x(r.error):new L(yield t(r.value))})))}andThrough(t){return new e(this._promise.then(r=>T(this,void 0,void 0,function*(){if(r.isErr())return new x(r.error);let n=yield t(r.value);return n.isErr()?new x(n.error):new L(r.value)})))}andTee(t){return new e(this._promise.then(r=>T(this,void 0,void 0,function*(){if(r.isErr())return new x(r.error);try{yield t(r.value)}catch{}return new L(r.value)})))}mapErr(t){return new e(this._promise.then(r=>T(this,void 0,void 0,function*(){return r.isOk()?new L(r.value):new x(yield t(r.error))})))}andThen(t){return new e(this._promise.then(r=>{if(r.isErr())return new x(r.error);let n=t(r.value);return n instanceof e?n._promise:n}))}orElse(t){return new e(this._promise.then(r=>T(this,void 0,void 0,function*(){return r.isErr()?t(r.error):new L(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 Qe(this,arguments,function*(){return yield R(yield R(yield*et(tt(yield R(this._promise.then(r=>r.safeUnwrap()))))))})}then(t,r){return this._promise.then(t,r)}},O=e=>new w(Promise.resolve(new L(e))),E=e=>new w(Promise.resolve(new x(e))),Mt=w.fromPromise,Tt=w.fromSafePromise,It=w.fromThrowable,de=e=>{let t=C([]);for(let r of e)if(r.isErr()){t=S(r.error);break}else t.map(n=>n.push(r.value));return t},rt=e=>w.fromSafePromise(Promise.all(e)).andThen(de),pe=e=>{let t=C([]);for(let r of e)r.isErr()&&t.isErr()?t.error.push(r.error):r.isErr()&&t.isOk()?t=S([r.error]):r.isOk()&&t.isOk()&&t.value.push(r.value);return t},nt=e=>w.fromSafePromise(Promise.all(e)).andThen(pe),re;(function(e){function t(o,i){return(...s)=>{try{let a=o(...s);return C(a)}catch(a){return S(i?i(a):a)}}}e.fromThrowable=t;function r(o){return de(o)}e.combine=r;function n(o){return pe(o)}e.combineWithAllErrors=n})(re||(re={}));var C=e=>new L(e);function S(e){return new x(e)}var L=class{constructor(t){this.value=t}isOk(){return!0}isErr(){return!this.isOk()}map(t){return C(t(this.value))}mapErr(t){return C(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 C(this.value)}orElse(t){return C(this.value)}asyncAndThen(t){return t(this.value)}asyncAndThrough(t){return t(this.value).map(()=>this.value)}asyncMap(t){return w.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 le("Called `_unsafeUnwrapErr` on an Ok",this,t)}},x=class{constructor(t){this.error=t}isOk(){return!1}isErr(){return!this.isOk()}map(t){return S(this.error)}mapErr(t){return S(t(this.error))}andThrough(t){return S(this.error)}andTee(t){return S(this.error)}andThen(t){return S(this.error)}orElse(t){return t(this.error)}asyncAndThen(t){return E(this.error)}asyncAndThrough(t){return E(this.error)}asyncMap(t){return E(this.error)}unwrapOr(t){return t}match(t,r){return r(this.error)}safeUnwrap(){let t=this.error;return function*(){throw yield S(t),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(t){throw le("Called `_unsafeUnwrap` on an Err",this,t)}_unsafeUnwrapErr(t){return this.error}},Ut=re.fromThrowable;var k=class extends Error{constructor(r,n={}){let{cause:o,context:i}=n;super(r,{cause:o});b(this,"context");this.name=this.constructor.name,this.context=i}};var D=class extends k{};var J=class extends D{constructor(){super(...arguments);b(this,"message","An error occured while trying to connect to WebSocket")}};var P=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 ot=()=>typeof Deno<"u";var I=e=>ot()?new URL(`./worker/${e}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${e==="main"?`worker/${e}`:e}.js`));var ke=ue(De());var m=new ke.default,v,be=!1;self.onmessage=e=>{lt(e),be||(be=!0,m.once("OPERATION_FAILED",()=>{v&&v.terminate()}))};var B=(e,t)=>(Object.assign(e,t),typeof WorkerGlobalScope<"u"&&self.postMessage({event:"FILE_UPDATED",lufiFile:e}),e);var lt=(e,t)=>{let{action:r}=e.data;if(r===5||r===8)v.postMessage(e.data);else{switch(r){case 2:v=new Worker(I("cancel"),{type:"module"}),v.postMessage(e.data);break;case 3:v=new Worker(I("download"),{type:"module"}),v.postMessage(e.data);break;case 4:v=new Worker(I("infos"),{type:"module"}),v.postMessage(e.data);break;case 7:v=v||new Worker(I("remove"),{type:"module"}),v.postMessage(e.data);break;case 9:v=v||new Worker(I("upload"),{type:"module"}),v.postMessage(e.data);break;default:console.error("Action not found")}v.onmessage=n=>{t&&t(n),self.postMessage(n.data)},v.onerror=n=>{console.error(`Error: ${n.message}`)}}},_e=()=>{m.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),m.once("OPERATION_FAILED",e=>{self.postMessage({event:"OPERATION_FAILED",error:e})})};var N=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,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 dt=new N("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");function F(e){return dt.Decode(e)}var pt=new N("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",!0);function oe(e){return pt.Decode(e)}var Ue=ue(Te());var _=class extends k{};var W=class extends _{constructor(){super(...arguments);b(this,"message","Unable to decrypt the provided data")}};var Be=(e,t)=>{try{let r=typeof t=="string"?t:t.data;return O(F(Ue.default.decrypt(e,r)))}catch(r){return E(new W(void 0,{cause:P(r)}))}};var Ne=(e,t)=>gt(e).andThen(r=>w.fromPromise(crypto.subtle.decrypt({name:"AES-GCM",iv:t.iv},r,F(t.data)),n=>new W(void 0,{cause:P(n)})));var gt=e=>w.fromPromise(crypto.subtle.importKey("raw",oe(e),{name:"AES-GCM"},!1,["encrypt","decrypt"]),t=>new _("Unable to import cryptography key",{cause:P(t)}));var je=(e,t)=>t.algo===void 0||t.algo===0?Be(e,t):Ne(e,t);var A={},We=5,Et=e=>(m.emit("UPLOAD_CANCELLED",e.success),O(void 0)),At=(e,t)=>{let r=e.split("XXMOJOXX"),n=r.shift();if(n!==void 0){let o=JSON.parse(n);if(_t(o)){let i=r.shift();if(i){let s=JSON.parse(i);return s.iv&&(s.iv=new Uint8Array(Object.values(s.iv))),je(t.keys.client,s).andThen(a=>{let f=typeof a=="string"?new TextEncoder().encode(a).buffer:a;return o.part===0?(B(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")):B(t,{chunksReady:t.chunksReady+1}),m.emit("CHUNK_DOWNLOADED",f,o.part),++o.part===o.total?Dt(t).andThen(()=>(m.emit("DOWNLOAD_COMPLETE"),m.emit("SOCKET_OPERATION_TERMINATED"),O(void 0))):O(void 0)})}else{let s=new D("Can't retrieve metadata from data received by the server");return m.emit("OPERATION_FAILED",s),E(s)}}else{let i=new D(o.msg);return m.emit("OPERATION_FAILED",i),E(i)}}else{let o=new D("Can't retrieve metadata from data received by the server");return m.emit("OPERATION_FAILED",o),E(o)}},Lt=(e,t)=>{if(e.success)return e.j===0&&(B(t,{keys:{client:t.keys.client,server:e.short},actionToken:e.token,queueIndex:e.i}),m.emit("UPLOAD_STARTED")),B(t,{chunksReady:t.chunksReady+1,createdAt:e.created_at}),m.emit("CHUNK_UPLOADED"),t.chunksReady===t.totalChunks&&(B(t,{uploadStatus:1}),m.emit("UPLOAD_COMPLETE"),m.emit("SOCKET_OPERATION_TERMINATED")),O(void 0);{let r=new D(e.msg);return m.emit("OPERATION_FAILED",r),E(r)}},xt=(e,t)=>{let r=kt(e.data),n;if(r)if(!r.action&&r.msg){let o=new D(r.msg);return m.emit("OPERATION_FAILED",o),E(o)}else"delay"in r?n=Lt(r,t):n=Et(r);else n=At(e.data,t);return n},Ot=e=>A!==void 0&&A[e]!==void 0&&A[e].readyState===WebSocket.CONNECTING,ce=e=>A!==void 0&&A[e]!==void 0&&A[e].readyState===WebSocket.OPEN;var Je=(e,t)=>{let r;return e.password?r={part:t,file_pwd:e.password}:r={part:t},ae(ee(e),e,JSON.stringify(r))},Dt=e=>{let t;return e.password?t={ended:!0,file_pwd:e.password}:t={ended:!0},ae(ee(e),e,JSON.stringify(t))};var ae=(e,t,r)=>ce(e)?(A[e].onmessage=n=>xt(n,t),A[e].send(r),O(void 0)):Fe(e).andThen(()=>ae(e,t,r)),Fe=(e,t=0)=>(!ce(e)&&!Ot(e)&&(A[e]=new WebSocket(e),m.once("SOCKET_OPERATION_TERMINATED",()=>{A[e].close()}),m.once("OPERATION_FAILED",()=>{m.emit("SOCKET_OPERATION_TERMINATED")}),A[e].onopen=()=>{m.emit("SOCKET_OPENED")},A[e].onclose=()=>{},A[e].onerror=()=>++t<=We?(console.error(`An error happened while trying to connect to WebSocket ${e}. Trying again. ${t} / ${We}`),Fe(e,t)):(m.emit("SOCKET_ONERROR"),E(new J(`Unable to connect to WebSocket ${e}.`)))),bt(e).andThen(()=>O(e)).orElse(r=>E(r))),bt=e=>w.fromPromise(new Promise((t,r)=>{ce(e)?t(void 0):(m.once("SOCKET_OPENED",()=>{t(void 0)}),m.on("SOCKET_ONERROR",()=>{r(new J)}))}),t=>P(t));var St=(e,t)=>{let r=new URL(e);return r.protocol=r.protocol==="http:"?"ws:":"wss:",r.pathname+=t,new URL(r.origin+r.pathname)},ee=e=>St(new URL(e.serverUrl),"download"+`/${e.keys.server}`).toString();var kt=e=>{try{let t=JSON.parse(e);if(t&&typeof t=="object")return t}catch{}return!1},_t=e=>typeof e=="object"&&e!==null&&!("msg"in e);var Xe=!1;self.onmessage=e=>{Xe||(_e(),Xe=!0),m.on("DOWNLOAD_STARTED",()=>{A[ee(e.data.args.lufiFile)].close(),self.postMessage({event:"INFOS_RETRIEVED"})}),Rt(e.data).mapErr(t=>{self.postMessage({event:"OPERATION_FAILED",error:t})})};var Rt=e=>Je(e.args.lufiFile,0); +var Ge=Object.create;var te=Object.defineProperty;var He=Object.getOwnPropertyDescriptor;var $e=Object.getOwnPropertyNames;var qe=Object.getPrototypeOf,Ve=Object.prototype.hasOwnProperty;var Ke=(e,t,r)=>t in e?te(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var Ye=(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 fe=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Ze=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of $e(t))!Ve.call(e,o)&&o!==r&&te(e,o,{get:()=>t[o],enumerable:!(n=He(t,o))||n.enumerable});return e};var ue=(e,t,r)=>(r=e!=null?Ge(qe(e)):{},Ze(t||!e||!e.__esModule?te(r,"default",{value:e,enumerable:!0}):r,e));var k=(e,t,r)=>Ke(e,typeof t!="symbol"?t+"":t,r);var Se=fe((sr,ne)=>{"use strict";var N=typeof Reflect=="object"?Reflect:null,ye=N&&typeof N.apply=="function"?N.apply:function(t,r,n){return Function.prototype.apply.call(t,r,n)},V;N&&typeof N.ownKeys=="function"?V=N.ownKeys:Object.getOwnPropertySymbols?V=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:V=function(t){return Object.getOwnPropertyNames(t)};function it(e){console&&console.warn&&console.warn(e)}var ve=Number.isNaN||function(t){return t!==t};function y(){y.init.call(this)}ne.exports=y;ne.exports.once=ft;y.EventEmitter=y;y.prototype._events=void 0;y.prototype._eventsCount=0;y.prototype._maxListeners=void 0;var ge=10;function K(e){if(typeof e!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}Object.defineProperty(y,"defaultMaxListeners",{enumerable:!0,get:function(){return ge},set:function(e){if(typeof e!="number"||e<0||ve(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");ge=e}});y.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};y.prototype.setMaxListeners=function(t){if(typeof t!="number"||t<0||ve(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?y.defaultMaxListeners:e._maxListeners}y.prototype.getMaxListeners=function(){return we(this)};y.prototype.emit=function(t){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[t];if(f===void 0)return!1;if(typeof f=="function")ye(f,this,r);else for(var u=f.length,l=Oe(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(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning",a.emitter=e,a.type=t,a.count=s.length,it(a)}return e}y.prototype.addListener=function(t,r){return Ee(this,t,r,!1)};y.prototype.on=y.prototype.addListener;y.prototype.prependListener=function(t,r){return Ee(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 Ae(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}y.prototype.once=function(t,r){return K(r),this.on(t,Ae(this,t,r)),this};y.prototype.prependOnceListener=function(t,r){return K(r),this.prependListener(t,Ae(this,t,r)),this};y.prototype.removeListener=function(t,r){var n,o,i,s,a;if(K(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){a=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,a||r)}return this};y.prototype.off=y.prototype.removeListener;y.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 Le(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?at(o):Oe(o,o.length)}y.prototype.listeners=function(t){return Le(this,t,!0)};y.prototype.rawListeners=function(t){return Le(this,t,!1)};y.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):xe.call(e,t)};y.prototype.listenerCount=xe;function xe(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}y.prototype.eventNames=function(){return this._eventsCount>0?V(this._events):[]};function Oe(e,t){for(var r=new Array(t),n=0;n{"use strict";var c={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}}};c.cipher.aes=function(e){this.s[0][0][0]||this.O();var t,r,n,o,i=this.s[0][4],s=this.s[1];t=e.length;var a=1;if(t!==4&&t!==6&&t!==8)throw new c.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^a<<24,a=a<<1^283*(a>>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]]};c.cipher.aes.prototype={encrypt:function(e){return Pe(this,e,0)},decrypt:function(e){return Pe(this,e,1)},s:[[[],[],[],[],[]],[[],[],[],[],[]]],O:function(){var e=this.s[0],t=this.s[1],r=e[4],n=t[4],o,i,s,a=[],f=[],u,l,h,p;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(h=s^s<<1^s<<2^s<<3^s<<4,h=h>>8^h&255^99,r[i]=h,n[h]=i,l=a[o=a[u=a[i]]],p=16843009*l^65537*o^257*u^16843008*i,l=257*a[h]^16843008*h,o=0;4>o;o++)e[o][i]=l=l<<24^l>>>8,t[o][h]=p=p<<24^p>>>8;for(o=0;5>o;o++)e[o]=e[o].slice(0),t[o]=t[o].slice(0)}};function Pe(e,t,r){if(t.length!==4)throw new c.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 a,f,u,l=n.length/4-2,h,p=4,d=[0,0,0,0];a=e.s[r],e=a[0];var m=a[1],b=a[2],I=a[3],T=a[4];for(h=0;h>>24]^m[i>>16&255]^b[s>>8&255]^I[t&255]^n[p],f=e[i>>>24]^m[s>>16&255]^b[t>>8&255]^I[o&255]^n[p+1],u=e[s>>>24]^m[t>>16&255]^b[o>>8&255]^I[i&255]^n[p+2],t=e[t>>>24]^m[o>>16&255]^b[i>>8&255]^I[s&255]^n[p+3],p+=4,o=a,i=f,s=u;for(h=0;4>h;h++)d[r?3&-h:h]=T[o>>>24]<<24^T[i>>16&255]<<16^T[s>>8&255]<<8^T[t&255]^n[p++],a=o,o=i,i=s,s=t,t=a;return d}c.bitArray={bitSlice:function(e,t,r){return e=c.bitArray.$(e.slice(t/32),32-(t&31)).slice(1),r===void 0?e:c.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(c.bitArray.bitLength(e)!==c.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=c.bitArray.getPartial(o),n.push(c.bitArray.partial(t+e&31,32>>24|r>>>8&65280|(r&65280)<<8|r<<24;return e}};c.codec.utf8String={fromBits:function(e){var t="",r=c.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>>s)>>>o),sl){if(!t)try{return c.codec.base32hex.toBits(e)}catch{}throw new c.exception.invalid("this isn't "+h+"!")}a>o?(a-=o,i.push(u^l>>>a),u=l<>>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=c.codec.base64.B,s=0,a;for(t&&(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(e){return c.codec.base64.fromBits(e,1,1)},toBits:function(e){return c.codec.base64.toBits(e,1)}};c.hash.sha256=function(e){this.b[0]||this.O(),e?(this.F=e.F.slice(0),this.A=e.A.slice(0),this.l=e.l):this.reset()};c.hash.sha256.hash=function(e){return new c.hash.sha256().update(e).finalize()};c.hash.sha256.prototype={blockSize:512,reset:function(){return this.F=this.Y.slice(0),this.A=[],this.l=0,this},update:function(e){typeof e=="string"&&(e=c.codec.utf8String.toBits(e));var t,r=this.A=c.bitArray.concat(this.A,e);if(t=this.l,e=this.l=t+c.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.Y[t]=e(Math.pow(r,.5))),this.b[t]=e(Math.pow(r,1/3)),t++)}}};function ie(e,t){var r,n,o,i=e.F,s=e.b,a=i[0],f=i[1],u=i[2],l=i[3],h=i[4],p=i[5],d=i[6],m=i[7];for(r=0;64>r;r++)16>r?n=t[r]:(n=t[r+1&15],o=t[r+14&15],n=t[r&15]=(n>>>7^n>>>18^n>>>3^n<<25^n<<14)+(o>>>17^o>>>19^o>>>10^o<<15^o<<13)+t[r&15]+t[r+9&15]|0),n=n+m+(h>>>6^h>>>11^h>>>25^h<<26^h<<21^h<<7)+(d^h&(p^d))+s[r],m=d,d=p,p=h,h=l+n|0,l=u,u=f,f=a,a=n+(f&u^l&(f^u))+(f>>>2^f>>>13^f>>>22^f<<30^f<<19^f<<10)|0;i[0]=i[0]+a|0,i[1]=i[1]+f|0,i[2]=i[2]+u|0,i[3]=i[3]+l|0,i[4]=i[4]+h|0,i[5]=i[5]+p|0,i[6]=i[6]+d|0,i[7]=i[7]+m|0}c.mode.ccm={name:"ccm",G:[],listenProgress:function(e){c.mode.ccm.G.push(e)},unListenProgress:function(e){e=c.mode.ccm.G.indexOf(e),-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)),t=c.mode.ccm.V(e,t,r,n,o,i),s=c.mode.ccm.C(e,s,r,t,o,i),a.concat(s.data,s.tag)},decrypt:function(e,t,r,n,o){o=o||64,n=n||[];var i=c.bitArray,s=i.bitLength(r)/8,u=i.bitLength(t),a=i.clamp(t,u-o),f=i.bitSlice(t,u-o),u=(u-o)/8;if(7>s)throw new c.exception.invalid("ccm: iv must be at least 7 bytes");for(t=2;4>t&&u>>>8*t;t++);if(t<15-s&&(t=15-s),r=i.clamp(r,8*(15-t)),a=c.mode.ccm.C(e,a,r,f,o,t),e=c.mode.ccm.V(e,a.data,r,n,o,t),!i.equal(a.tag,e))throw new c.exception.corrupt("ccm: tag doesn't match");return a.data},na:function(e,t,r,n,o,i){var s=[],a=c.bitArray,f=a.i;if(n=[a.partial(8,(t.length?64:0)|n-2<<2|i-1)],n=a.concat(n,r),n[3]|=o,n=e.encrypt(n),t.length)for(r=a.bitLength(t)/8,65279>=r?s=[a.partial(16,r)]:4294967295>=r&&(s=a.concat([a.partial(16,65534)],[r])),s=a.concat(s,t),t=0;to||16l&&(c.mode.ccm.fa(s/f),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:a.clamp(t,u)}}};c.mode.ocb2={name:"ocb2",encrypt:function(e,t,r,n,o,i){if(c.bitArray.bitLength(r)!==128)throw new c.exception.invalid("ocb iv must be 128 bits");var s,a=c.mode.ocb2.S,f=c.bitArray,u=f.i,l=[0,0,0,0];r=a(e.encrypt(r));var h,p=[];for(n=n||[],o=o||64,s=0;s+4o.bitLength(r)&&(a=i(a,n(a)),r=o.concat(r,[-2147483648,0,0,0])),s=i(s,r),e.encrypt(i(n(i(a,n(a))),s))},S:function(e){return[e[0]<<1^e[1]>>>31,e[1]<<1^e[2]>>>31,e[2]<<1^e[3]>>>31,e[3]<<1^135*(e[0]>>>31)]}};c.mode.gcm={name:"gcm",encrypt:function(e,t,r,n,o){var i=t.slice(0);return t=c.bitArray,n=n||[],e=c.mode.gcm.C(!0,e,i,n,r,o||128),t.concat(e.data,e.tag)},decrypt:function(e,t,r,n,o){var i=t.slice(0),s=c.bitArray,a=s.bitLength(i);if(o=o||128,n=n||[],o<=a?(t=s.bitSlice(i,a-o),i=s.bitSlice(i,0,a-o)):(t=i,i=[]),e=c.mode.gcm.C(!1,e,i,n,r,o),!s.equal(e.tag,t))throw new c.exception.corrupt("gcm: tag doesn't match");return e.data},ka:function(e,t){var r,n,o,i,s,a=c.bitArray.i;for(o=[0,0,0,0],i=t.slice(0),r=0;128>r;r++){for((n=(e[Math.floor(r/32)]&1<<31-r%32)!==0)&&(o=a(o,i)),s=(i[3]&1)!==0,n=3;0>>1|(i[n-1]&1)<<31;i[0]>>>=1,s&&(i[0]^=-520093696)}return o},j:function(e,t,r){var n,o=r.length;for(t=t.slice(0),n=0;no&&(e=t.hash(e)),n=0;nn||0>r)throw new c.exception.invalid("invalid params to pbkdf2");typeof e=="string"&&(e=c.codec.utf8String.toBits(e)),typeof t=="string"&&(t=c.codec.utf8String.toBits(t)),o=o||c.misc.hmac,e=new o(e);var i,s,a,f,u=[],l=c.bitArray;for(f=1;32*u.length<(n||1);f++){for(o=i=e.encrypt(l.concat(t,[f])),s=1;ss;s++)o.push(4294967296*Math.random()|0);for(s=0;s=1<this.o&&(this.o=i),this.P++,this.b=c.hash.sha256.hash(this.b.concat(o)),this.L=new c.cipher.aes(this.b),n=0;4>n&&(this.h[n]=this.h[n]+1|0,!this.h[n]);n++);}for(n=0;n>>1;this.c[s].update([n,this.N++,2,t,i,e.length].concat(e))}break;case"string":t===void 0&&(t=e.length),this.c[s].update([n,this.N++,3,t,i,e.length]),this.c[s].update(e);break;default:f=1}if(f)throw new c.exception.bug("random: addEntropy only supports number, array of numbers or string");this.m[s]+=t,this.f+=t,a===this.u&&(this.isReady()!==this.u&&Me("seeded",Math.max(this.o,this.f)),Me("progress",this.getProgress()))},isReady:function(e){return e=this.T[e!==void 0?e:this.M],this.o&&this.o>=e?this.m[0]>this.ba&&new Date().valueOf()>this.Z?this.J|this.I:this.I:this.f>=e?this.J|this.u:this.u},getProgress:function(e){return e=this.T[e||this.M],this.o>=e||this.f>e?1:this.f/e},startCollectors:function(){if(!this.D){if(this.a={loadTimeCollector:H(this,this.ma),mouseCollector:H(this,this.oa),keyboardCollector:H(this,this.la),accelerometerCollector:H(this,this.ea),touchCollector:H(this,this.qa)},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(e,t){this.K[e][this.ga++]=t},removeEventListener:function(e,t){var r,n,o=this.K[e],i=[];for(n in o)o.hasOwnProperty(n)&&o[n]===t&&i.push(n);for(r=0;rt&&(e.h[t]=e.h[t]+1|0,!e.h[t]);t++);return e.L.encrypt(e.h)}function H(e,t){return function(){t.apply(e,arguments)}}c.random=new c.prng(6);e:try{if(Z=typeof J<"u"&&J.exports){try{Q=Ye("crypto")}catch{Q=null}Z=Y=Q}if(Z&&Y.randomBytes)$=Y.randomBytes(128),$=new Uint32Array(new Uint8Array($).buffer),c.random.addEntropy($,1024,"crypto['randomBytes']");else if(typeof window<"u"&&typeof Uint32Array<"u"){if(q=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(q);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(q);else break e;c.random.addEntropy(q,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 $,Y,q,Z,Q;c.json={defaults:{v:1,iter:1e4,ks:128,ts:64,mode:"ccm",adata:"",cipher:"aes"},ja:function(e,t,r,n){r=r||{},n=n||{};var o=c.json,i=o.g({iv:c.random.randomWords(4,0)},o.defaults),s;if(o.g(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 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 U(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 a(l){try{u(n.next(l))}catch(h){s(h)}}function f(l){try{u(n.throw(l))}catch(h){s(h)}}function u(l){l.done?i(l.value):o(l.value).then(a,f)}u((n=n.apply(e,t||[])).next())})}function he(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 O(e){return this instanceof O?(this.v=e,this):new O(e)}function le(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),a("next"),a("throw"),a("return",s),o[Symbol.asyncIterator]=function(){return this},o;function s(d){return function(m){return Promise.resolve(m).then(d,h)}}function a(d,m){n[d]&&(o[d]=function(b){return new Promise(function(I,T){i.push([d,b,I,T])>1||f(d,b)})},m&&(o[d]=m(o[d])))}function f(d,m){try{u(n[d](m))}catch(b){p(i[0][3],b)}}function u(d){d.value instanceof O?Promise.resolve(d.value.v).then(l,h):p(i[0][2],d)}function l(d){f("next",d)}function h(d){f("throw",d)}function p(d,m){d(m),i.shift(),i.length&&f(i[0][0],i[0][1])}}function et(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:O(e[o](s)),done:!1}:i?i(s):s}:i}}function tt(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 he=="function"?he(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(a,f){s=e[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 E=class e{constructor(t){this._promise=t}static fromSafePromise(t){let r=t.then(n=>new L(n));return new e(r)}static fromPromise(t,r){let n=t.then(o=>new L(o)).catch(o=>new x(r(o)));return new e(n)}static fromThrowable(t,r){return(...n)=>new e(U(this,void 0,void 0,function*(){try{return new L(yield t(...n))}catch(o){return new x(r?r(o):o)}}))}static combine(t){return rt(t)}static combineWithAllErrors(t){return nt(t)}map(t){return new e(this._promise.then(r=>U(this,void 0,void 0,function*(){return r.isErr()?new x(r.error):new L(yield t(r.value))})))}andThrough(t){return new e(this._promise.then(r=>U(this,void 0,void 0,function*(){if(r.isErr())return new x(r.error);let n=yield t(r.value);return n.isErr()?new x(n.error):new L(r.value)})))}andTee(t){return new e(this._promise.then(r=>U(this,void 0,void 0,function*(){if(r.isErr())return new x(r.error);try{yield t(r.value)}catch{}return new L(r.value)})))}mapErr(t){return new e(this._promise.then(r=>U(this,void 0,void 0,function*(){return r.isOk()?new L(r.value):new x(yield t(r.error))})))}andThen(t){return new e(this._promise.then(r=>{if(r.isErr())return new x(r.error);let n=t(r.value);return n instanceof e?n._promise:n}))}orElse(t){return new e(this._promise.then(r=>U(this,void 0,void 0,function*(){return r.isErr()?t(r.error):new L(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 le(this,arguments,function*(){return yield O(yield O(yield*et(tt(yield O(this._promise.then(r=>r.safeUnwrap()))))))})}then(t,r){return this._promise.then(t,r)}[Symbol.asyncIterator](){return le(this,arguments,function*(){let r=yield O(this._promise);return r.isErr()&&(yield yield O(w(r.error))),yield O(r.value)})}},D=e=>new E(Promise.resolve(new L(e))),w=e=>new E(Promise.resolve(new x(e))),Mt=E.fromPromise,It=E.fromSafePromise,Tt=E.fromThrowable,pe=e=>{let t=P([]);for(let r of e)if(r.isErr()){t=_(r.error);break}else t.map(n=>n.push(r.value));return t},rt=e=>E.fromSafePromise(Promise.all(e)).andThen(pe),me=e=>{let t=P([]);for(let r of e)r.isErr()&&t.isErr()?t.error.push(r.error):r.isErr()&&t.isOk()?t=_([r.error]):r.isOk()&&t.isOk()&&t.value.push(r.value);return t},nt=e=>E.fromSafePromise(Promise.all(e)).andThen(me),re;(function(e){function t(o,i){return(...s)=>{try{let a=o(...s);return P(a)}catch(a){return _(i?i(a):a)}}}e.fromThrowable=t;function r(o){return pe(o)}e.combine=r;function n(o){return me(o)}e.combineWithAllErrors=n})(re||(re={}));var P=e=>new L(e);function _(e){return new x(e)}var L=class{constructor(t){this.value=t}isOk(){return!0}isErr(){return!this.isOk()}map(t){return P(t(this.value))}mapErr(t){return P(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 P(this.value)}orElse(t){return P(this.value)}asyncAndThen(t){return t(this.value)}asyncAndThrough(t){return t(this.value).map(()=>this.value)}asyncMap(t){return E.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 de("Called `_unsafeUnwrapErr` on an Ok",this,t)}*[Symbol.iterator](){return this.value}},x=class{constructor(t){this.error=t}isOk(){return!1}isErr(){return!this.isOk()}map(t){return _(this.error)}mapErr(t){return _(t(this.error))}andThrough(t){return _(this.error)}andTee(t){return _(this.error)}andThen(t){return _(this.error)}orElse(t){return t(this.error)}asyncAndThen(t){return w(this.error)}asyncAndThrough(t){return w(this.error)}asyncMap(t){return w(this.error)}unwrapOr(t){return t}match(t,r){return r(this.error)}safeUnwrap(){let t=this.error;return function*(){throw yield _(t),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(t){throw de("Called `_unsafeUnwrap` on an Err",this,t)}_unsafeUnwrapErr(t){return this.error}*[Symbol.iterator](){let t=this;return yield t,t}},Ut=re.fromThrowable;var C=class extends Error{constructor(r,n={}){let{cause:o,context:i}=n;super(r,{cause:o});k(this,"context");this.name=this.constructor.name,this.context=i}};var S=class extends C{};var X=class extends S{constructor(){super(...arguments);k(this,"message","An error occured while trying to connect to WebSocket")}};var M=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 ot=()=>typeof Deno<"u";var B=e=>ot()?new URL(`./worker/${e}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${e==="main"?`worker/${e}`:e}.js`));var _e=ue(Se());var g=new _e.default,v,be=!1;self.onmessage=e=>{lt(e),be||(be=!0,g.once("OPERATION_FAILED",()=>{v&&v.terminate()}))};var j=(e,t)=>(Object.assign(e,t),typeof WorkerGlobalScope<"u"&&self.postMessage({event:"FILE_UPDATED",lufiFile:e}),e);var lt=(e,t)=>{let{action:r}=e.data;if(r===5||r===8)v.postMessage(e.data);else{switch(r){case 2:v=new Worker(B("cancel"),{type:"module"}),v.postMessage(e.data);break;case 3:v=new Worker(B("download"),{type:"module"}),v.postMessage(e.data);break;case 4:v=new Worker(B("infos"),{type:"module"}),v.postMessage(e.data);break;case 7:v=v||new Worker(B("remove"),{type:"module"}),v.postMessage(e.data);break;case 9:v=v||new Worker(B("upload"),{type:"module"}),v.postMessage(e.data);break;default:console.error("Action not found")}v.onmessage=n=>{t&&t(n),self.postMessage(n.data)},v.onerror=n=>{console.error(`Error: ${n.message}`)}}},Ce=()=>{g.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),g.once("OPERATION_FAILED",e=>{self.postMessage({event:"OPERATION_FAILED",error:e})})};var W=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,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 dt=new W("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");function z(e){return dt.Decode(e)}var pt=new W("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",!0);function oe(e){return pt.Decode(e)}var Be=ue(Te());var R=class extends C{};var F=class extends R{constructor(){super(...arguments);k(this,"message","Unable to decrypt the provided data")}};var Ne=(e,t)=>{try{let r=typeof t=="string"?t:t.data;return D(z(Be.default.decrypt(e,r)))}catch(r){return w(new F(void 0,{cause:M(r)}))}};var je=(e,t)=>gt(e).andThen(r=>E.fromPromise(crypto.subtle.decrypt({name:"AES-GCM",iv:t.iv},r,z(t.data)),n=>new F(void 0,{cause:M(n)})));var gt=e=>E.fromPromise(crypto.subtle.importKey("raw",oe(e),{name:"AES-GCM"},!1,["encrypt","decrypt"]),t=>new R("Unable to import cryptography key",{cause:M(t)}));var We=(e,t)=>t.algo===void 0||t.algo===0?Ne(e,t):je(e,t);var A={},Je=5,Et=e=>(g.emit("UPLOAD_CANCELLED",e.success),D(void 0)),At=(e,t)=>{let r=e.split("XXMOJOXX"),n=r.shift();if(n!==void 0){let o=JSON.parse(n);if(_t(o)){let i=r.shift();if(i){let s=JSON.parse(i);return s.iv&&(s.iv=new Uint8Array(Object.values(s.iv))),We(t.keys.client,s).andThen(a=>{let f=typeof a=="string"?new TextEncoder().encode(a).buffer:a;return o.part===0?(j(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")):j(t,{chunksReady:t.chunksReady+1}),g.emit("CHUNK_DOWNLOADED",f,o.part),++o.part===o.total?Dt(t).andThen(()=>(g.emit("DOWNLOAD_COMPLETE"),g.emit("SOCKET_OPERATION_TERMINATED"),D(void 0))):D(void 0)})}else{let s=new S("Can't retrieve metadata from data received by the server");return g.emit("OPERATION_FAILED",s),w(s)}}else{let i=new S(o.msg);return g.emit("OPERATION_FAILED",i),w(i)}}else{let o=new S("Can't retrieve metadata from data received by the server");return g.emit("OPERATION_FAILED",o),w(o)}},Lt=(e,t)=>{if(e.success)return e.j===0&&(j(t,{keys:{client:t.keys.client,server:e.short},actionToken:e.token,queueIndex:e.i}),g.emit("UPLOAD_STARTED")),j(t,{chunksReady:t.chunksReady+1,createdAt:e.created_at}),g.emit("CHUNK_UPLOADED"),t.chunksReady===t.totalChunks&&(j(t,{uploadStatus:1}),g.emit("UPLOAD_COMPLETE"),g.emit("SOCKET_OPERATION_TERMINATED")),D(void 0);{let r=new S(e.msg);return g.emit("OPERATION_FAILED",r),w(r)}},xt=(e,t)=>{let r=kt(e.data),n;if(r)if(!r.action&&r.msg){let o=new S(r.msg);return g.emit("OPERATION_FAILED",o),w(o)}else"delay"in r?n=Lt(r,t):n=Et(r);else n=At(e.data,t);return n},Ot=e=>A!==void 0&&A[e]!==void 0&&A[e].readyState===WebSocket.CONNECTING,ce=e=>A!==void 0&&A[e]!==void 0&&A[e].readyState===WebSocket.OPEN;var Fe=(e,t)=>{let r;return e.password?r={part:t,file_pwd:e.password}:r={part:t},ae(ee(e),e,JSON.stringify(r))},Dt=e=>{let t;return e.password?t={ended:!0,file_pwd:e.password}:t={ended:!0},ae(ee(e),e,JSON.stringify(t))};var ae=(e,t,r)=>ce(e)?(A[e].onmessage=n=>xt(n,t),A[e].send(r),D(void 0)):Xe(e).andThen(()=>ae(e,t,r)),Xe=(e,t=0)=>(!ce(e)&&!Ot(e)&&(A[e]=new WebSocket(e),g.once("SOCKET_OPERATION_TERMINATED",()=>{A[e].close()}),g.once("OPERATION_FAILED",()=>{g.emit("SOCKET_OPERATION_TERMINATED")}),A[e].onopen=()=>{g.emit("SOCKET_OPENED")},A[e].onclose=()=>{},A[e].onerror=()=>++t<=Je?(console.error(`An error happened while trying to connect to WebSocket ${e}. Trying again. ${t} / ${Je}`),Xe(e,t)):(g.emit("SOCKET_ONERROR"),w(new X(`Unable to connect to WebSocket ${e}.`)))),St(e).andThen(()=>D(e)).orElse(r=>w(r))),St=e=>E.fromPromise(new Promise((t,r)=>{ce(e)?t(void 0):(g.once("SOCKET_OPENED",()=>{t(void 0)}),g.on("SOCKET_ONERROR",()=>{r(new X)}))}),t=>M(t));var bt=(e,t)=>{let r=new URL(e);return r.protocol=r.protocol==="http:"?"ws:":"wss:",r.pathname+=t,new URL(r.origin+r.pathname)},ee=e=>bt(new URL(e.serverUrl),"download"+`/${e.keys.server}`).toString();var kt=e=>{try{let t=JSON.parse(e);if(t&&typeof t=="object")return t}catch{}return!1},_t=e=>typeof e=="object"&&e!==null&&!("msg"in e);var ze=!1;self.onmessage=e=>{ze||(Ce(),ze=!0),g.on("DOWNLOAD_STARTED",()=>{A[ee(e.data.args.lufiFile)].close(),self.postMessage({event:"INFOS_RETRIEVED"})}),Rt(e.data).mapErr(t=>{self.postMessage({event:"OPERATION_FAILED",error:t})})};var Rt=e=>Fe(e.args.lufiFile,0); diff --git a/themes/default/public/js/worker/main.js b/themes/default/public/js/worker/main.js index 0245dfd..7775a7d 100644 --- a/themes/default/public/js/worker/main.js +++ b/themes/default/public/js/worker/main.js @@ -1 +1 @@ -var V=Object.create;var C=Object.defineProperty;var ee=Object.getOwnPropertyDescriptor;var re=Object.getOwnPropertyNames;var te=Object.getPrototypeOf,ne=Object.prototype.hasOwnProperty;var oe=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var ie=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of re(e))!ne.call(r,o)&&o!==t&&C(r,o,{get:()=>e[o],enumerable:!(n=ee(e,o))||n.enumerable});return r};var se=(r,e,t)=>(t=r!=null?V(te(r)):{},ie(e||!r||!r.__esModule?C(t,"default",{value:r,enumerable:!0}):t,r));var $=oe((De,M)=>{"use strict";var g=typeof Reflect=="object"?Reflect:null,U=g&&typeof g.apply=="function"?g.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)},O;g&&typeof g.ownKeys=="function"?O=g.ownKeys:Object.getOwnPropertySymbols?O=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:O=function(e){return Object.getOwnPropertyNames(e)};function ue(r){console&&console.warn&&console.warn(r)}var R=Number.isNaN||function(e){return e!==e};function a(){a.init.call(this)}M.exports=a;M.exports.once=le;a.EventEmitter=a;a.prototype._events=void 0;a.prototype._eventsCount=0;a.prototype._maxListeners=void 0;var F=10;function A(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||R(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||R(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 T(r){return r._maxListeners===void 0?a.defaultMaxListeners:r._maxListeners}a.prototype.getMaxListeners=function(){return T(this)};a.prototype.emit=function(e){for(var t=[],n=1;n0&&(i=t[0]),i instanceof Error)throw i;var f=new Error("Unhandled error."+(i?" ("+i.message+")":""));throw f.context=i,f}var h=s[e];if(h===void 0)return!1;if(typeof h=="function")U(h,this,t);else for(var m=h.length,u=H(h,m),n=0;n0&&i.length>o&&!i.warned){i.warned=!0;var f=new Error("Possible EventEmitter memory leak detected. "+i.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");f.name="MaxListenersExceededWarning",f.emitter=r,f.type=e,f.count=i.length,ue(f)}return r}a.prototype.addListener=function(e,t){return j(this,e,t,!1)};a.prototype.on=a.prototype.addListener;a.prototype.prependListener=function(e,t){return j(this,e,t,!0)};function ae(){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 N(r,e,t){var n={fired:!1,wrapFn:void 0,target:r,type:e,listener:t},o=ae.bind(n);return o.listener=t,n.wrapFn=o,o}a.prototype.once=function(e,t){return A(t),this.on(e,N(this,e,t)),this};a.prototype.prependOnceListener=function(e,t){return A(t),this.prependListener(e,N(this,e,t)),this};a.prototype.removeListener=function(e,t){var n,o,s,i,f;if(A(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){f=n[i].listener,s=i;break}if(s<0)return this;s===0?n.shift():fe(n,s),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 s=Object.keys(n),i;for(o=0;o=0;o--)this.removeListener(e,t[o]);return this};function W(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?ce(o):H(o,o.length)}a.prototype.listeners=function(e){return W(this,e,!0)};a.prototype.rawListeners=function(e){return W(this,e,!1)};a.listenerCount=function(r,e){return typeof r.listenerCount=="function"?r.listenerCount(e):J.call(r,e)};a.prototype.listenerCount=J;function J(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?O(this._events):[]};function H(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 pe={withStackTrace:!1},q=(r,e,t=pe)=>{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 f(u){try{m(n.next(u))}catch(L){i(L)}}function h(u){try{m(n.throw(u))}catch(L){i(L)}}function m(u){u.done?s(u.value):o(u.value).then(f,h)}m((n=n.apply(r,[])).next())})}function G(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 y(r){return this instanceof y?(this.v=r,this):new y(r)}function de(r,e,t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=t.apply(r,e||[]),o,s=[];return o={},i("next"),i("throw"),i("return"),o[Symbol.asyncIterator]=function(){return this},o;function i(l){n[l]&&(o[l]=function(_){return new Promise(function(x,K){s.push([l,_,x,K])>1||f(l,_)})})}function f(l,_){try{h(n[l](_))}catch(x){L(s[0][3],x)}}function h(l){l.value instanceof y?Promise.resolve(l.value.v).then(m,u):L(s[0][2],l)}function m(l){f("next",l)}function u(l){f("throw",l)}function L(l,_){l(_),s.shift(),s.length&&f(s[0][0],s[0][1])}}function me(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:y(r[o](i)),done:o==="return"}:s?s(i):i}:s}}function ve(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 G=="function"?G(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(f,h){i=r[s](i),o(f,h,i.done,i.value)})}}function o(s,i,f,h){Promise.resolve(h).then(function(m){s({value:m,done:f})},i)}}var v=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(b(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 Ee(e)}map(e){return new r(this._promise.then(t=>b(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=>b(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=>b(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=>b(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=>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 de(this,arguments,function*(){return yield y(yield y(yield*me(ve(yield y(this._promise.then(t=>t.safeUnwrap()))))))})}then(e,t){return this._promise.then(e,t)}};var P=r=>new v(Promise.resolve(new p(r))),xe=v.fromPromise,Me=v.fromSafePromise,ke=v.fromThrowable,z=r=>{let e=E([]);for(let t of r)if(t.isErr()){e=w(t.error);break}else e.map(n=>n.push(t.value));return e},we=r=>v.fromSafePromise(Promise.all(r)).andThen(z),Q=r=>{let e=E([]);for(let t of r)t.isErr()&&e.isErr()?e.error.push(t.error):t.isErr()&&e.isOk()?e=w([t.error]):t.isOk()&&e.isOk()&&e.value.push(t.value);return e},Ee=r=>v.fromSafePromise(Promise.all(r)).andThen(Q),I;(function(r){function e(o,s){return(...i)=>{try{let f=o(...i);return E(f)}catch(f){return w(s?s(f):f)}}}r.fromThrowable=e;function t(o){return z(o)}r.combine=t;function n(o){return Q(o)}r.combineWithAllErrors=n})(I||(I={}));var E=r=>new d(r);function w(r){return new p(r)}var d=class{constructor(e){this.value=e}isOk(){return!0}isErr(){return!this.isOk()}map(e){return E(e(this.value))}mapErr(e){return E(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 E(this.value)}orElse(e){return E(this.value)}asyncAndThen(e){return e(this.value)}asyncAndThrough(e){return e(this.value).map(()=>this.value)}asyncMap(e){return v.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)}},p=class{constructor(e){this.error=e}isOk(){return!1}isErr(){return!this.isOk()}map(e){return w(this.error)}mapErr(e){return w(e(this.error))}andThrough(e){return w(this.error)}andTee(e){return w(this.error)}andThen(e){return w(this.error)}orElse(e){return e(this.error)}asyncAndThen(e){return P(this.error)}asyncAndThrough(e){return P(this.error)}asyncMap(e){return P(this.error)}unwrapOr(e){return e}match(e,t){return t(this.error)}safeUnwrap(){let e=this.error;return function*(){throw yield w(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}},Ie=I.fromThrowable;var Le=()=>typeof Deno<"u";var D=r=>Le()?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 Y.default,c,X=!1;self.onmessage=r=>{ge(r),X||(X=!0,S.once("OPERATION_FAILED",()=>{c&&c.terminate()}))};var _e=(r,e)=>(Object.assign(r,e),typeof WorkerGlobalScope<"u"&&self.postMessage({event:"FILE_UPDATED",lufiFile:r}),r),Ve=(r,e)=>{_e(r,{uploadStatus:2}),self.postMessage({event:"OPERATION_FAILED",error:e})},ge=(r,e)=>{let{action:t}=r.data;if(t===5||t===8)c.postMessage(r.data);else{switch(t){case 2:c=new Worker(D("cancel"),{type:"module"}),c.postMessage(r.data);break;case 3:c=new Worker(D("download"),{type:"module"}),c.postMessage(r.data);break;case 4:c=new Worker(D("infos"),{type:"module"}),c.postMessage(r.data);break;case 7:c=c||new Worker(D("remove"),{type:"module"}),c.postMessage(r.data);break;case 9:c=c||new Worker(D("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}`)}}},er=()=>{S.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),S.once("OPERATION_FAILED",r=>{self.postMessage({event:"OPERATION_FAILED",error:r})})},rr=r=>typeof r=="object"&&r!==null&&"action"in r&&Object.values(k).includes(r.action);export{S as events,er as init,rr as isWorkerActionMessage,Ve as sendFileError,_e as updateFile}; +var te=Object.create;var U=Object.defineProperty;var ne=Object.getOwnPropertyDescriptor;var oe=Object.getOwnPropertyNames;var ie=Object.getPrototypeOf,se=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))!se.call(r,o)&&o!==t&&U(r,o,{get:()=>e[o],enumerable:!(n=ne(e,o))||n.enumerable});return r};var fe=(r,e,t)=>(t=r!=null?te(ie(r)):{},ae(e||!r||!r.__esModule?U(t,"default",{value:r,enumerable:!0}):t,r));var G=ue((Ae,M)=>{"use strict";var g=typeof Reflect=="object"?Reflect:null,R=g&&typeof g.apply=="function"?g.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)},P;g&&typeof g.ownKeys=="function"?P=g.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&&(i=t[0]),i instanceof Error)throw i;var f=new Error("Unhandled error."+(i?" ("+i.message+")":""));throw f.context=i,f}var h=s[e];if(h===void 0)return!1;if(typeof h=="function")R(h,this,t);else for(var m=h.length,u=B(h,m),n=0;n0&&i.length>o&&!i.warned){i.warned=!0;var f=new Error("Possible EventEmitter memory leak detected. "+i.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");f.name="MaxListenersExceededWarning",f.emitter=r,f.type=e,f.count=i.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,s,i,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(s=-1,i=n.length-1;i>=0;i--)if(n[i]===t||n[i].listener===t){f=n[i].listener,s=i;break}if(s<0)return this;s===0?n.shift():he(n,s),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 s=Object.keys(n),i;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 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 f(u){try{m(n.next(u))}catch(_){i(_)}}function h(u){try{m(n.throw(u))}catch(_){i(_)}}function m(u){u.done?s(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,s=[];return o=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),f("next"),f("throw"),f("return",i),o[Symbol.asyncIterator]=function(){return this},o;function i(c){return function(E){return Promise.resolve(E).then(c,_)}}function f(c,E){n[c]&&(o[c]=function(A){return new Promise(function(ee,re){s.push([c,A,ee,re])>1||h(c,A)})},E&&(o[c]=E(o[c])))}function h(c,E){try{m(n[c](E))}catch(A){C(s[0][3],A)}}function m(c){c.value instanceof v?Promise.resolve(c.value.v).then(u,_):C(s[0][2],c)}function u(c){h("next",c)}function _(c){h("throw",c)}function C(c,E){c(E),s.shift(),s.length&&h(s[0][0],s[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,s){e[o]=r[o]?function(i){return(t=!t)?{value:v(r[o](i)),done:!1}:s?s(i):i}:s}}function we(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(s){t[s]=r[s]&&function(i){return new Promise(function(f,h){i=r[s](i),o(f,h,i.done,i.value)})}}function o(s,i,f,h){Promise.resolve(h).then(function(m){s({value:m,done:f})},i)}}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(b(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 Ee(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 p(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 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=>b(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=>b(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=>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 z(this,arguments,function*(){return yield v(yield v(yield*ye(we(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,Se=y.fromSafePromise,Ie=y.fromThrowable,Z=r=>{let e=L([]);for(let t of r)if(t.isErr()){e=w(t.error);break}else e.map(n=>n.push(t.value));return e},Ee=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=w([t.error]):t.isOk()&&e.isOk()&&e.value.push(t.value);return e},Le=r=>y.fromSafePromise(Promise.all(r)).andThen(X),S;(function(r){function e(o,s){return(...i)=>{try{let f=o(...i);return L(f)}catch(f){return w(s?s(f):f)}}}r.fromThrowable=e;function t(o){return Z(o)}r.combine=t;function n(o){return X(o)}r.combineWithAllErrors=n})(S||(S={}));var L=r=>new d(r);function w(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 w(this.error)}mapErr(e){return w(e(this.error))}andThrough(e){return w(this.error)}andTee(e){return w(this.error)}andThen(e){return w(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 w(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=S.fromThrowable;var ge=()=>typeof Deno<"u";var D=r=>ge()?new URL(`./worker/${r}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${r==="main"?`worker/${r}`:r}.js`));var I=new V.default,l,K=!1;self.onmessage=r=>{De(r),K||(K=!0,I.once("OPERATION_FAILED",()=>{l&&l.terminate()}))};var be=(r,e)=>(Object.assign(r,e),typeof WorkerGlobalScope<"u"&&self.postMessage({event:"FILE_UPDATED",lufiFile:r}),r),rr=(r,e)=>{be(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=()=>{I.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),I.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{I as events,tr as init,nr as isWorkerActionMessage,rr as sendFileError,be as updateFile}; diff --git a/themes/default/public/js/worker/remove.js b/themes/default/public/js/worker/remove.js index 9005618..0a42668 100644 --- a/themes/default/public/js/worker/remove.js +++ b/themes/default/public/js/worker/remove.js @@ -1 +1 @@ -var re=Object.create;var S=Object.defineProperty;var te=Object.getOwnPropertyDescriptor;var ne=Object.getOwnPropertyNames;var oe=Object.getPrototypeOf,se=Object.prototype.hasOwnProperty;var ie=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var ue=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ne(e))!se.call(r,o)&&o!==t&&S(r,o,{get:()=>e[o],enumerable:!(n=te(e,o))||n.enumerable});return r};var ae=(r,e,t)=>(t=r!=null?re(oe(r)):{},ue(e||!r||!r.__esModule?S(t,"default",{value:r,enumerable:!0}):t,r));var q=ie((Qe,M)=>{"use strict";var D=typeof Reflect=="object"?Reflect:null,N=D&&typeof D.apply=="function"?D.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)},A;D&&typeof D.ownKeys=="function"?A=D.ownKeys:Object.getOwnPropertySymbols?A=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:A=function(e){return Object.getOwnPropertyNames(e)};function Ee(r){console&&console.warn&&console.warn(r)}var J=Number.isNaN||function(e){return e!==e};function u(){u.init.call(this)}M.exports=u;M.exports.once=ge;u.EventEmitter=u;u.prototype._events=void 0;u.prototype._eventsCount=0;u.prototype._maxListeners=void 0;var W=10;function P(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 W},set:function(r){if(typeof r!="number"||r<0||J(r))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+r+".");W=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||J(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 H(r){return r._maxListeners===void 0?u.defaultMaxListeners:r._maxListeners}u.prototype.getMaxListeners=function(){return H(this)};u.prototype.emit=function(e){for(var t=[],n=1;n0&&(s=t[0]),s instanceof Error)throw s;var a=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw a.context=s,a}var l=i[e];if(l===void 0)return!1;if(typeof l=="function")N(l,this,t);else for(var v=l.length,m=Q(l,v),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=r,a.type=e,a.count=s.length,Ee(a)}return r}u.prototype.addListener=function(e,t){return B(this,e,t,!1)};u.prototype.on=u.prototype.addListener;u.prototype.prependListener=function(e,t){return B(this,e,t,!0)};function we(){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 $(r,e,t){var n={fired:!1,wrapFn:void 0,target:r,type:e,listener:t},o=we.bind(n);return o.listener=t,n.wrapFn=o,o}u.prototype.once=function(e,t){return P(t),this.on(e,$(this,e,t)),this};u.prototype.prependOnceListener=function(e,t){return P(t),this.prependListener(e,$(this,e,t)),this};u.prototype.removeListener=function(e,t){var n,o,i,s,a;if(P(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){a=n[s].listener,i=s;break}if(i<0)return this;i===0?n.shift():ye(n,i),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 i=Object.keys(n),s;for(o=0;o=0;o--)this.removeListener(e,t[o]);return this};function G(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?Le(o):Q(o,o.length)}u.prototype.listeners=function(e){return G(this,e,!0)};u.prototype.rawListeners=function(e){return G(this,e,!1)};u.listenerCount=function(r,e){return typeof r.listenerCount=="function"?r.listenerCount(e):z.call(r,e)};u.prototype.listenerCount=z;function z(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?A(this._events):[]};function Q(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 _(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 a(m){try{v(n.next(m))}catch(L){s(L)}}function l(m){try{v(n.throw(m))}catch(L){s(L)}}function v(m){m.done?i(m.value):o(m.value).then(a,l)}v((n=n.apply(r,[])).next())})}function C(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 y(r){return this instanceof y?(this.v=r,this):new y(r)}function ce(r,e,t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=t.apply(r,e||[]),o,i=[];return o={},s("next"),s("throw"),s("return"),o[Symbol.asyncIterator]=function(){return this},o;function s(c){n[c]&&(o[c]=function(g){return new Promise(function(k,ee){i.push([c,g,k,ee])>1||a(c,g)})})}function a(c,g){try{l(n[c](g))}catch(k){L(i[0][3],k)}}function l(c){c.value instanceof y?Promise.resolve(c.value.v).then(v,m):L(i[0][2],c)}function v(c){a("next",c)}function m(c){a("throw",c)}function L(c,g){c(g),i.shift(),i.length&&a(i[0][0],i[0][1])}}function le(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:y(r[o](s)),done:o==="return"}:i?i(s):s}:i}}function he(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 C=="function"?C(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(a,l){s=r[i](s),o(a,l,s.done,s.value)})}}function o(i,s,a,l){Promise.resolve(l).then(function(v){i({value:v,done:a})},s)}}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(_(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 pe(e)}static combineWithAllErrors(e){return me(e)}map(e){return new r(this._promise.then(t=>_(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=>_(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=>_(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=>_(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=>_(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 ce(this,arguments,function*(){return yield y(yield y(yield*le(he(yield y(this._promise.then(t=>t.safeUnwrap()))))))})}then(e,t){return this._promise.then(e,t)}};var O=r=>new p(Promise.resolve(new h(r))),ke=p.fromPromise,xe=p.fromSafePromise,Me=p.fromThrowable,R=r=>{let e=w([]);for(let t of r)if(t.isErr()){e=E(t.error);break}else e.map(n=>n.push(t.value));return e},pe=r=>p.fromSafePromise(Promise.all(r)).andThen(R),U=r=>{let e=w([]);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},me=r=>p.fromSafePromise(Promise.all(r)).andThen(U),x;(function(r){function e(o,i){return(...s)=>{try{let a=o(...s);return w(a)}catch(a){return E(i?i(a):a)}}}r.fromThrowable=e;function t(o){return R(o)}r.combine=t;function n(o){return U(o)}r.combineWithAllErrors=n})(x||(x={}));var w=r=>new d(r);function E(r){return new h(r)}var d=class{constructor(e){this.value=e}isOk(){return!0}isErr(){return!this.isOk()}map(e){return w(e(this.value))}mapErr(e){return w(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 w(this.value)}orElse(e){return w(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 F("Called `_unsafeUnwrapErr` on an Ok",this,e)}},h=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 F("Called `_unsafeUnwrap` on an Err",this,e)}_unsafeUnwrapErr(e){return this.error}},Ie=x.fromThrowable;var j=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 ve=()=>typeof Deno<"u";var b=r=>ve()?new URL(`./worker/${r}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${r==="main"?`worker/${r}`:r}.js`));var Y=ae(q());var I=new Y.default,f,X=!1;self.onmessage=r=>{De(r),X||(X=!0,I.once("OPERATION_FAILED",()=>{f&&f.terminate()}))};var De=(r,e)=>{let{action:t}=r.data;if(t===5||t===8)f.postMessage(r.data);else{switch(t){case 2:f=new Worker(b("cancel"),{type:"module"}),f.postMessage(r.data);break;case 3:f=new Worker(b("download"),{type:"module"}),f.postMessage(r.data);break;case 4:f=new Worker(b("infos"),{type:"module"}),f.postMessage(r.data);break;case 7:f=f||new Worker(b("remove"),{type:"module"}),f.postMessage(r.data);break;case 9:f=f||new Worker(b("upload"),{type:"module"}),f.postMessage(r.data);break;default:console.error("Action not found")}f.onmessage=n=>{e&&e(n),self.postMessage(n.data)},f.onerror=n=>{console.error(`Error: ${n.message}`)}}},K=()=>{I.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),I.once("OPERATION_FAILED",r=>{self.postMessage({event:"OPERATION_FAILED",error:r})})};var V=!1;self.onmessage=r=>{V||(K(),V=!0),Oe(r.data).map(()=>{self.postMessage({event:"FILE_REMOVED"})}).mapErr(e=>{self.postMessage({event:"OPERATION_FAILED",error:e})})};var Oe=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(o.statusText))}),e=>j(e)); +var oe=Object.create;var C=Object.defineProperty;var se=Object.getOwnPropertyDescriptor;var ie=Object.getOwnPropertyNames;var ue=Object.getPrototypeOf,ae=Object.prototype.hasOwnProperty;var fe=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var ce=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ie(e))!ae.call(r,o)&&o!==t&&C(r,o,{get:()=>e[o],enumerable:!(n=se(e,o))||n.enumerable});return r};var le=(r,e,t)=>(t=r!=null?oe(ue(r)):{},ce(e||!r||!r.__esModule?C(t,"default",{value:r,enumerable:!0}):t,r));var Y=fe((qe,M)=>{"use strict";var D=typeof Reflect=="object"?Reflect:null,J=D&&typeof D.apply=="function"?D.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)},P;D&&typeof D.ownKeys=="function"?P=D.ownKeys:Object.getOwnPropertySymbols?P=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:P=function(e){return Object.getOwnPropertyNames(e)};function we(r){console&&console.warn&&console.warn(r)}var B=Number.isNaN||function(e){return e!==e};function u(){u.init.call(this)}M.exports=u;M.exports.once=be;u.EventEmitter=u;u.prototype._events=void 0;u.prototype._eventsCount=0;u.prototype._maxListeners=void 0;var H=10;function k(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 H},set:function(r){if(typeof r!="number"||r<0||B(r))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+r+".");H=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||B(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 $(r){return r._maxListeners===void 0?u.defaultMaxListeners:r._maxListeners}u.prototype.getMaxListeners=function(){return $(this)};u.prototype.emit=function(e){for(var t=[],n=1;n0&&(s=t[0]),s instanceof Error)throw s;var a=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw a.context=s,a}var l=i[e];if(l===void 0)return!1;if(typeof l=="function")J(l,this,t);else for(var v=l.length,m=q(l,v),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=r,a.type=e,a.count=s.length,we(a)}return r}u.prototype.addListener=function(e,t){return G(this,e,t,!1)};u.prototype.on=u.prototype.addListener;u.prototype.prependListener=function(e,t){return G(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 z(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}u.prototype.once=function(e,t){return k(t),this.on(e,z(this,e,t)),this};u.prototype.prependOnceListener=function(e,t){return k(t),this.prependListener(e,z(this,e,t)),this};u.prototype.removeListener=function(e,t){var n,o,i,s,a;if(k(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){a=n[s].listener,i=s;break}if(i<0)return this;i===0?n.shift():ge(n,i),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 i=Object.keys(n),s;for(o=0;o=0;o--)this.removeListener(e,t[o]);return this};function Q(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?_e(o):q(o,o.length)}u.prototype.listeners=function(e){return Q(this,e,!0)};u.prototype.rawListeners=function(e){return Q(this,e,!1)};u.listenerCount=function(r,e){return typeof r.listenerCount=="function"?r.listenerCount(e):Z.call(r,e)};u.prototype.listenerCount=Z;function Z(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 q(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 _(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 a(m){try{v(n.next(m))}catch(g){s(g)}}function l(m){try{v(n.throw(m))}catch(g){s(g)}}function v(m){m.done?i(m.value):o(m.value).then(a,l)}v((n=n.apply(r,e||[])).next())})}function R(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 F(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),a("next"),a("throw"),a("return",s),o[Symbol.asyncIterator]=function(){return this},o;function s(f){return function(w){return Promise.resolve(w).then(f,g)}}function a(f,w){n[f]&&(o[f]=function(A){return new Promise(function(te,ne){i.push([f,A,te,ne])>1||l(f,A)})},w&&(o[f]=w(o[f])))}function l(f,w){try{v(n[f](w))}catch(A){S(i[0][3],A)}}function v(f){f.value instanceof E?Promise.resolve(f.value.v).then(m,g):S(i[0][2],f)}function m(f){l("next",f)}function g(f){l("throw",f)}function S(f,w){f(w),i.shift(),i.length&&l(i[0][0],i[0][1])}}function pe(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:E(r[o](s)),done:!1}:i?i(s):s}:i}}function me(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 R=="function"?R(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(a,l){s=r[i](s),o(a,l,s.done,s.value)})}}function o(i,s,a,l){Promise.resolve(l).then(function(v){i({value:v,done:a})},s)}}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(_(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 de(e)}static combineWithAllErrors(e){return ve(e)}map(e){return new r(this._promise.then(t=>_(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=>_(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=>_(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=>_(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=>_(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 F(this,arguments,function*(){return yield E(yield E(yield*pe(me(yield E(this._promise.then(t=>t.safeUnwrap()))))))})}then(e,t){return this._promise.then(e,t)}[Symbol.asyncIterator](){return F(this,arguments,function*(){let t=yield E(this._promise);return t.isErr()&&(yield yield E(O(t.error))),yield E(t.value)})}};var O=r=>new p(Promise.resolve(new h(r))),Me=p.fromPromise,Ie=p.fromSafePromise,Se=p.fromThrowable,T=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},de=r=>p.fromSafePromise(Promise.all(r)).andThen(T),j=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},ve=r=>p.fromSafePromise(Promise.all(r)).andThen(j),x;(function(r){function e(o,i){return(...s)=>{try{let a=o(...s);return L(a)}catch(a){return y(i?i(a):a)}}}r.fromThrowable=e;function t(o){return T(o)}r.combine=t;function n(o){return j(o)}r.combineWithAllErrors=n})(x||(x={}));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 U("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 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 y(e),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(e){throw U("Called `_unsafeUnwrap` on an Err",this,e)}_unsafeUnwrapErr(e){return this.error}*[Symbol.iterator](){let e=this;return yield e,e}},Ce=x.fromThrowable;var W=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 ye=()=>typeof Deno<"u";var b=r=>ye()?new URL(`./worker/${r}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${r==="main"?`worker/${r}`:r}.js`));var V=le(Y());var I=new V.default,c,K=!1;self.onmessage=r=>{Ae(r),K||(K=!0,I.once("OPERATION_FAILED",()=>{c&&c.terminate()}))};var Ae=(r,e)=>{let{action:t}=r.data;if(t===5||t===8)c.postMessage(r.data);else{switch(t){case 2:c=new Worker(b("cancel"),{type:"module"}),c.postMessage(r.data);break;case 3:c=new Worker(b("download"),{type:"module"}),c.postMessage(r.data);break;case 4:c=new Worker(b("infos"),{type:"module"}),c.postMessage(r.data);break;case 7:c=c||new Worker(b("remove"),{type:"module"}),c.postMessage(r.data);break;case 9:c=c||new Worker(b("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}`)}}},ee=()=>{I.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),I.once("OPERATION_FAILED",r=>{self.postMessage({event:"OPERATION_FAILED",error:r})})};var re=!1;self.onmessage=r=>{re||(ee(),re=!0),Pe(r.data).map(()=>{self.postMessage({event:"FILE_REMOVED"})}).mapErr(e=>{self.postMessage({event:"OPERATION_FAILED",error:e})})};var Pe=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(o.statusText))}),e=>W(e)); diff --git a/themes/default/public/js/worker/upload.js b/themes/default/public/js/worker/upload.js index 60a4119..f55fa9b 100644 --- a/themes/default/public/js/worker/upload.js +++ b/themes/default/public/js/worker/upload.js @@ -1 +1 @@ -var Yt=Object.create;var je=Object.defineProperty;var Qt=Object.getOwnPropertyDescriptor;var Zt=Object.getOwnPropertyNames;var er=Object.getPrototypeOf,tr=Object.prototype.hasOwnProperty;var st=e=>{throw TypeError(e)};var rr=(e,t,r)=>t in e?je(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var nr=(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 We=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var ir=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Zt(t))!tr.call(e,i)&&i!==r&&je(e,i,{get:()=>t[i],enumerable:!(n=Qt(t,i))||n.enumerable});return e};var se=(e,t,r)=>(r=e!=null?Yt(er(e)):{},ir(t||!e||!e.__esModule?je(r,"default",{value:e,enumerable:!0}):r,e));var D=(e,t,r)=>rr(e,typeof t!="symbol"?t+"":t,r),ze=(e,t,r)=>t.has(e)||st("Cannot "+r);var d=(e,t,r)=>(ze(e,t,"read from private field"),r?r.call(e):t.get(e)),A=(e,t,r)=>t.has(e)?st("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,r),w=(e,t,r,n)=>(ze(e,t,"write to private field"),n?n.call(e,r):t.set(e,r),r),b=(e,t,r)=>(ze(e,t,"access private method"),r);var be=(e,t,r,n)=>({set _(i){w(e,t,i,r)},get _(){return d(e,t,n)}});var De=We((wn,qe)=>{"use strict";var K=typeof Reflect=="object"?Reflect:null,lt=K&&typeof K.apply=="function"?K.apply:function(t,r,n){return Function.prototype.apply.call(t,r,n)},Oe;K&&typeof K.ownKeys=="function"?Oe=K.ownKeys:Object.getOwnPropertySymbols?Oe=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:Oe=function(t){return Object.getOwnPropertyNames(t)};function hr(e){console&&console.warn&&console.warn(e)}var pt=Number.isNaN||function(t){return t!==t};function v(){v.init.call(this)}qe.exports=v;qe.exports.once=yr;v.EventEmitter=v;v.prototype._events=void 0;v.prototype._eventsCount=0;v.prototype._maxListeners=void 0;var ht=10;function xe(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 ht},set:function(e){if(typeof e!="number"||e<0||pt(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");ht=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||pt(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 dt(e){return e._maxListeners===void 0?v.defaultMaxListeners:e._maxListeners}v.prototype.getMaxListeners=function(){return dt(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=o[t];if(u===void 0)return!1;if(typeof u=="function")lt(u,this,r);else for(var f=u.length,h=Et(u,f),n=0;n0&&s.length>i&&!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,hr(c)}return e}v.prototype.addListener=function(t,r){return mt(this,t,r,!1)};v.prototype.on=v.prototype.addListener;v.prototype.prependListener=function(t,r){return mt(this,t,r,!0)};function pr(){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 yt(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},i=pr.bind(n);return i.listener=r,n.wrapFn=i,i}v.prototype.once=function(t,r){return xe(r),this.on(t,yt(this,t,r)),this};v.prototype.prependOnceListener=function(t,r){return xe(r),this.prependListener(t,yt(this,t,r)),this};v.prototype.removeListener=function(t,r){var n,i,o,s,c;if(xe(r),i=this._events,i===void 0)return this;if(n=i[t],n===void 0)return this;if(n===r||n.listener===r)--this._eventsCount===0?this._events=Object.create(null):(delete i[t],i.removeListener&&this.emit("removeListener",t,n.listener||r));else if(typeof n!="function"){for(o=-1,s=n.length-1;s>=0;s--)if(n[s]===r||n[s].listener===r){c=n[s].listener,o=s;break}if(o<0)return this;o===0?n.shift():dr(n,o),n.length===1&&(i[t]=n[0]),i.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,i;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 o=Object.keys(n),s;for(i=0;i=0;i--)this.removeListener(t,r[i]);return this};function gt(e,t,r){var n=e._events;if(n===void 0)return[];var i=n[t];return i===void 0?[]:typeof i=="function"?r?[i.listener||i]:[i]:r?mr(i):Et(i,i.length)}v.prototype.listeners=function(t){return gt(this,t,!0)};v.prototype.rawListeners=function(t){return gt(this,t,!1)};v.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):vt.call(e,t)};v.prototype.listenerCount=vt;function vt(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?Oe(this._events):[]};function Et(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.s[0][0][0]||this.O();var t,r,n,i,o=this.s[0][4],s=this.s[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),i=[]],e=t;e<4*t+28;e++)r=n[e-1],(e%t===0||t===8&&e%t===4)&&(r=o[r>>>24]<<24^o[r>>16&255]<<16^o[r>>8&255]<<8^o[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],i[t]=4>=e||4>t?r:s[0][o[r>>>24]]^s[1][o[r>>16&255]]^s[2][o[r>>8&255]]^s[3][o[r&255]]};a.cipher.aes.prototype={encrypt:function(e){return Dt(this,e,0)},decrypt:function(e){return Dt(this,e,1)},s:[[[],[],[],[],[]],[[],[],[],[],[]]],O:function(){var e=this.s[0],t=this.s[1],r=e[4],n=t[4],i,o,s,c=[],u=[],f,h,l,p;for(i=0;256>i;i++)u[(c[i]=i<<1^283*(i>>7))^i]=i;for(o=s=0;!r[o];o^=f||1,s=u[s]||1)for(l=s^s<<1^s<<2^s<<3^s<<4,l=l>>8^l&255^99,r[o]=l,n[l]=o,h=c[i=c[f=c[o]]],p=16843009*h^65537*i^257*f^16843008*o,h=257*c[l]^16843008*l,i=0;4>i;i++)e[i][o]=h=h<<24^h>>>8,t[i][l]=p=p<<24^p>>>8;for(i=0;5>i;i++)e[i]=e[i].slice(0),t[i]=t[i].slice(0)}};function Dt(e,t,r){if(t.length!==4)throw new a.exception.invalid("invalid aes block size");var n=e.b[r],i=t[0]^n[0],o=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,p=4,m=[0,0,0,0];c=e.s[r],e=c[0];var E=c[1],V=c[2],Ae=c[3],Le=c[4];for(l=0;l>>24]^E[o>>16&255]^V[s>>8&255]^Ae[t&255]^n[p],u=e[o>>>24]^E[s>>16&255]^V[t>>8&255]^Ae[i&255]^n[p+1],f=e[s>>>24]^E[t>>16&255]^V[i>>8&255]^Ae[o&255]^n[p+2],t=e[t>>>24]^E[i>>16&255]^V[o>>8&255]^Ae[s&255]^n[p+3],p+=4,i=c,o=u,s=f;for(l=0;4>l;l++)m[r?3&-l:l]=Le[i>>>24]<<24^Le[o>>16&255]<<16^Le[s>>8&255]<<8^Le[t&255]^n[p++],c=i,i=o,o=s,s=t,t=c;return m}a.bitArray={bitSlice:function(e,t,r){return e=a.bitArray.$(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[i]<<32-t;return i=e.length?e[e.length-1]:0,e=a.bitArray.getPartial(i),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,i;for(n=0;n>>8>>>8>>>8),i<<=8;return decodeURIComponent(escape(t))},toBits:function(e){e=unescape(encodeURIComponent(e));var t=[],r,n=0;for(r=0;r>>s)>>>i),sh){if(!t)try{return a.codec.base32hex.toBits(e)}catch{}throw new a.exception.invalid("this isn't "+l+"!")}c>i?(c-=i,o.push(f^h>>>c),f=h<>>i)>>>26),6>i?(s=e[r]<<6-i,i+=26,r++):(s<<=6,i-=6);for(;n.length&3&&!t;)n+="=";return n},toBits:function(e,t){e=e.replace(/\s|=/g,"");var r=[],n,i=0,o=a.codec.base64.B,s=0,c;for(t&&(o=o.substr(0,62)+"-_"),n=0;nc)throw new a.exception.invalid("this isn't base64!");26>>i),s=c<<32-i):(i+=6,s^=c<<32-i)}return i&56&&r.push(a.bitArray.partial(i&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.O(),e?(this.F=e.F.slice(0),this.A=e.A.slice(0),this.l=e.l):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.F=this.Y.slice(0),this.A=[],this.l=0,this},update:function(e){typeof e=="string"&&(e=a.codec.utf8String.toBits(e));var t,r=this.A=a.bitArray.concat(this.A,e);if(t=this.l,e=this.l=t+a.bitArray.bitLength(e),9007199254740991t;r++){for(i=!0,n=2;n*n<=r;n++)if(r%n===0){i=!1;break}i&&(8>t&&(this.Y[t]=e(Math.pow(r,.5))),this.b[t]=e(Math.pow(r,1/3)),t++)}}};function He(e,t){var r,n,i,o=e.F,s=e.b,c=o[0],u=o[1],f=o[2],h=o[3],l=o[4],p=o[5],m=o[6],E=o[7];for(r=0;64>r;r++)16>r?n=t[r]:(n=t[r+1&15],i=t[r+14&15],n=t[r&15]=(n>>>7^n>>>18^n>>>3^n<<25^n<<14)+(i>>>17^i>>>19^i>>>10^i<<15^i<<13)+t[r&15]+t[r+9&15]|0),n=n+E+(l>>>6^l>>>11^l>>>25^l<<26^l<<21^l<<7)+(m^l&(p^m))+s[r],E=m,m=p,p=l,l=h+n|0,h=f,f=u,u=c,c=n+(u&f^h&(u^f))+(u>>>2^u>>>13^u>>>22^u<<30^u<<19^u<<10)|0;o[0]=o[0]+c|0,o[1]=o[1]+u|0,o[2]=o[2]+f|0,o[3]=o[3]+h|0,o[4]=o[4]+l|0,o[5]=o[5]+p|0,o[6]=o[6]+m|0,o[7]=o[7]+E|0}a.mode.ccm={name:"ccm",G:[],listenProgress:function(e){a.mode.ccm.G.push(e)},unListenProgress:function(e){e=a.mode.ccm.G.indexOf(e),-1u)throw new a.exception.invalid("ccm: iv must be at least 7 bytes");for(o=2;4>o&&f>>>8*o;o++);return o<15-u&&(o=15-u),r=c.clamp(r,8*(15-o)),t=a.mode.ccm.V(e,t,r,n,i,o),s=a.mode.ccm.C(e,s,r,t,i,o),c.concat(s.data,s.tag)},decrypt:function(e,t,r,n,i){i=i||64,n=n||[];var o=a.bitArray,s=o.bitLength(r)/8,f=o.bitLength(t),c=o.clamp(t,f-i),u=o.bitSlice(t,f-i),f=(f-i)/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=o.clamp(r,8*(15-t)),c=a.mode.ccm.C(e,c,r,u,i,t),e=a.mode.ccm.V(e,c.data,r,n,i,t),!o.equal(c.tag,e))throw new a.exception.corrupt("ccm: tag doesn't match");return c.data},na:function(e,t,r,n,i,o){var s=[],c=a.bitArray,u=c.i;if(n=[c.partial(8,(t.length?64:0)|n-2<<2|o-1)],n=c.concat(n,r),n[3]|=i,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;ti||16h&&(a.mode.ccm.fa(s/u),h+=l),r[3]++,i=e.encrypt(r),t[s]^=i[0],t[s+1]^=i[1],t[s+2]^=i[2],t[s+3]^=i[3];return{tag:n,data:c.clamp(t,f)}}};a.mode.ocb2={name:"ocb2",encrypt:function(e,t,r,n,i,o){if(a.bitArray.bitLength(r)!==128)throw new a.exception.invalid("ocb iv must be 128 bits");var s,c=a.mode.ocb2.S,u=a.bitArray,f=u.i,h=[0,0,0,0];r=c(e.encrypt(r));var l,p=[];for(n=n||[],i=i||64,s=0;s+4i.bitLength(r)&&(c=o(c,n(c)),r=i.concat(r,[-2147483648,0,0,0])),s=o(s,r),e.encrypt(o(n(o(c,n(c))),s))},S:function(e){return[e[0]<<1^e[1]>>>31,e[1]<<1^e[2]>>>31,e[2]<<1^e[3]>>>31,e[3]<<1^135*(e[0]>>>31)]}};a.mode.gcm={name:"gcm",encrypt:function(e,t,r,n,i){var o=t.slice(0);return t=a.bitArray,n=n||[],e=a.mode.gcm.C(!0,e,o,n,r,i||128),t.concat(e.data,e.tag)},decrypt:function(e,t,r,n,i){var o=t.slice(0),s=a.bitArray,c=s.bitLength(o);if(i=i||128,n=n||[],i<=c?(t=s.bitSlice(o,c-i),o=s.bitSlice(o,0,c-i)):(t=o,o=[]),e=a.mode.gcm.C(!1,e,o,n,r,i),!s.equal(e.tag,t))throw new a.exception.corrupt("gcm: tag doesn't match");return e.data},ka:function(e,t){var r,n,i,o,s,c=a.bitArray.i;for(i=[0,0,0,0],o=t.slice(0),r=0;128>r;r++){for((n=(e[Math.floor(r/32)]&1<<31-r%32)!==0)&&(i=c(i,o)),s=(o[3]&1)!==0,n=3;0>>1|(o[n-1]&1)<<31;o[0]>>>=1,s&&(o[0]^=-520093696)}return i},j:function(e,t,r){var n,i=r.length;for(t=t.slice(0),n=0;ni&&(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)),i=i||a.misc.hmac,e=new i(e);var o,s,c,u,f=[],h=a.bitArray;for(u=1;32*f.length<(n||1);u++){for(i=o=e.encrypt(h.concat(t,[u])),s=1;ss;s++)i.push(4294967296*Math.random()|0);for(s=0;s=1<this.o&&(this.o=o),this.P++,this.b=a.hash.sha256.hash(this.b.concat(i)),this.L=new a.cipher.aes(this.b),n=0;4>n&&(this.h[n]=this.h[n]+1|0,!this.h[n]);n++);}for(n=0;n>>1;this.c[s].update([n,this.N++,2,t,o,e.length].concat(e))}break;case"string":t===void 0&&(t=e.length),this.c[s].update([n,this.N++,3,t,o,e.length]),this.c[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.m[s]+=t,this.f+=t,c===this.u&&(this.isReady()!==this.u&&_t("seeded",Math.max(this.o,this.f)),_t("progress",this.getProgress()))},isReady:function(e){return e=this.T[e!==void 0?e:this.M],this.o&&this.o>=e?this.m[0]>this.ba&&new Date().valueOf()>this.Z?this.J|this.I:this.I:this.f>=e?this.J|this.u:this.u},getProgress:function(e){return e=this.T[e||this.M],this.o>=e||this.f>e?1:this.f/e},startCollectors:function(){if(!this.D){if(this.a={loadTimeCollector:fe(this,this.ma),mouseCollector:fe(this,this.oa),keyboardCollector:fe(this,this.la),accelerometerCollector:fe(this,this.ea),touchCollector:fe(this,this.qa)},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.K[e][this.ga++]=t},removeEventListener:function(e,t){var r,n,i=this.K[e],o=[];for(n in i)i.hasOwnProperty(n)&&i[n]===t&&o.push(n);for(r=0;rt&&(e.h[t]=e.h[t]+1|0,!e.h[t]);t++);return e.L.encrypt(e.h)}function fe(e,t){return function(){t.apply(e,arguments)}}a.random=new a.prng(6);e:try{if(Se=typeof Q<"u"&&Q.exports){try{Re=nr("crypto")}catch{Re=null}Se=Pe=Re}if(Se&&Pe.randomBytes)le=Pe.randomBytes(128),le=new Uint32Array(new Uint8Array(le).buffer),a.random.addEntropy(le,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 le,Pe,he,Se,Re;a.json={defaults:{v:1,iter:1e4,ks:128,ts:64,mode:"ccm",adata:"",cipher:"aes"},ja:function(e,t,r,n){r=r||{},n=n||{};var i=a.json,o=i.g({iv:a.random.randomWords(4,0)},i.defaults),s;if(i.g(o,r),r=o.adata,typeof o.salt=="string"&&(o.salt=a.codec.base64.toBits(o.salt)),typeof o.iv=="string"&&(o.iv=a.codec.base64.toBits(o.iv)),!a.mode[o.mode]||!a.cipher[o.cipher]||typeof e=="string"&&100>=o.iter||o.ts!==64&&o.ts!==96&&o.ts!==128||o.ks!==128&&o.ks!==192&&o.ks!==256||2>o.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 Wr=Object.prototype.hasOwnProperty,k="~";function pe(){}Object.create&&(pe.prototype=Object.create(null),new pe().__proto__||(k=!1));function zr(e,t,r){this.fn=e,this.context=t,this.once=r||!1}function jt(e,t,r,n,i){if(typeof r!="function")throw new TypeError("The listener must be a function");var o=new zr(r,n||e,i),s=k?k+t:t;return e._events[s]?e._events[s].fn?e._events[s]=[e._events[s],o]:e._events[s].push(o):(e._events[s]=o,e._eventsCount++),e}function Te(e,t){--e._eventsCount===0?e._events=new pe:delete e._events[t]}function _(){this._events=new pe,this._eventsCount=0}_.prototype.eventNames=function(){var t=[],r,n;if(this._eventsCount===0)return t;for(n in r=this._events)Wr.call(r,n)&&t.push(k?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(r)):t};_.prototype.listeners=function(t){var r=k?k+t:t,n=this._events[r];if(!n)return[];if(n.fn)return[n.fn];for(var i=0,o=n.length,s=new Array(o);i{let n=t.isOk()?{type:"Ok",value:t.value}:{type:"Err",value:t.error},i=r.withStackTrace?new Error().stack:void 0;return{data:n,message:e,stack:i}};function X(e,t,r,n){function i(o){return o instanceof r?o:new r(function(s){s(o)})}return new(r||(r=Promise))(function(o,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?o(h.value):i(h.value).then(c,u)}f((n=n.apply(e,[])).next())})}function at(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 sr(e,t,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=r.apply(e,t||[]),i,o=[];return i={},s("next"),s("throw"),s("return"),i[Symbol.asyncIterator]=function(){return this},i;function s(p){n[p]&&(i[p]=function(m){return new Promise(function(E,V){o.push([p,m,E,V])>1||c(p,m)})})}function c(p,m){try{u(n[p](m))}catch(E){l(o[0][3],E)}}function u(p){p.value instanceof G?Promise.resolve(p.value.v).then(f,h):l(o[0][2],p)}function f(p){c("next",p)}function h(p){c("throw",p)}function l(p,m){p(m),o.shift(),o.length&&c(o[0][0],o[0][1])}}function ar(e){var t,r;return t={},n("next"),n("throw",function(i){throw i}),n("return"),t[Symbol.iterator]=function(){return this},t;function n(i,o){t[i]=e[i]?function(s){return(r=!r)?{value:G(e[i](s)),done:i==="return"}:o?o(s):s}:o}}function cr(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 at=="function"?at(e):e[Symbol.iterator](),r={},n("next"),n("throw"),n("return"),r[Symbol.asyncIterator]=function(){return this},r);function n(o){r[o]=e[o]&&function(s){return new Promise(function(c,u){s=e[o](s),i(c,u,s.done,s.value)})}}function i(o,s,c,u){Promise.resolve(u).then(function(f){o({value:f,done:c})},s)}}var L=class e{constructor(t){this._promise=t}static fromSafePromise(t){let r=t.then(n=>new R(n));return new e(r)}static fromPromise(t,r){let n=t.then(i=>new R(i)).catch(i=>new T(r(i)));return new e(n)}static fromThrowable(t,r){return(...n)=>new e(X(this,void 0,void 0,function*(){try{return new R(yield t(...n))}catch(i){return new T(r?r(i):i)}}))}static combine(t){return ur(t)}static combineWithAllErrors(t){return fr(t)}map(t){return new e(this._promise.then(r=>X(this,void 0,void 0,function*(){return r.isErr()?new T(r.error):new R(yield t(r.value))})))}andThrough(t){return new e(this._promise.then(r=>X(this,void 0,void 0,function*(){if(r.isErr())return new T(r.error);let n=yield t(r.value);return n.isErr()?new T(n.error):new R(r.value)})))}andTee(t){return new e(this._promise.then(r=>X(this,void 0,void 0,function*(){if(r.isErr())return new T(r.error);try{yield t(r.value)}catch{}return new R(r.value)})))}mapErr(t){return new e(this._promise.then(r=>X(this,void 0,void 0,function*(){return r.isOk()?new R(r.value):new T(yield t(r.error))})))}andThen(t){return new e(this._promise.then(r=>{if(r.isErr())return new T(r.error);let n=t(r.value);return n instanceof e?n._promise:n}))}orElse(t){return new e(this._promise.then(r=>X(this,void 0,void 0,function*(){return r.isErr()?t(r.error):new R(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 sr(this,arguments,function*(){return yield G(yield G(yield*ar(cr(yield G(this._promise.then(r=>r.safeUnwrap()))))))})}then(t,r){return this._promise.then(t,r)}},C=e=>new L(Promise.resolve(new R(e))),O=e=>new L(Promise.resolve(new T(e))),Hr=L.fromPromise,Gr=L.fromSafePromise,Vr=L.fromThrowable,ut=e=>{let t=q([]);for(let r of e)if(r.isErr()){t=U(r.error);break}else t.map(n=>n.push(r.value));return t},ur=e=>L.fromSafePromise(Promise.all(e)).andThen(ut),ft=e=>{let t=q([]);for(let r of e)r.isErr()&&t.isErr()?t.error.push(r.error):r.isErr()&&t.isOk()?t=U([r.error]):r.isOk()&&t.isOk()&&t.value.push(r.value);return t},fr=e=>L.fromSafePromise(Promise.all(e)).andThen(ft),Je;(function(e){function t(i,o){return(...s)=>{try{let c=i(...s);return q(c)}catch(c){return U(o?o(c):c)}}}e.fromThrowable=t;function r(i){return ut(i)}e.combine=r;function n(i){return ft(i)}e.combineWithAllErrors=n})(Je||(Je={}));var q=e=>new R(e);function U(e){return new T(e)}var R=class{constructor(t){this.value=t}isOk(){return!0}isErr(){return!this.isOk()}map(t){return q(t(this.value))}mapErr(t){return q(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 q(this.value)}orElse(t){return q(this.value)}asyncAndThen(t){return t(this.value)}asyncAndThrough(t){return t(this.value).map(()=>this.value)}asyncMap(t){return L.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 ct("Called `_unsafeUnwrapErr` on an Ok",this,t)}},T=class{constructor(t){this.error=t}isOk(){return!1}isErr(){return!this.isOk()}map(t){return U(this.error)}mapErr(t){return U(t(this.error))}andThrough(t){return U(this.error)}andTee(t){return U(this.error)}andThen(t){return U(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 U(t),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(t){throw ct("Called `_unsafeUnwrap` on an Err",this,t)}_unsafeUnwrapErr(t){return this.error}},Xr=Je.fromThrowable;var B=class extends Error{constructor(r,n={}){let{cause:i,context:o}=n;super(r,{cause:i});D(this,"context");this.name=this.constructor.name,this.context=o}};var j=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 lr=()=>typeof Deno<"u";var W=e=>lr()?new URL(`./worker/${e}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${e==="main"?`worker/${e}`:e}.js`));var N=class extends B{};var ae=class extends N{constructor(){super(...arguments);D(this,"message","An error occured while trying to connect to WebSocket")}};var bt=se(De());var g=new bt.default,x,At=!1;self.onmessage=e=>{vr(e),At||(At=!0,g.once("OPERATION_FAILED",()=>{x&&x.terminate()}))};var z=(e,t)=>(Object.assign(e,t),typeof WorkerGlobalScope<"u"&&self.postMessage({event:"FILE_UPDATED",lufiFile:e}),e),Ce=(e,t)=>{z(e,{uploadStatus:2}),self.postMessage({event:"OPERATION_FAILED",error:t})},vr=(e,t)=>{let{action:r}=e.data;if(r===5||r===8)x.postMessage(e.data);else{switch(r){case 2:x=new Worker(W("cancel"),{type:"module"}),x.postMessage(e.data);break;case 3:x=new Worker(W("download"),{type:"module"}),x.postMessage(e.data);break;case 4:x=new Worker(W("infos"),{type:"module"}),x.postMessage(e.data);break;case 7:x=x||new Worker(W("remove"),{type:"module"}),x.postMessage(e.data);break;case 9:x=x||new Worker(W("upload"),{type:"module"}),x.postMessage(e.data);break;default:console.error("Action not found")}x.onmessage=n=>{t&&t(n),self.postMessage(n.data)},x.onerror=n=>{console.error(`Error: ${n.message}`)}}},Ot=()=>{g.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),g.once("OPERATION_FAILED",e=>{self.postMessage({event:"OPERATION_FAILED",error:e})})};var Y=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),i="";for(let o=0;o>2]+this._charset[(n[o]&3)<<4|n[o+1]>>4]+this._charset[(n[o+1]&15)<<2|n[o+2]>>6]+this._charset[n[o+2]&63];return r%3==2?(i=i.substring(0,i.length-1),this._noPadding||(i+="=")):r%3==1&&(i=i.substring(0,i.length-2),this._noPadding||(i+="==")),i}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),i,o,s,c,u=0,f=0;for(;u>4,n[u++]=(o&15)<<4|s>>2,n[u++]=(s&3)<<6|c;return n.buffer}};var Er=new Y("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");function ce(e){return Er.Decode(e)}var wr=new Y("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",!0);function $e(e){return wr.Decode(e)}var Pt=se(Ct());var $=class extends B{};var Z=class extends ${constructor(){super(...arguments);D(this,"message","Unable to decrypt the provided data")}};var St=(e,t)=>{try{let r=typeof t=="string"?t:t.data;return C(ce(Pt.default.decrypt(e,r)))}catch(r){return O(new Z(void 0,{cause:j(r)}))}};var Rt=(e,t)=>br(e).andThen(r=>L.fromPromise(crypto.subtle.decrypt({name:"AES-GCM",iv:t.iv},r,ce(t.data)),n=>new Z(void 0,{cause:j(n)})));var br=e=>L.fromPromise(crypto.subtle.importKey("raw",$e(e),{name:"AES-GCM"},!1,["encrypt","decrypt"]),t=>new $("Unable to import cryptography key",{cause:j(t)}));var Tt=(e,t)=>t.algo===void 0||t.algo===0?St(e,t):Rt(e,t);var S={},Mt=5,xr=e=>(g.emit("UPLOAD_CANCELLED",e.success),C(void 0)),Dr=(e,t)=>{let r=e.split("XXMOJOXX"),n=r.shift();if(n!==void 0){let i=JSON.parse(n);if(Mr(i)){let o=r.shift();if(o){let s=JSON.parse(o);return s.iv&&(s.iv=new Uint8Array(Object.values(s.iv))),Tt(t.keys.client,s).andThen(c=>{let u=typeof c=="string"?new TextEncoder().encode(c).buffer:c;return i.part===0?(z(t,{chunksReady:t.chunksReady+1,delAtFirstView:i.del_at_first_view,delay:i.delay,name:i.name,size:i.size,totalChunks:i.total,type:i.type,zipped:i.zipped}),g.emit("DOWNLOAD_STARTED")):z(t,{chunksReady:t.chunksReady+1}),g.emit("CHUNK_DOWNLOADED",u,i.part),++i.part===i.total?Pr(t).andThen(()=>(g.emit("DOWNLOAD_COMPLETE"),g.emit("SOCKET_OPERATION_TERMINATED"),C(void 0))):C(void 0)})}else{let s=new N("Can't retrieve metadata from data received by the server");return g.emit("OPERATION_FAILED",s),O(s)}}else{let o=new N(i.msg);return g.emit("OPERATION_FAILED",o),O(o)}}else{let i=new N("Can't retrieve metadata from data received by the server");return g.emit("OPERATION_FAILED",i),O(i)}},_r=(e,t)=>{if(e.success)return e.j===0&&(z(t,{keys:{client:t.keys.client,server:e.short},actionToken:e.token,queueIndex:e.i}),g.emit("UPLOAD_STARTED")),z(t,{chunksReady:t.chunksReady+1,createdAt:e.created_at}),g.emit("CHUNK_UPLOADED"),t.chunksReady===t.totalChunks&&(z(t,{uploadStatus:1}),g.emit("UPLOAD_COMPLETE"),g.emit("SOCKET_OPERATION_TERMINATED")),C(void 0);{let r=new N(e.msg);return g.emit("OPERATION_FAILED",r),O(r)}},kr=(e,t)=>{let r=Ir(e.data),n;if(r)if(!r.action&&r.msg){let i=new N(r.msg);return g.emit("OPERATION_FAILED",i),O(i)}else"delay"in r?n=_r(r,t):n=xr(r);else n=Dr(e.data,t);return n},Cr=e=>S!==void 0&&S[e]!==void 0&&S[e].readyState===WebSocket.CONNECTING,Xe=e=>S!==void 0&&S[e]!==void 0&&S[e].readyState===WebSocket.OPEN;var Pr=e=>{let t;return e.password?t={ended:!0,file_pwd:e.password}:t={ended:!0},Ye(Rr(e),e,JSON.stringify(t))},Ke=(e,t,r)=>Ye(Tr(e),e,`${JSON.stringify(t)}XXMOJOXX${JSON.stringify(r)}`),Ye=(e,t,r)=>Xe(e)?(S[e].onmessage=n=>kr(n,t),S[e].send(r),C(void 0)):Ut(e).andThen(()=>Ye(e,t,r)),Ut=(e,t=0)=>(!Xe(e)&&!Cr(e)&&(S[e]=new WebSocket(e),g.once("SOCKET_OPERATION_TERMINATED",()=>{S[e].close()}),g.once("OPERATION_FAILED",()=>{g.emit("SOCKET_OPERATION_TERMINATED")}),S[e].onopen=()=>{g.emit("SOCKET_OPENED")},S[e].onclose=()=>{},S[e].onerror=()=>++t<=Mt?(console.error(`An error happened while trying to connect to WebSocket ${e}. Trying again. ${t} / ${Mt}`),Ut(e,t)):(g.emit("SOCKET_ONERROR"),O(new ae(`Unable to connect to WebSocket ${e}.`)))),Sr(e).andThen(()=>C(e)).orElse(r=>O(r))),Sr=e=>L.fromPromise(new Promise((t,r)=>{Xe(e)?t(void 0):(g.once("SOCKET_OPENED",()=>{t(void 0)}),g.on("SOCKET_ONERROR",()=>{r(new ae)}))}),t=>j(t));var Nt=(e,t)=>{let r=new URL(e);return r.protocol=r.protocol==="http:"?"ws:":"wss:",r.pathname+=t,new URL(r.origin+r.pathname)},Rr=e=>Nt(new URL(e.serverUrl),"download"+`/${e.keys.server}`).toString(),Tr=e=>Nt(new URL(e.serverUrl),"upload").toString(),Ir=e=>{try{let t=JSON.parse(e);if(t&&typeof t=="object")return t}catch{}return!1},Mr=e=>typeof e=="object"&&e!==null&&!("msg"in e);var Ft=se(De());var Fr=se(De());var Br={},so=new Ft.default;var jr=()=>Object.values(Br).filter(e=>e.uploadStatus===4),Bt=e=>Object.keys(jr()).indexOf(e);var Ze=se(Wt(),1);var de=class extends Error{constructor(t){super(t),this.name="TimeoutError"}},et=class extends Error{constructor(t){super(),this.name="AbortError",this.message=t}},zt=e=>globalThis.DOMException===void 0?new et(e):new DOMException(e),Jt=e=>{let t=e.reason===void 0?zt("This operation was aborted."):e.reason;return t instanceof Error?t:zt(t)};function tt(e,t){let{milliseconds:r,fallback:n,message:i,customTimers:o={setTimeout,clearTimeout}}=t,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(t.signal){let{signal:p}=t;p.aborted&&h(Jt(p));let m=()=>{h(Jt(p))};p.addEventListener("abort",m,{once:!0}),e.finally(()=>{p.removeEventListener("abort",m)})}if(r===Number.POSITIVE_INFINITY){e.then(f,h);return}let l=new de;s=o.setTimeout.call(void 0,()=>{if(n){try{f(n())}catch(p){h(p)}return}typeof e.cancel=="function"&&e.cancel(),i===!1?f():i instanceof Error?h(i):(l.message=i!=null?i:`Promise timed out after ${r} milliseconds`,h(l))},r),(async()=>{try{f(await e)}catch(p){h(p)}})()}).finally(()=>{u.clear()});return u.clear=()=>{o.clearTimeout.call(void 0,s),s=void 0},u}function rt(e,t,r){let n=0,i=e.length;for(;i>0;){let o=Math.trunc(i/2),s=n+o;r(e[s],t)<=0?(n=++s,i-=o+1):i=o}return n}var F,me=class{constructor(){A(this,F,[])}enqueue(t,r){r={priority:0,...r};let n={priority:r.priority,run:t};if(this.size&&d(this,F)[this.size-1].priority>=r.priority){d(this,F).push(n);return}let i=rt(d(this,F),n,(o,s)=>s.priority-o.priority);d(this,F).splice(i,0,n)}dequeue(){let t=d(this,F).shift();return t==null?void 0:t.run}filter(t){return d(this,F).filter(r=>r.priority===t.priority).map(r=>r.run)}get size(){return d(this,F).length}};F=new WeakMap;var ee,te,H,ge,re,ve,I,ne,P,Ee,M,ie,J,we,y,qt,$t,Ht,Gt,Vt,Ie,nt,it,Me,Xt,Ue,ye=class extends Ze.default{constructor(r){var n,i,o,s;super();A(this,y);A(this,ee);A(this,te);A(this,H,0);A(this,ge);A(this,re);A(this,ve,0);A(this,I);A(this,ne);A(this,P);A(this,Ee);A(this,M,0);A(this,ie);A(this,J);A(this,we);D(this,"timeout");if(r={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:me,...r},!(typeof r.intervalCap=="number"&&r.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${(i=(n=r.intervalCap)==null?void 0:n.toString())!=null?i:""}\` (${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=(o=r.interval)==null?void 0:o.toString())!=null?s:""}\` (${typeof r.interval})`);w(this,ee,r.carryoverConcurrencyCount),w(this,te,r.intervalCap===Number.POSITIVE_INFINITY||r.interval===0),w(this,ge,r.intervalCap),w(this,re,r.interval),w(this,P,new r.queueClass),w(this,Ee,r.queueClass),this.concurrency=r.concurrency,this.timeout=r.timeout,w(this,we,r.throwOnTimeout===!0),w(this,J,r.autoStart===!1)}get concurrency(){return d(this,ie)}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,ie,r),b(this,y,Me).call(this)}async add(r,n={}){return n={timeout:this.timeout,throwOnTimeout:d(this,we),...n},new Promise((i,o)=>{d(this,P).enqueue(async()=>{var s;be(this,M)._++,be(this,H)._++;try{(s=n.signal)==null||s.throwIfAborted();let c=r({signal:n.signal});n.timeout&&(c=tt(Promise.resolve(c),{milliseconds:n.timeout})),n.signal&&(c=Promise.race([c,b(this,y,Xt).call(this,n.signal)]));let u=await c;i(u),this.emit("completed",u)}catch(c){if(c instanceof de&&!n.throwOnTimeout){i();return}o(c),this.emit("error",c)}finally{b(this,y,Ht).call(this)}},n),this.emit("add"),b(this,y,Ie).call(this)})}async addAll(r,n){return Promise.all(r.map(async i=>this.add(i,n)))}start(){return d(this,J)?(w(this,J,!1),b(this,y,Me).call(this),this):this}pause(){w(this,J,!0)}clear(){w(this,P,new(d(this,Ee)))}async onEmpty(){d(this,P).size!==0&&await b(this,y,Ue).call(this,"empty")}async onSizeLessThan(r){d(this,P).sized(this,P).size{b(this,y,Gt).call(this)},n)),!0}return!1},Ie=function(){if(d(this,P).size===0)return d(this,I)&&clearInterval(d(this,I)),w(this,I,void 0),this.emit("empty"),d(this,M)===0&&this.emit("idle"),!1;if(!d(this,J)){let r=!d(this,y,Vt);if(d(this,y,qt)&&d(this,y,$t)){let n=d(this,P).dequeue();return n?(this.emit("active"),n(),r&&b(this,y,nt).call(this),!0):!1}}return!1},nt=function(){d(this,te)||d(this,I)!==void 0||(w(this,I,setInterval(()=>{b(this,y,it).call(this)},d(this,re))),w(this,ve,Date.now()+d(this,re)))},it=function(){d(this,H)===0&&d(this,M)===0&&d(this,I)&&(clearInterval(d(this,I)),w(this,I,void 0)),w(this,H,d(this,ee)?d(this,M):0),b(this,y,Me).call(this)},Me=function(){for(;b(this,y,Ie).call(this););},Xt=async function(r){return new Promise((n,i)=>{r.addEventListener("abort",()=>{i(r.reason)},{once:!0})})},Ue=async function(r,n){return new Promise(i=>{let o=()=>{n&&!n()||(this.off(r,o),i())};this.on(r,o)})};var Kt=!1,ot=navigator.hardwareConcurrency||4,oe=new ye({concurrency:ot,autoStart:!1}),Fe=0,Be=[],Ne=!1;self.onmessage=e=>{let t=e.data,{chunk:r,lufiFile:n}=t.args;if(Kt||(Ot(),Kt=!0),r){if(Be[r.index]=r,Be.length===n.totalChunks)return g.once("UPLOAD_COMPLETE",()=>{self.postMessage({event:"UPLOAD_COMPLETE"})}),g.on("FILE_UPDATED",z),g.on("CHUNK_UPLOADED",()=>{self.postMessage({event:"CHUNK_UPLOADED"}),Fe--,!Ne&&Feqr(e,Bt(e.args.lufiFile.keys.client)),qr=(e,t)=>{let{lufiFile:r}=e.args,n=new Worker(W("encrypt"),{type:"module"});return g.on("UPLOAD_STARTED",()=>{n.onmessage=async i=>{if(i.data.encryptedData){let{encryptedData:o}=i.data;await oe.add(async()=>{await Ke(r,{total:r.totalChunks,part:i.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},o),Fe++,(Ne||Fe===ot)&&oe.pause()})}oe.start(),i.data.error&&(Ce(r,i.data.error),n.terminate())};for(let i=1;i{if(i.data.encryptedData){let{encryptedData:o}=i.data;Ke(r,{total:r.totalChunks,part:i.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},o).mapErr(s=>{Ce(r,s)})}i.data.error&&Ce(r,i.data.error)},e.args.chunk=Be[0],n.postMessage(e),C(void 0)}; +var Qt=Object.create;var je=Object.defineProperty;var Zt=Object.getOwnPropertyDescriptor;var er=Object.getOwnPropertyNames;var tr=Object.getPrototypeOf,rr=Object.prototype.hasOwnProperty;var st=t=>{throw TypeError(t)};var nr=(t,e,r)=>e in t?je(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var or=(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 We=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var ir=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of er(e))!rr.call(t,o)&&o!==r&&je(t,o,{get:()=>e[o],enumerable:!(n=Zt(e,o))||n.enumerable});return t};var ce=(t,e,r)=>(r=t!=null?Qt(tr(t)):{},ir(e||!t||!t.__esModule?je(r,"default",{value:t,enumerable:!0}):r,t));var D=(t,e,r)=>nr(t,typeof e!="symbol"?e+"":e,r),ze=(t,e,r)=>e.has(t)||st("Cannot "+r);var p=(t,e,r)=>(ze(t,e,"read from private field"),r?r.call(t):e.get(t)),A=(t,e,r)=>e.has(t)?st("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r),w=(t,e,r,n)=>(ze(t,e,"write to private field"),n?n.call(t,r):e.set(t,r),r),O=(t,e,r)=>(ze(t,e,"access private method"),r);var be=(t,e,r,n)=>({set _(o){w(t,e,o,r)},get _(){return p(t,e,n)}});var De=We((wn,qe)=>{"use strict";var Q=typeof Reflect=="object"?Reflect:null,ht=Q&&typeof Q.apply=="function"?Q.apply:function(e,r,n){return Function.prototype.apply.call(e,r,n)},Oe;Q&&typeof Q.ownKeys=="function"?Oe=Q.ownKeys:Object.getOwnPropertySymbols?Oe=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:Oe=function(e){return Object.getOwnPropertyNames(e)};function hr(t){console&&console.warn&&console.warn(t)}var dt=Number.isNaN||function(e){return e!==e};function E(){E.init.call(this)}qe.exports=E;qe.exports.once=yr;E.EventEmitter=E;E.prototype._events=void 0;E.prototype._eventsCount=0;E.prototype._maxListeners=void 0;var pt=10;function xe(t){if(typeof t!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t)}Object.defineProperty(E,"defaultMaxListeners",{enumerable:!0,get:function(){return pt},set:function(t){if(typeof t!="number"||t<0||dt(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");pt=t}});E.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};E.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||dt(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 mt(t){return t._maxListeners===void 0?E.defaultMaxListeners:t._maxListeners}E.prototype.getMaxListeners=function(){return mt(this)};E.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")ht(u,this,r);else for(var f=u.length,h=wt(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,hr(c)}return t}E.prototype.addListener=function(e,r){return yt(this,e,r,!1)};E.prototype.on=E.prototype.addListener;E.prototype.prependListener=function(e,r){return yt(this,e,r,!0)};function pr(){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 gt(t,e,r){var n={fired:!1,wrapFn:void 0,target:t,type:e,listener:r},o=pr.bind(n);return o.listener=r,n.wrapFn=o,o}E.prototype.once=function(e,r){return xe(r),this.on(e,gt(this,e,r)),this};E.prototype.prependOnceListener=function(e,r){return xe(r),this.prependListener(e,gt(this,e,r)),this};E.prototype.removeListener=function(e,r){var n,o,i,s,c;if(xe(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():dr(n,i),n.length===1&&(o[e]=n[0]),o.removeListener!==void 0&&this.emit("removeListener",e,c||r)}return this};E.prototype.off=E.prototype.removeListener;E.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 vt(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?mr(o):wt(o,o.length)}E.prototype.listeners=function(e){return vt(this,e,!0)};E.prototype.rawListeners=function(e){return vt(this,e,!1)};E.listenerCount=function(t,e){return typeof t.listenerCount=="function"?t.listenerCount(e):Et.call(t,e)};E.prototype.listenerCount=Et;function Et(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}E.prototype.eventNames=function(){return this._eventsCount>0?Oe(this._events):[]};function wt(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.s[0][0][0]||this.O();var e,r,n,o,i=this.s[0][4],s=this.s[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 _t(this,t,0)},decrypt:function(t){return _t(this,t,1)},s:[[[],[],[],[],[]],[[],[],[],[],[]]],O:function(){var t=this.s[0],e=this.s[1],r=t[4],n=e[4],o,i,s,c=[],u=[],f,h,l,d;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]]],d=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]=d=d<<24^d>>>8;for(o=0;5>o;o++)t[o]=t[o].slice(0),e[o]=e[o].slice(0)}};function _t(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,d=4,m=[0,0,0,0];c=t.s[r],t=c[0];var v=c[1],j=c[2],X=c[3],K=c[4];for(l=0;l>>24]^v[i>>16&255]^j[s>>8&255]^X[e&255]^n[d],u=t[i>>>24]^v[s>>16&255]^j[e>>8&255]^X[o&255]^n[d+1],f=t[s>>>24]^v[e>>16&255]^j[o>>8&255]^X[i&255]^n[d+2],e=t[e>>>24]^v[o>>16&255]^j[i>>8&255]^X[s&255]^n[d+3],d+=4,o=c,i=u,s=f;for(l=0;4>l;l++)m[r?3&-l:l]=K[o>>>24]<<24^K[i>>16&255]<<16^K[s>>8&255]<<8^K[e&255]^n[d++],c=o,o=i,i=s,s=e,e=c;return m}a.bitArray={bitSlice:function(t,e,r){return t=a.bitArray.$(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>>s)>>>o),sh){if(!e)try{return a.codec.base32hex.toBits(t)}catch{}throw new a.exception.invalid("this isn't "+l+"!")}c>o?(c-=o,i.push(f^h>>>c),f=h<>>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.B,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.O(),t?(this.F=t.F.slice(0),this.A=t.A.slice(0),this.l=t.l):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.F=this.Y.slice(0),this.A=[],this.l=0,this},update:function(t){typeof t=="string"&&(t=a.codec.utf8String.toBits(t));var e,r=this.A=a.bitArray.concat(this.A,t);if(e=this.l,t=this.l=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.Y[e]=t(Math.pow(r,.5))),this.b[e]=t(Math.pow(r,1/3)),e++)}}};function He(t,e){var r,n,o,i=t.F,s=t.b,c=i[0],u=i[1],f=i[2],h=i[3],l=i[4],d=i[5],m=i[6],v=i[7];for(r=0;64>r;r++)16>r?n=e[r]:(n=e[r+1&15],o=e[r+14&15],n=e[r&15]=(n>>>7^n>>>18^n>>>3^n<<25^n<<14)+(o>>>17^o>>>19^o>>>10^o<<15^o<<13)+e[r&15]+e[r+9&15]|0),n=n+v+(l>>>6^l>>>11^l>>>25^l<<26^l<<21^l<<7)+(m^l&(d^m))+s[r],v=m,m=d,d=l,l=h+n|0,h=f,f=u,u=c,c=n+(u&f^h&(u^f))+(u>>>2^u>>>13^u>>>22^u<<30^u<<19^u<<10)|0;i[0]=i[0]+c|0,i[1]=i[1]+u|0,i[2]=i[2]+f|0,i[3]=i[3]+h|0,i[4]=i[4]+l|0,i[5]=i[5]+d|0,i[6]=i[6]+m|0,i[7]=i[7]+v|0}a.mode.ccm={name:"ccm",G:[],listenProgress:function(t){a.mode.ccm.G.push(t)},unListenProgress:function(t){t=a.mode.ccm.G.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.V(t,e,r,n,o,i),s=a.mode.ccm.C(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.C(t,c,r,u,o,e),t=a.mode.ccm.V(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},na:function(t,e,r,n,o,i){var s=[],c=a.bitArray,u=c.i;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.fa(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.mode.ocb2={name:"ocb2",encrypt:function(t,e,r,n,o,i){if(a.bitArray.bitLength(r)!==128)throw new a.exception.invalid("ocb iv must be 128 bits");var s,c=a.mode.ocb2.S,u=a.bitArray,f=u.i,h=[0,0,0,0];r=c(t.encrypt(r));var l,d=[];for(n=n||[],o=o||64,s=0;s+4o.bitLength(r)&&(c=i(c,n(c)),r=o.concat(r,[-2147483648,0,0,0])),s=i(s,r),t.encrypt(i(n(i(c,n(c))),s))},S:function(t){return[t[0]<<1^t[1]>>>31,t[1]<<1^t[2]>>>31,t[2]<<1^t[3]>>>31,t[3]<<1^135*(t[0]>>>31)]}};a.mode.gcm={name:"gcm",encrypt:function(t,e,r,n,o){var i=e.slice(0);return e=a.bitArray,n=n||[],t=a.mode.gcm.C(!0,t,i,n,r,o||128),e.concat(t.data,t.tag)},decrypt:function(t,e,r,n,o){var i=e.slice(0),s=a.bitArray,c=s.bitLength(i);if(o=o||128,n=n||[],o<=c?(e=s.bitSlice(i,c-o),i=s.bitSlice(i,0,c-o)):(e=i,i=[]),t=a.mode.gcm.C(!1,t,i,n,r,o),!s.equal(t.tag,e))throw new a.exception.corrupt("gcm: tag doesn't match");return t.data},ka:function(t,e){var r,n,o,i,s,c=a.bitArray.i;for(o=[0,0,0,0],i=e.slice(0),r=0;128>r;r++){for((n=(t[Math.floor(r/32)]&1<<31-r%32)!==0)&&(o=c(o,i)),s=(i[3]&1)!==0,n=3;0>>1|(i[n-1]&1)<<31;i[0]>>>=1,s&&(i[0]^=-520093696)}return o},j:function(t,e,r){var n,o=r.length;for(e=e.slice(0),n=0;no&&(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.o&&(this.o=i),this.P++,this.b=a.hash.sha256.hash(this.b.concat(o)),this.L=new a.cipher.aes(this.b),n=0;4>n&&(this.h[n]=this.h[n]+1|0,!this.h[n]);n++);}for(n=0;n>>1;this.c[s].update([n,this.N++,2,e,i,t.length].concat(t))}break;case"string":e===void 0&&(e=t.length),this.c[s].update([n,this.N++,3,e,i,t.length]),this.c[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.m[s]+=e,this.f+=e,c===this.u&&(this.isReady()!==this.u&&kt("seeded",Math.max(this.o,this.f)),kt("progress",this.getProgress()))},isReady:function(t){return t=this.T[t!==void 0?t:this.M],this.o&&this.o>=t?this.m[0]>this.ba&&new Date().valueOf()>this.Z?this.J|this.I:this.I:this.f>=t?this.J|this.u:this.u},getProgress:function(t){return t=this.T[t||this.M],this.o>=t||this.f>t?1:this.f/t},startCollectors:function(){if(!this.D){if(this.a={loadTimeCollector:he(this,this.ma),mouseCollector:he(this,this.oa),keyboardCollector:he(this,this.la),accelerometerCollector:he(this,this.ea),touchCollector:he(this,this.qa)},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.K[t][this.ga++]=e},removeEventListener:function(t,e){var r,n,o=this.K[t],i=[];for(n in o)o.hasOwnProperty(n)&&o[n]===e&&i.push(n);for(r=0;re&&(t.h[e]=t.h[e]+1|0,!t.h[e]);e++);return t.L.encrypt(t.h)}function he(t,e){return function(){e.apply(t,arguments)}}a.random=new a.prng(6);e:try{if(Se=typeof ee<"u"&&ee.exports){try{Re=or("crypto")}catch{Re=null}Se=Pe=Re}if(Se&&Pe.randomBytes)pe=Pe.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(de=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(de);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(de);else break e;a.random.addEntropy(de,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 pe,Pe,de,Se,Re;a.json={defaults:{v:1,iter:1e4,ks:128,ts:64,mode:"ccm",adata:"",cipher:"aes"},ja:function(t,e,r,n){r=r||{},n=n||{};var o=a.json,i=o.g({iv:a.random.randomWords(4,0)},o.defaults),s;if(o.g(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 Wr=Object.prototype.hasOwnProperty,k="~";function me(){}Object.create&&(me.prototype=Object.create(null),new me().__proto__||(k=!1));function zr(t,e,r){this.fn=t,this.context=e,this.once=r||!1}function Wt(t,e,r,n,o){if(typeof r!="function")throw new TypeError("The listener must be a function");var i=new zr(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 Te(t,e){--t._eventsCount===0?t._events=new me:delete t._events[e]}function _(){this._events=new me,this._eventsCount=0}_.prototype.eventNames=function(){var e=[],r,n;if(this._eventsCount===0)return e;for(n in r=this._events)Wr.call(r,n)&&e.push(k?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(r)):e};_.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 Y(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 at(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 U(t){return this instanceof U?(this.v=t,this):new U(t)}function ct(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(m){return function(v){return Promise.resolve(v).then(m,l)}}function c(m,v){n[m]&&(o[m]=function(j){return new Promise(function(X,K){i.push([m,j,X,K])>1||u(m,j)})},v&&(o[m]=v(o[m])))}function u(m,v){try{f(n[m](v))}catch(j){d(i[0][3],j)}}function f(m){m.value instanceof U?Promise.resolve(m.value.v).then(h,l):d(i[0][2],m)}function h(m){u("next",m)}function l(m){u("throw",m)}function d(m,v){m(v),i.shift(),i.length&&u(i[0][0],i[0][1])}}function ar(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:U(t[o](s)),done:!1}:i?i(s):s}:i}}function cr(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 at=="function"?at(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 b=class t{constructor(e){this._promise=e}static fromSafePromise(e){let r=e.then(n=>new R(n));return new t(r)}static fromPromise(e,r){let n=e.then(o=>new R(o)).catch(o=>new T(r(o)));return new t(n)}static fromThrowable(e,r){return(...n)=>new t(Y(this,void 0,void 0,function*(){try{return new R(yield e(...n))}catch(o){return new T(r?r(o):o)}}))}static combine(e){return ur(e)}static combineWithAllErrors(e){return fr(e)}map(e){return new t(this._promise.then(r=>Y(this,void 0,void 0,function*(){return r.isErr()?new T(r.error):new R(yield e(r.value))})))}andThrough(e){return new t(this._promise.then(r=>Y(this,void 0,void 0,function*(){if(r.isErr())return new T(r.error);let n=yield e(r.value);return n.isErr()?new T(n.error):new R(r.value)})))}andTee(e){return new t(this._promise.then(r=>Y(this,void 0,void 0,function*(){if(r.isErr())return new T(r.error);try{yield e(r.value)}catch{}return new R(r.value)})))}mapErr(e){return new t(this._promise.then(r=>Y(this,void 0,void 0,function*(){return r.isOk()?new R(r.value):new T(yield e(r.error))})))}andThen(e){return new t(this._promise.then(r=>{if(r.isErr())return new T(r.error);let n=e(r.value);return n instanceof t?n._promise:n}))}orElse(e){return new t(this._promise.then(r=>Y(this,void 0,void 0,function*(){return r.isErr()?e(r.error):new R(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 ct(this,arguments,function*(){return yield U(yield U(yield*ar(cr(yield U(this._promise.then(r=>r.safeUnwrap()))))))})}then(e,r){return this._promise.then(e,r)}[Symbol.asyncIterator](){return ct(this,arguments,function*(){let r=yield U(this._promise);return r.isErr()&&(yield yield U(L(r.error))),yield U(r.value)})}},C=t=>new b(Promise.resolve(new R(t))),L=t=>new b(Promise.resolve(new T(t))),Hr=b.fromPromise,Gr=b.fromSafePromise,Vr=b.fromThrowable,ft=t=>{let e=H([]);for(let r of t)if(r.isErr()){e=N(r.error);break}else e.map(n=>n.push(r.value));return e},ur=t=>b.fromSafePromise(Promise.all(t)).andThen(ft),lt=t=>{let e=H([]);for(let r of t)r.isErr()&&e.isErr()?e.error.push(r.error):r.isErr()&&e.isOk()?e=N([r.error]):r.isOk()&&e.isOk()&&e.value.push(r.value);return e},fr=t=>b.fromSafePromise(Promise.all(t)).andThen(lt),Je;(function(t){function e(o,i){return(...s)=>{try{let c=o(...s);return H(c)}catch(c){return N(i?i(c):c)}}}t.fromThrowable=e;function r(o){return ft(o)}t.combine=r;function n(o){return lt(o)}t.combineWithAllErrors=n})(Je||(Je={}));var H=t=>new R(t);function N(t){return new T(t)}var R=class{constructor(e){this.value=e}isOk(){return!0}isErr(){return!this.isOk()}map(e){return H(e(this.value))}mapErr(e){return H(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 H(this.value)}orElse(e){return H(this.value)}asyncAndThen(e){return e(this.value)}asyncAndThrough(e){return e(this.value).map(()=>this.value)}asyncMap(e){return b.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 ut("Called `_unsafeUnwrapErr` on an Ok",this,e)}*[Symbol.iterator](){return this.value}},T=class{constructor(e){this.error=e}isOk(){return!1}isErr(){return!this.isOk()}map(e){return N(this.error)}mapErr(e){return N(e(this.error))}andThrough(e){return N(this.error)}andTee(e){return N(this.error)}andThen(e){return N(this.error)}orElse(e){return e(this.error)}asyncAndThen(e){return L(this.error)}asyncAndThrough(e){return L(this.error)}asyncMap(e){return L(this.error)}unwrapOr(e){return e}match(e,r){return r(this.error)}safeUnwrap(){let e=this.error;return function*(){throw yield N(e),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(e){throw ut("Called `_unsafeUnwrap` on an Err",this,e)}_unsafeUnwrapErr(e){return this.error}*[Symbol.iterator](){let e=this;return yield e,e}},Xr=Je.fromThrowable;var W=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 z=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 lr=()=>typeof Deno<"u";var J=t=>lr()?new URL(`./worker/${t}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${t==="main"?`worker/${t}`:t}.js`));var F=class extends W{};var ue=class extends F{constructor(){super(...arguments);D(this,"message","An error occured while trying to connect to WebSocket")}};var Ot=ce(De());var g=new Ot.default,x,Lt=!1;self.onmessage=t=>{vr(t),Lt||(Lt=!0,g.once("OPERATION_FAILED",()=>{x&&x.terminate()}))};var q=(t,e)=>(Object.assign(t,e),typeof WorkerGlobalScope<"u"&&self.postMessage({event:"FILE_UPDATED",lufiFile:t}),t),Ce=(t,e)=>{q(t,{uploadStatus:2}),self.postMessage({event:"OPERATION_FAILED",error:e})},vr=(t,e)=>{let{action:r}=t.data;if(r===5||r===8)x.postMessage(t.data);else{switch(r){case 2:x=new Worker(J("cancel"),{type:"module"}),x.postMessage(t.data);break;case 3:x=new Worker(J("download"),{type:"module"}),x.postMessage(t.data);break;case 4:x=new Worker(J("infos"),{type:"module"}),x.postMessage(t.data);break;case 7:x=x||new Worker(J("remove"),{type:"module"}),x.postMessage(t.data);break;case 9:x=x||new Worker(J("upload"),{type:"module"}),x.postMessage(t.data);break;default:console.error("Action not found")}x.onmessage=n=>{e&&e(n),self.postMessage(n.data)},x.onerror=n=>{console.error(`Error: ${n.message}`)}}},xt=()=>{g.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),g.once("OPERATION_FAILED",t=>{self.postMessage({event:"OPERATION_FAILED",error:t})})};var Z=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 Er=new Z("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");function fe(t){return Er.Decode(t)}var wr=new Z("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",!0);function $e(t){return wr.Decode(t)}var St=ce(Pt());var G=class extends W{};var te=class extends G{constructor(){super(...arguments);D(this,"message","Unable to decrypt the provided data")}};var Rt=(t,e)=>{try{let r=typeof e=="string"?e:e.data;return C(fe(St.default.decrypt(t,r)))}catch(r){return L(new te(void 0,{cause:z(r)}))}};var Tt=(t,e)=>br(t).andThen(r=>b.fromPromise(crypto.subtle.decrypt({name:"AES-GCM",iv:e.iv},r,fe(e.data)),n=>new te(void 0,{cause:z(n)})));var br=t=>b.fromPromise(crypto.subtle.importKey("raw",$e(t),{name:"AES-GCM"},!1,["encrypt","decrypt"]),e=>new G("Unable to import cryptography key",{cause:z(e)}));var It=(t,e)=>e.algo===void 0||e.algo===0?Rt(t,e):Tt(t,e);var S={},Ut=5,xr=t=>(g.emit("UPLOAD_CANCELLED",t.success),C(void 0)),Dr=(t,e)=>{let r=t.split("XXMOJOXX"),n=r.shift();if(n!==void 0){let o=JSON.parse(n);if(Mr(o)){let i=r.shift();if(i){let s=JSON.parse(i);return s.iv&&(s.iv=new Uint8Array(Object.values(s.iv))),It(e.keys.client,s).andThen(c=>{let u=typeof c=="string"?new TextEncoder().encode(c).buffer:c;return o.part===0?(q(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}),g.emit("DOWNLOAD_STARTED")):q(e,{chunksReady:e.chunksReady+1}),g.emit("CHUNK_DOWNLOADED",u,o.part),++o.part===o.total?Pr(e).andThen(()=>(g.emit("DOWNLOAD_COMPLETE"),g.emit("SOCKET_OPERATION_TERMINATED"),C(void 0))):C(void 0)})}else{let s=new F("Can't retrieve metadata from data received by the server");return g.emit("OPERATION_FAILED",s),L(s)}}else{let i=new F(o.msg);return g.emit("OPERATION_FAILED",i),L(i)}}else{let o=new F("Can't retrieve metadata from data received by the server");return g.emit("OPERATION_FAILED",o),L(o)}},_r=(t,e)=>{if(t.success)return t.j===0&&(q(e,{keys:{client:e.keys.client,server:t.short},actionToken:t.token,queueIndex:t.i}),g.emit("UPLOAD_STARTED")),q(e,{chunksReady:e.chunksReady+1,createdAt:t.created_at}),g.emit("CHUNK_UPLOADED"),e.chunksReady===e.totalChunks&&(q(e,{uploadStatus:1}),g.emit("UPLOAD_COMPLETE"),g.emit("SOCKET_OPERATION_TERMINATED")),C(void 0);{let r=new F(t.msg);return g.emit("OPERATION_FAILED",r),L(r)}},kr=(t,e)=>{let r=Ir(t.data),n;if(r)if(!r.action&&r.msg){let o=new F(r.msg);return g.emit("OPERATION_FAILED",o),L(o)}else"delay"in r?n=_r(r,e):n=xr(r);else n=Dr(t.data,e);return n},Cr=t=>S!==void 0&&S[t]!==void 0&&S[t].readyState===WebSocket.CONNECTING,Xe=t=>S!==void 0&&S[t]!==void 0&&S[t].readyState===WebSocket.OPEN;var Pr=t=>{let e;return t.password?e={ended:!0,file_pwd:t.password}:e={ended:!0},Ye(Rr(t),t,JSON.stringify(e))},Ke=(t,e,r)=>Ye(Tr(t),t,`${JSON.stringify(e)}XXMOJOXX${JSON.stringify(r)}`),Ye=(t,e,r)=>Xe(t)?(S[t].onmessage=n=>kr(n,e),S[t].send(r),C(void 0)):Nt(t).andThen(()=>Ye(t,e,r)),Nt=(t,e=0)=>(!Xe(t)&&!Cr(t)&&(S[t]=new WebSocket(t),g.once("SOCKET_OPERATION_TERMINATED",()=>{S[t].close()}),g.once("OPERATION_FAILED",()=>{g.emit("SOCKET_OPERATION_TERMINATED")}),S[t].onopen=()=>{g.emit("SOCKET_OPENED")},S[t].onclose=()=>{},S[t].onerror=()=>++e<=Ut?(console.error(`An error happened while trying to connect to WebSocket ${t}. Trying again. ${e} / ${Ut}`),Nt(t,e)):(g.emit("SOCKET_ONERROR"),L(new ue(`Unable to connect to WebSocket ${t}.`)))),Sr(t).andThen(()=>C(t)).orElse(r=>L(r))),Sr=t=>b.fromPromise(new Promise((e,r)=>{Xe(t)?e(void 0):(g.once("SOCKET_OPENED",()=>{e(void 0)}),g.on("SOCKET_ONERROR",()=>{r(new ue)}))}),e=>z(e));var Ft=(t,e)=>{let r=new URL(t);return r.protocol=r.protocol==="http:"?"ws:":"wss:",r.pathname+=e,new URL(r.origin+r.pathname)},Rr=t=>Ft(new URL(t.serverUrl),"download"+`/${t.keys.server}`).toString(),Tr=t=>Ft(new URL(t.serverUrl),"upload").toString(),Ir=t=>{try{let e=JSON.parse(t);if(e&&typeof e=="object")return e}catch{}return!1},Mr=t=>typeof t=="object"&&t!==null&&!("msg"in t);var Bt=ce(De());var Fr=ce(De());var Br={},ai=new Bt.default;var jr=()=>Object.values(Br).filter(t=>t.uploadStatus===4),jt=t=>Object.keys(jr()).indexOf(t);var Ze=ce(zt(),1);var ye=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},et=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},Jt=t=>globalThis.DOMException===void 0?new et(t):new DOMException(t),qt=t=>{let e=t.reason===void 0?Jt("This operation was aborted."):t.reason;return e instanceof Error?e:Jt(e)};function tt(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:d}=e;d.aborted&&h(qt(d));let m=()=>{h(qt(d))};d.addEventListener("abort",m,{once:!0}),t.finally(()=>{d.removeEventListener("abort",m)})}if(r===Number.POSITIVE_INFINITY){t.then(f,h);return}let l=new ye;s=i.setTimeout.call(void 0,()=>{if(n){try{f(n())}catch(d){h(d)}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(d){h(d)}})()}).finally(()=>{u.clear()});return u.clear=()=>{i.clearTimeout.call(void 0,s),s=void 0},u}function rt(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 B,ge=class{constructor(){A(this,B,[])}enqueue(e,r){r={priority:0,...r};let n={priority:r.priority,run:e};if(this.size&&p(this,B)[this.size-1].priority>=r.priority){p(this,B).push(n);return}let o=rt(p(this,B),n,(i,s)=>s.priority-i.priority);p(this,B).splice(o,0,n)}dequeue(){let e=p(this,B).shift();return e==null?void 0:e.run}filter(e){return p(this,B).filter(r=>r.priority===e.priority).map(r=>r.run)}get size(){return p(this,B).length}};B=new WeakMap;var re,ne,V,Ee,oe,we,I,ie,P,Ae,M,se,$,Le,y,$t,Ht,Gt,Vt,Xt,Ie,nt,ot,Me,Kt,Ue,ve=class extends Ze.default{constructor(r){var n,o,i,s;super();A(this,y);A(this,re);A(this,ne);A(this,V,0);A(this,Ee);A(this,oe);A(this,we,0);A(this,I);A(this,ie);A(this,P);A(this,Ae);A(this,M,0);A(this,se);A(this,$);A(this,Le);D(this,"timeout");if(r={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:ge,...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,re,r.carryoverConcurrencyCount),w(this,ne,r.intervalCap===Number.POSITIVE_INFINITY||r.interval===0),w(this,Ee,r.intervalCap),w(this,oe,r.interval),w(this,P,new r.queueClass),w(this,Ae,r.queueClass),this.concurrency=r.concurrency,this.timeout=r.timeout,w(this,Le,r.throwOnTimeout===!0),w(this,$,r.autoStart===!1)}get concurrency(){return p(this,se)}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,se,r),O(this,y,Me).call(this)}async add(r,n={}){return n={timeout:this.timeout,throwOnTimeout:p(this,Le),...n},new Promise((o,i)=>{p(this,P).enqueue(async()=>{var s;be(this,M)._++,be(this,V)._++;try{(s=n.signal)==null||s.throwIfAborted();let c=r({signal:n.signal});n.timeout&&(c=tt(Promise.resolve(c),{milliseconds:n.timeout})),n.signal&&(c=Promise.race([c,O(this,y,Kt).call(this,n.signal)]));let u=await c;o(u),this.emit("completed",u)}catch(c){if(c instanceof ye&&!n.throwOnTimeout){o();return}i(c),this.emit("error",c)}finally{O(this,y,Gt).call(this)}},n),this.emit("add"),O(this,y,Ie).call(this)})}async addAll(r,n){return Promise.all(r.map(async o=>this.add(o,n)))}start(){return p(this,$)?(w(this,$,!1),O(this,y,Me).call(this),this):this}pause(){w(this,$,!0)}clear(){w(this,P,new(p(this,Ae)))}async onEmpty(){p(this,P).size!==0&&await O(this,y,Ue).call(this,"empty")}async onSizeLessThan(r){p(this,P).sizep(this,P).size{O(this,y,Vt).call(this)},n)),!0}return!1},Ie=function(){if(p(this,P).size===0)return p(this,I)&&clearInterval(p(this,I)),w(this,I,void 0),this.emit("empty"),p(this,M)===0&&this.emit("idle"),!1;if(!p(this,$)){let r=!p(this,y,Xt);if(p(this,y,$t)&&p(this,y,Ht)){let n=p(this,P).dequeue();return n?(this.emit("active"),n(),r&&O(this,y,nt).call(this),!0):!1}}return!1},nt=function(){p(this,ne)||p(this,I)!==void 0||(w(this,I,setInterval(()=>{O(this,y,ot).call(this)},p(this,oe))),w(this,we,Date.now()+p(this,oe)))},ot=function(){p(this,V)===0&&p(this,M)===0&&p(this,I)&&(clearInterval(p(this,I)),w(this,I,void 0)),w(this,V,p(this,re)?p(this,M):0),O(this,y,Me).call(this)},Me=function(){for(;O(this,y,Ie).call(this););},Kt=async function(r){return new Promise((n,o)=>{r.addEventListener("abort",()=>{o(r.reason)},{once:!0})})},Ue=async function(r,n){return new Promise(o=>{let i=()=>{n&&!n()||(this.off(r,i),o())};this.on(r,i)})};var Yt=!1,it=navigator.hardwareConcurrency||4,ae=new ve({concurrency:it,autoStart:!1}),Fe=0,Be=[],Ne=!1;self.onmessage=t=>{let e=t.data,{chunk:r,lufiFile:n}=e.args;if(Yt||(xt(),Yt=!0),r){if(Be[r.index]=r,Be.length===n.totalChunks)return g.once("UPLOAD_COMPLETE",()=>{self.postMessage({event:"UPLOAD_COMPLETE"})}),g.on("FILE_UPDATED",q),g.on("CHUNK_UPLOADED",()=>{self.postMessage({event:"CHUNK_UPLOADED"}),Fe--,!Ne&&Feqr(t,jt(t.args.lufiFile.keys.client)),qr=(t,e)=>{let{lufiFile:r}=t.args,n=new Worker(J("encrypt"),{type:"module"});return g.on("UPLOAD_STARTED",()=>{n.onmessage=async o=>{if(o.data.encryptedData){let{encryptedData:i}=o.data;await ae.add(async()=>{await Ke(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:e,file_pwd:r.password},i),Fe++,(Ne||Fe===it)&&ae.pause()})}ae.start(),o.data.error&&(Ce(r,o.data.error),n.terminate())};for(let o=1;o{if(o.data.encryptedData){let{encryptedData:i}=o.data;Ke(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:e,file_pwd:r.password},i).mapErr(s=>{Ce(r,s)})}o.data.error&&Ce(r,o.data.error)},t.args.chunk=Be[0],n.postMessage(t),C(void 0)};