From 2e02ed37940fcc1fc3141c55d096a4f3ff7daec6 Mon Sep 17 00:00:00 2001 From: Booteille Date: Thu, 31 Oct 2024 16:23:37 +0100 Subject: [PATCH] Update lufi API to last version --- themes/default/public/js/worker/cancel.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 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/themes/default/public/js/worker/cancel.js b/themes/default/public/js/worker/cancel.js index c9dd395..160ec2a 100644 --- a/themes/default/public/js/worker/cancel.js +++ b/themes/default/public/js/worker/cancel.js @@ -1 +1 @@ -var Xe=Object.create;var se=Object.defineProperty;var ze=Object.getOwnPropertyDescriptor;var Ge=Object.getOwnPropertyNames;var $e=Object.getPrototypeOf,Ke=Object.prototype.hasOwnProperty;var qe=(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 ce=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var He=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ge(t))!Ke.call(e,o)&&o!==r&&se(e,o,{get:()=>t[o],enumerable:!(n=ze(t,o))||n.enumerable});return e};var ae=(e,t,r)=>(r=e!=null?Xe($e(e)):{},He(t||!e||!e.__esModule?se(r,"default",{value:e,enumerable:!0}):r,e));var we=ce((Mt,Q)=>{"use strict";var M=typeof Reflect=="object"?Reflect:null,fe=M&&typeof M.apply=="function"?M.apply:function(t,r,n){return Function.prototype.apply.call(t,r,n)},q;M&&typeof M.ownKeys=="function"?q=M.ownKeys:Object.getOwnPropertySymbols?q=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:q=function(t){return Object.getOwnPropertyNames(t)};function Ye(e){console&&console.warn&&console.warn(e)}var he=Number.isNaN||function(t){return t!==t};function p(){p.init.call(this)}Q.exports=p;Q.exports.once=et;p.EventEmitter=p;p.prototype._events=void 0;p.prototype._eventsCount=0;p.prototype._maxListeners=void 0;var ue=10;function H(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 ue},set:function(e){if(typeof e!="number"||e<0||he(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");ue=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||he(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 le(e){return e._maxListeners===void 0?p.defaultMaxListeners:e._maxListeners}p.prototype.getMaxListeners=function(){return le(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")fe(f,this,r);else for(var u=f.length,l=ge(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,Ye(a)}return e}p.prototype.addListener=function(t,r){return de(this,t,r,!1)};p.prototype.on=p.prototype.addListener;p.prototype.prependListener=function(t,r){return de(this,t,r,!0)};function Ve(){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 pe(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},o=Ve.bind(n);return o.listener=r,n.wrapFn=o,o}p.prototype.once=function(t,r){return H(r),this.on(t,pe(this,t,r)),this};p.prototype.prependOnceListener=function(t,r){return H(r),this.prependListener(t,pe(this,t,r)),this};p.prototype.removeListener=function(t,r){var n,o,i,s,a;if(H(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():Ze(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 me(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?Qe(o):ge(o,o.length)}p.prototype.listeners=function(t){return me(this,t,!0)};p.prototype.rawListeners=function(t){return me(this,t,!1)};p.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):ye.call(e,t)};p.prototype.listenerCount=ye;function ye(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?q(this._events):[]};function ge(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],P=a[2],$=a[3],K=a[4];for(h=0;h>>24]^g[i>>16&255]^P[s>>8&255]^$[t&255]^n[d],f=e[i>>>24]^g[s>>16&255]^P[t>>8&255]^$[o&255]^n[d+1],u=e[s>>>24]^g[t>>16&255]^P[o>>8&255]^$[i&255]^n[d+2],t=e[t>>>24]^g[o>>16&255]^P[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]=K[o>>>24]<<24^K[i>>16&255]<<16^K[s>>8&255]<<8^K[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 re(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&&Se("seeded",Math.max(this.o,this.f)),Se("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:X(this,this.ma),mouseCollector:X(this,this.oa),keyboardCollector:X(this,this.la),accelerometerCollector:X(this,this.ea),touchCollector:X(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 X(e,t){return function(){t.apply(e,arguments)}}c.random=new c.prng(6);e:try{if(V=typeof B<"u"&&B.exports){try{Z=qe("crypto")}catch{Z=null}V=Y=Z}if(V&&Y.randomBytes)z=Y.randomBytes(128),z=new Uint32Array(new Uint8Array(z).buffer),c.random.addEntropy(z,1024,"crypto['randomBytes']");else if(typeof window<"u"&&typeof Uint32Array<"u"){if(G=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(G);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(G);else break e;c.random.addEntropy(G,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 z,Y,G,V,Z;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 Ee(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 S(e){return this instanceof S?(this.v=e,this):new S(e)}function nt(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,P){i.push([d,y,g,P])>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 S?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 ot(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:S(e[o](s)),done:o==="return"}:i?i(s):s}:i}}function it(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=e[Symbol.asyncIterator],r;return t?t.call(e):(e=typeof Ee=="function"?Ee(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 v=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 O(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 O(r?r(o):o)}}))}static combine(t){return st(t)}static combineWithAllErrors(t){return ct(t)}map(t){return new e(this._promise.then(r=>T(this,void 0,void 0,function*(){return r.isErr()?new O(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 O(r.error);let n=yield t(r.value);return n.isErr()?new O(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 O(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 O(yield t(r.error))})))}andThen(t){return new e(this._promise.then(r=>{if(r.isErr())return new O(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 nt(this,arguments,function*(){return yield S(yield S(yield*ot(it(yield S(this._promise.then(r=>r.safeUnwrap()))))))})}then(t,r){return this._promise.then(t,r)}},x=e=>new v(Promise.resolve(new L(e))),E=e=>new v(Promise.resolve(new O(e))),Nt=v.fromPromise,Ut=v.fromSafePromise,Bt=v.fromThrowable,Le=e=>{let t=C([]);for(let r of e)if(r.isErr()){t=k(r.error);break}else t.map(n=>n.push(r.value));return t},st=e=>v.fromSafePromise(Promise.all(e)).andThen(Le),Oe=e=>{let t=C([]);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},ct=e=>v.fromSafePromise(Promise.all(e)).andThen(Oe),ee;(function(e){function t(o,i){return(...s)=>{try{let a=o(...s);return C(a)}catch(a){return k(i?i(a):a)}}}e.fromThrowable=t;function r(o){return Le(o)}e.combine=r;function n(o){return Oe(o)}e.combineWithAllErrors=n})(ee||(ee={}));var C=e=>new L(e);function k(e){return new O(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 v.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 Ae("Called `_unsafeUnwrapErr` on an Ok",this,t)}},O=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 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 k(t),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(t){throw Ae("Called `_unsafeUnwrap` on an Err",this,t)}_unsafeUnwrapErr(t){return this.error}},jt=ee.fromThrowable;var D=class extends Error{context;constructor(t,r={}){let{cause:n,context:o}=r;super(t,{cause:n}),this.name=this.constructor.name,this.context=o}};var R=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 at=()=>typeof Deno<"u",I=e=>at()?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 ke.default,w,xe=!1;self.onmessage=e=>{ut(e),xe||(xe=!0,m.once("OPERATION_FAILED",()=>{w&&w.terminate()}))};var N=(e,t)=>(Object.assign(e,t),typeof WorkerGlobalScope<"u"&&self.postMessage({event:"FILE_UPDATED",lufiFile:e}),e);var ut=(e,t)=>{let{action:r}=e.data;switch(r){case 0:w=new Worker(I("cancel"),{type:"module"}),w.postMessage(e.data);break;case 1:w=new Worker(I("download"),{type:"module"}),w.postMessage(e.data);break;case 2:w=new Worker(I("infos"),{type:"module"}),w.postMessage(e.data);break;case 4:w=w||new Worker(I("remove"),{type:"module"}),w.postMessage(e.data);break;case 5:{w=w||new Worker(I("upload"),{type:"module"}),w.postMessage(e.data);break}default:console.error("Action not found")}w.onmessage=n=>{t&&t(n),self.postMessage(n.data)},w.onerror=n=>{console.error(`Error: ${n.message}`)}},De=()=>{m.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),m.once("OPERATION_FAILED",e=>{self.postMessage({event:"OPERATION_FAILED",error:e})})};var b=class extends D{};var W=class extends b{message="An error occured while trying to connect to WebSocket"};var U=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 ht=new U("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");function J(e){return ht.Decode(e)}var lt=new U("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",!0);function te(e){return lt.Decode(e)}var Te=ae(Pe());var _=class extends D{};var j=class extends _{message="Unable to decrypt the provided data"};var Ie=(e,t)=>{try{let r=typeof t=="string"?t:t.data;return x(J(Te.default.decrypt(e,r)))}catch(r){return E(new j(void 0,{cause:R(r)}))}};var Ne=(e,t)=>mt(e).andThen(r=>v.fromPromise(crypto.subtle.decrypt({name:"AES-GCM",iv:t.iv},r,J(t.data)),n=>new j(void 0,{cause:R(n)})));var mt=e=>v.fromPromise(crypto.subtle.importKey("raw",te(e),{name:"AES-GCM"},!1,["encrypt","decrypt"]),t=>new _("Unable to import cryptography key",{cause:R(t)}));var Ue=(e,t)=>t.algo===void 0||t.algo===0?Ie(e,t):Ne(e,t);var A={},Be=5,vt=e=>(m.emit("UPLOAD_CANCELLED",e.success),x(void 0)),wt=(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))),Ue(t.keys.client,s).andThen(a=>{let f=typeof a=="string"?new TextEncoder().encode(a).buffer:a;return o.part===0?(N(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")):N(t,{chunksReady:t.chunksReady+1}),m.emit("CHUNK_DOWNLOADED",f,o.part),++o.part===o.total?Ot(t).andThen(()=>(m.emit("DOWNLOAD_COMPLETE"),m.emit("SOCKET_OPERATION_TERMINATED"),x(void 0))):x(void 0)})}else{let s=new b("Can't retrieve metadata from data received by the server");return m.emit("OPERATION_FAILED",s),E(s)}}else{let i=new b(o.msg);return m.emit("OPERATION_FAILED",i),E(i)}}else{let o=new b("Can't retrieve metadata from data received by the server");return m.emit("OPERATION_FAILED",o),E(o)}},Et=(e,t)=>{if(e.success)return e.j===0&&(N(t,{keys:{client:t.keys.client,server:e.short},actionToken:e.token,queueIndex:e.i}),m.emit("UPLOAD_STARTED")),N(t,{chunksReady:t.chunksReady+1,createdAt:e.created_at}),m.emit("CHUNK_UPLOADED"),t.chunksReady===t.totalChunks&&(N(t,{uploadStatus:1}),m.emit("UPLOAD_COMPLETE"),m.emit("SOCKET_OPERATION_TERMINATED")),x(void 0);{let r=new b(e.msg);return m.emit("OPERATION_FAILED",r),E(r)}},At=(e,t)=>{let r=Dt(e.data),n;if(r)if(!r.action&&r.msg){let o=new b(r.msg);return m.emit("OPERATION_FAILED",o),E(o)}else"delay"in r?n=Et(r,t):n=vt(r);else n=wt(e.data,t);return n},Lt=e=>A!==void 0&&A[e]!==void 0&&A[e].readyState===WebSocket.CONNECTING,oe=e=>A!==void 0&&A[e]!==void 0&&A[e].readyState===WebSocket.OPEN,je=e=>ie(kt(e),e,`${JSON.stringify({id:e.keys.server,mod_token:e.actionToken,cancel:!0,i:e.queueIndex})}XXMOJOXXuseless`);var Ot=e=>{let t;return e.password?t={ended:!0,file_pwd:e.password}:t={ended:!0},ie(bt(e),e,JSON.stringify(t))};var ie=(e,t,r)=>oe(e)?(A[e].onmessage=n=>At(n,t),A[e].send(r),x(void 0)):We(e).andThen(()=>ie(e,t,r)),We=(e,t=0)=>(!oe(e)&&!Lt(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<=Be?(console.error(`An error happened while trying to connect to WebSocket ${e}. Trying again. ${t} / ${Be}`),We(e,t)):(m.emit("SOCKET_ONERROR"),E(new W(`Unable to connect to WebSocket ${e}.`)))),xt(e).andThen(()=>x(e)).orElse(r=>E(r))),xt=e=>v.fromPromise(new Promise((t,r)=>{oe(e)?t(void 0):(m.once("SOCKET_OPENED",()=>{t(void 0)}),m.on("SOCKET_ONERROR",()=>{r(new W)}))}),t=>R(t));var Je=(e,t)=>{let r=new URL(e);return r.protocol=r.protocol==="http:"?"ws:":"wss:",r.pathname+=t,r},bt=e=>Je(new URL(e.serverUrl),"download"+`/${e.keys.server}`).toString(),kt=e=>Je(new URL(e.serverUrl),"upload").toString(),Dt=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 Fe=!1;self.onmessage=e=>{Fe||(De(),Fe=!0),m.on("UPLOAD_CANCELLED",t=>{self.postMessage({event:"UPLOAD_CANCELLED",success:t})}),St(e.data).mapErr(t=>{self.postMessage({event:"OPERATION_FAILED",error:t})})};var St=e=>je(e.args.lufiFile); +var Xe=Object.create;var se=Object.defineProperty;var ze=Object.getOwnPropertyDescriptor;var Ge=Object.getOwnPropertyNames;var $e=Object.getPrototypeOf,Ke=Object.prototype.hasOwnProperty;var qe=(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 ce=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var He=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ge(t))!Ke.call(e,o)&&o!==r&&se(e,o,{get:()=>t[o],enumerable:!(n=ze(t,o))||n.enumerable});return e};var ae=(e,t,r)=>(r=e!=null?Xe($e(e)):{},He(t||!e||!e.__esModule?se(r,"default",{value:e,enumerable:!0}):r,e));var we=ce((Mt,Q)=>{"use strict";var M=typeof Reflect=="object"?Reflect:null,fe=M&&typeof M.apply=="function"?M.apply:function(t,r,n){return Function.prototype.apply.call(t,r,n)},q;M&&typeof M.ownKeys=="function"?q=M.ownKeys:Object.getOwnPropertySymbols?q=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:q=function(t){return Object.getOwnPropertyNames(t)};function Ye(e){console&&console.warn&&console.warn(e)}var he=Number.isNaN||function(t){return t!==t};function p(){p.init.call(this)}Q.exports=p;Q.exports.once=et;p.EventEmitter=p;p.prototype._events=void 0;p.prototype._eventsCount=0;p.prototype._maxListeners=void 0;var ue=10;function H(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 ue},set:function(e){if(typeof e!="number"||e<0||he(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");ue=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||he(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 le(e){return e._maxListeners===void 0?p.defaultMaxListeners:e._maxListeners}p.prototype.getMaxListeners=function(){return le(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")fe(f,this,r);else for(var u=f.length,l=ge(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,Ye(a)}return e}p.prototype.addListener=function(t,r){return de(this,t,r,!1)};p.prototype.on=p.prototype.addListener;p.prototype.prependListener=function(t,r){return de(this,t,r,!0)};function Ve(){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 pe(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},o=Ve.bind(n);return o.listener=r,n.wrapFn=o,o}p.prototype.once=function(t,r){return H(r),this.on(t,pe(this,t,r)),this};p.prototype.prependOnceListener=function(t,r){return H(r),this.prependListener(t,pe(this,t,r)),this};p.prototype.removeListener=function(t,r){var n,o,i,s,a;if(H(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():Ze(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 me(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?Qe(o):ge(o,o.length)}p.prototype.listeners=function(t){return me(this,t,!0)};p.prototype.rawListeners=function(t){return me(this,t,!1)};p.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):ye.call(e,t)};p.prototype.listenerCount=ye;function ye(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?q(this._events):[]};function ge(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 Se(this,e,0)},decrypt:function(e){return Se(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 Se(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],P=a[2],$=a[3],K=a[4];for(h=0;h>>24]^g[i>>16&255]^P[s>>8&255]^$[t&255]^n[d],f=e[i>>>24]^g[s>>16&255]^P[t>>8&255]^$[o&255]^n[d+1],u=e[s>>>24]^g[t>>16&255]^P[o>>8&255]^$[i&255]^n[d+2],t=e[t>>>24]^g[o>>16&255]^P[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]=K[o>>>24]<<24^K[i>>16&255]<<16^K[s>>8&255]<<8^K[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 re(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&&Ce("seeded",Math.max(this.o,this.f)),Ce("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:X(this,this.ma),mouseCollector:X(this,this.oa),keyboardCollector:X(this,this.la),accelerometerCollector:X(this,this.ea),touchCollector:X(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 X(e,t){return function(){t.apply(e,arguments)}}c.random=new c.prng(6);e:try{if(V=typeof j<"u"&&j.exports){try{Z=qe("crypto")}catch{Z=null}V=Y=Z}if(V&&Y.randomBytes)z=Y.randomBytes(128),z=new Uint32Array(new Uint8Array(z).buffer),c.random.addEntropy(z,1024,"crypto['randomBytes']");else if(typeof window<"u"&&typeof Uint32Array<"u"){if(G=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(G);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(G);else break e;c.random.addEntropy(G,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 z,Y,G,V,Z;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 Ee(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 C(e){return this instanceof C?(this.v=e,this):new C(e)}function nt(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,P){i.push([d,y,g,P])>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 C?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 ot(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:C(e[o](s)),done:o==="return"}:i?i(s):s}:i}}function it(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=e[Symbol.asyncIterator],r;return t?t.call(e):(e=typeof Ee=="function"?Ee(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 v=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 O(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 O(r?r(o):o)}}))}static combine(t){return st(t)}static combineWithAllErrors(t){return ct(t)}map(t){return new e(this._promise.then(r=>T(this,void 0,void 0,function*(){return r.isErr()?new O(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 O(r.error);let n=yield t(r.value);return n.isErr()?new O(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 O(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 O(yield t(r.error))})))}andThen(t){return new e(this._promise.then(r=>{if(r.isErr())return new O(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 nt(this,arguments,function*(){return yield C(yield C(yield*ot(it(yield C(this._promise.then(r=>r.safeUnwrap()))))))})}then(t,r){return this._promise.then(t,r)}},x=e=>new v(Promise.resolve(new L(e))),E=e=>new v(Promise.resolve(new O(e))),Nt=v.fromPromise,Ut=v.fromSafePromise,jt=v.fromThrowable,Le=e=>{let t=S([]);for(let r of e)if(r.isErr()){t=k(r.error);break}else t.map(n=>n.push(r.value));return t},st=e=>v.fromSafePromise(Promise.all(e)).andThen(Le),Oe=e=>{let t=S([]);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},ct=e=>v.fromSafePromise(Promise.all(e)).andThen(Oe),ee;(function(e){function t(o,i){return(...s)=>{try{let a=o(...s);return S(a)}catch(a){return k(i?i(a):a)}}}e.fromThrowable=t;function r(o){return Le(o)}e.combine=r;function n(o){return Oe(o)}e.combineWithAllErrors=n})(ee||(ee={}));var S=e=>new L(e);function k(e){return new O(e)}var L=class{constructor(t){this.value=t}isOk(){return!0}isErr(){return!this.isOk()}map(t){return S(t(this.value))}mapErr(t){return S(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 S(this.value)}orElse(t){return S(this.value)}asyncAndThen(t){return t(this.value)}asyncAndThrough(t){return t(this.value).map(()=>this.value)}asyncMap(t){return v.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 Ae("Called `_unsafeUnwrapErr` on an Ok",this,t)}},O=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 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 k(t),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(t){throw Ae("Called `_unsafeUnwrap` on an Err",this,t)}_unsafeUnwrapErr(t){return this.error}},Bt=ee.fromThrowable;var D=class extends Error{context;constructor(t,r={}){let{cause:n,context:o}=r;super(t,{cause:n}),this.name=this.constructor.name,this.context=o}};var R=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 at=()=>typeof Deno<"u",I=e=>at()?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 ke.default,w,xe=!1;self.onmessage=e=>{ut(e),xe||(xe=!0,m.once("OPERATION_FAILED",()=>{w&&w.terminate()}))};var N=(e,t)=>(Object.assign(e,t),typeof WorkerGlobalScope<"u"&&self.postMessage({event:"FILE_UPDATED",lufiFile:e}),e);var ut=(e,t)=>{let{action:r}=e.data;switch(r){case 0:w=new Worker(I("cancel"),{type:"module"}),w.postMessage(e.data);break;case 1:w=new Worker(I("download"),{type:"module"}),w.postMessage(e.data);break;case 2:w=new Worker(I("infos"),{type:"module"}),w.postMessage(e.data);break;case 4:w=w||new Worker(I("remove"),{type:"module"}),w.postMessage(e.data);break;case 5:{w=w||new Worker(I("upload"),{type:"module"}),w.postMessage(e.data);break}default:console.error("Action not found")}w.onmessage=n=>{t&&t(n),self.postMessage(n.data)},w.onerror=n=>{console.error(`Error: ${n.message}`)}},De=()=>{m.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),m.once("OPERATION_FAILED",e=>{self.postMessage({event:"OPERATION_FAILED",error:e})})};var b=class extends D{};var W=class extends b{message="An error occured while trying to connect to WebSocket"};var U=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 ht=new U("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");function J(e){return ht.Decode(e)}var lt=new U("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",!0);function te(e){return lt.Decode(e)}var Te=ae(Pe());var _=class extends D{};var B=class extends _{message="Unable to decrypt the provided data"};var Ie=(e,t)=>{try{let r=typeof t=="string"?t:t.data;return x(J(Te.default.decrypt(e,r)))}catch(r){return E(new B(void 0,{cause:R(r)}))}};var Ne=(e,t)=>mt(e).andThen(r=>v.fromPromise(crypto.subtle.decrypt({name:"AES-GCM",iv:t.iv},r,J(t.data)),n=>new B(void 0,{cause:R(n)})));var mt=e=>v.fromPromise(crypto.subtle.importKey("raw",te(e),{name:"AES-GCM"},!1,["encrypt","decrypt"]),t=>new _("Unable to import cryptography key",{cause:R(t)}));var Ue=(e,t)=>t.algo===void 0||t.algo===0?Ie(e,t):Ne(e,t);var A={},je=5,vt=e=>(m.emit("UPLOAD_CANCELLED",e.success),x(void 0)),wt=(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))),Ue(t.keys.client,s).andThen(a=>{let f=typeof a=="string"?new TextEncoder().encode(a).buffer:a;return o.part===0?(N(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")):N(t,{chunksReady:t.chunksReady+1}),m.emit("CHUNK_DOWNLOADED",f,o.part),++o.part===o.total?Ot(t).andThen(()=>(m.emit("DOWNLOAD_COMPLETE"),m.emit("SOCKET_OPERATION_TERMINATED"),x(void 0))):x(void 0)})}else{let s=new b("Can't retrieve metadata from data received by the server");return m.emit("OPERATION_FAILED",s),E(s)}}else{let i=new b(o.msg);return m.emit("OPERATION_FAILED",i),E(i)}}else{let o=new b("Can't retrieve metadata from data received by the server");return m.emit("OPERATION_FAILED",o),E(o)}},Et=(e,t)=>{if(e.success)return e.j===0&&(N(t,{keys:{client:t.keys.client,server:e.short},actionToken:e.token,queueIndex:e.i}),m.emit("UPLOAD_STARTED")),N(t,{chunksReady:t.chunksReady+1,createdAt:e.created_at}),m.emit("CHUNK_UPLOADED"),t.chunksReady===t.totalChunks&&(N(t,{uploadStatus:1}),m.emit("UPLOAD_COMPLETE"),m.emit("SOCKET_OPERATION_TERMINATED")),x(void 0);{let r=new b(e.msg);return m.emit("OPERATION_FAILED",r),E(r)}},At=(e,t)=>{let r=Dt(e.data),n;if(r)if(!r.action&&r.msg){let o=new b(r.msg);return m.emit("OPERATION_FAILED",o),E(o)}else"delay"in r?n=Et(r,t):n=vt(r);else n=wt(e.data,t);return n},Lt=e=>A!==void 0&&A[e]!==void 0&&A[e].readyState===WebSocket.CONNECTING,oe=e=>A!==void 0&&A[e]!==void 0&&A[e].readyState===WebSocket.OPEN,Be=e=>ie(kt(e),e,`${JSON.stringify({id:e.keys.server,mod_token:e.actionToken,cancel:!0,i:e.queueIndex})}XXMOJOXXuseless`);var Ot=e=>{let t;return e.password?t={ended:!0,file_pwd:e.password}:t={ended:!0},ie(bt(e),e,JSON.stringify(t))};var ie=(e,t,r)=>oe(e)?(A[e].onmessage=n=>At(n,t),A[e].send(r),x(void 0)):We(e).andThen(()=>ie(e,t,r)),We=(e,t=0)=>(!oe(e)&&!Lt(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}`),We(e,t)):(m.emit("SOCKET_ONERROR"),E(new W(`Unable to connect to WebSocket ${e}.`)))),xt(e).andThen(()=>x(e)).orElse(r=>E(r))),xt=e=>v.fromPromise(new Promise((t,r)=>{oe(e)?t(void 0):(m.once("SOCKET_OPENED",()=>{t(void 0)}),m.on("SOCKET_ONERROR",()=>{r(new W)}))}),t=>R(t));var Je=(e,t)=>{let r=new URL(e);return r.protocol=r.protocol==="http:"?"ws:":"wss:",r.pathname+=t,r},bt=e=>Je(new URL(e.serverUrl),"download"+`/${e.keys.server}`).toString(),kt=e=>Je(new URL(e.serverUrl),"upload").toString(),Dt=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 Fe=!1;self.onmessage=e=>{Fe||(De(),Fe=!0),m.on("UPLOAD_CANCELLED",t=>{self.postMessage({event:"UPLOAD_CANCELLED",success:t})}),Ct(e.data).mapErr(t=>{self.postMessage({event:"OPERATION_FAILED",error:t})})};var Ct=e=>Be(e.args.lufiFile); diff --git a/themes/default/public/js/worker/encrypt.js b/themes/default/public/js/worker/encrypt.js index 4a66aee..1ddf039 100644 --- a/themes/default/public/js/worker/encrypt.js +++ b/themes/default/public/js/worker/encrypt.js @@ -1 +1 @@ -var Me=Object.create;var ee=Object.defineProperty;var Re=Object.getOwnPropertyDescriptor;var Be=Object.getOwnPropertyNames;var Ie=Object.getPrototypeOf,je=Object.prototype.hasOwnProperty;var Te=(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 te=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var Ue=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Be(e))!je.call(t,o)&&o!==r&&ee(t,o,{get:()=>e[o],enumerable:!(n=Re(e,o))||n.enumerable});return t};var re=(t,e,r)=>(r=t!=null?Me(Ie(t)):{},Ue(e||!t||!t.__esModule?ee(r,"default",{value:t,enumerable:!0}):r,t));var he=te((Lt,S)=>{"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 ae(this,t,0)},decrypt:function(t){return ae(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 ae(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],_=a[2],N=a[3],W=a[4];for(h=0;h>>24]^y[i>>16&255]^_[s>>8&255]^N[e&255]^n[p],f=t[i>>>24]^y[s>>16&255]^_[e>>8&255]^N[o&255]^n[p+1],u=t[s>>>24]^y[e>>16&255]^_[o>>8&255]^N[i&255]^n[p+2],e=t[e>>>24]^y[o>>16&255]^_[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 X(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&&fe("seeded",Math.max(this.o,this.f)),fe("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:j(this,this.ma),mouseCollector:j(this,this.oa),keyboardCollector:j(this,this.la),accelerometerCollector:j(this,this.ea),touchCollector:j(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 j(t,e){return function(){e.apply(t,arguments)}}c.random=new c.prng(6);e:try{if(G=typeof S<"u"&&S.exports){try{J=Te("crypto")}catch{J=null}G=K=J}if(G&&K.randomBytes)T=K.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(U=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(U);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(U);else break e;c.random.addEntropy(U,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,K,U,G,J;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 R=typeof Reflect=="object"?Reflect:null,ge=R&&typeof R.apply=="function"?R.apply:function(e,r,n){return Function.prototype.apply.call(e,r,n)},q;R&&typeof R.ownKeys=="function"?q=R.ownKeys:Object.getOwnPropertySymbols?q=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:q=function(e){return Object.getOwnPropertyNames(e)};function et(t){console&&console.warn&&console.warn(t)}var we=Number.isNaN||function(e){return e!==e};function d(){d.init.call(this)}Z.exports=d;Z.exports.once=ot;d.EventEmitter=d;d.prototype._events=void 0;d.prototype._eventsCount=0;d.prototype._maxListeners=void 0;var ve=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 ve},set:function(t){if(typeof t!="number"||t<0||we(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");ve=t}});d.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0};d.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||we(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 Ee(t){return t._maxListeners===void 0?d.defaultMaxListeners:t._maxListeners}d.prototype.getMaxListeners=function(){return Ee(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")ge(f,this,r);else for(var u=f.length,l=ke(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,et(a)}return t}d.prototype.addListener=function(e,r){return Ae(this,e,r,!1)};d.prototype.on=d.prototype.addListener;d.prototype.prependListener=function(e,r){return Ae(this,e,r,!0)};function tt(){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 xe(t,e,r){var n={fired:!1,wrapFn:void 0,target:t,type:e,listener:r},o=tt.bind(n);return o.listener=r,n.wrapFn=o,o}d.prototype.once=function(e,r){return $(r),this.on(e,xe(this,e,r)),this};d.prototype.prependOnceListener=function(e,r){return $(r),this.prependListener(e,xe(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():rt(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 Le(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?nt(o):ke(o,o.length)}d.prototype.listeners=function(e){return Le(this,e,!0)};d.prototype.rawListeners=function(e){return Le(this,e,!1)};d.listenerCount=function(t,e){return typeof t.listenerCount=="function"?t.listenerCount(e):be.call(t,e)};d.prototype.listenerCount=be;function be(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 ke(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 Ne=new D("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");function B(t){return Ne.Encode(t)}var We=new D("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",!0);function Y(t){return We.Decode(t)}var Ke={withStackTrace:!1},ie=(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 C(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 oe(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 b(t){return this instanceof b?(this.v=t,this):new b(t)}function Ge(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,_){i.push([p,m,y,_])>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 b?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 Je(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:b(t[o](s)),done:o==="return"}:i?i(s):s}:i}}function ze(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 oe=="function"?oe(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(C(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 qe(e)}static combineWithAllErrors(e){return $e(e)}map(e){return new t(this._promise.then(r=>C(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=>C(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=>C(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=>C(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=>C(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 Ge(this,arguments,function*(){return yield b(yield b(yield*Je(ze(yield b(this._promise.then(r=>r.safeUnwrap()))))))})}then(e,r){return this._promise.then(e,r)}},F=t=>new v(Promise.resolve(new w(t))),k=t=>new v(Promise.resolve(new E(t))),vt=v.fromPromise,wt=v.fromSafePromise,Et=v.fromThrowable,se=t=>{let e=L([]);for(let r of t)if(r.isErr()){e=A(r.error);break}else e.map(n=>n.push(r.value));return e},qe=t=>v.fromSafePromise(Promise.all(t)).andThen(se),ce=t=>{let e=L([]);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},$e=t=>v.fromSafePromise(Promise.all(t)).andThen(ce),H;(function(t){function e(o,i){return(...s)=>{try{let a=o(...s);return L(a)}catch(a){return A(i?i(a):a)}}}t.fromThrowable=e;function r(o){return se(o)}t.combine=r;function n(o){return ce(o)}t.combineWithAllErrors=n})(H||(H={}));var L=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 L(e(this.value))}mapErr(e){return L(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 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 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 ie("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 k(this.error)}asyncAndThrough(e){return k(this.error)}asyncMap(e){return k(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 ie("Called `_unsafeUnwrap` on an Err",this,e)}_unsafeUnwrapErr(e){return this.error}},At=H.fromThrowable;var pe=re(he());var P=class extends Error{context;constructor(e,r={}){let{cause:n,context:o}=r;super(e,{cause:n}),this.name=this.constructor.name,this.context=o}};var x=class extends P{};var z=class extends x{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 Ye=()=>typeof Deno<"u",M=t=>Ye()?new URL(`./worker/${t}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${t==="main"?`worker/${t}`:t}.js`));var de=(t,e)=>{try{let r=pe.default.encrypt(t,B(e));return F({algo:0,data:r,iv:JSON.parse(r).iv})}catch(r){return k(new z(void 0,{cause:O(r)}))}};var me=(t,e)=>Ve(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=>F({algo:1,data:B(o),iv:n}))}),Ve=t=>v.fromPromise(crypto.subtle.importKey("raw",Y(t),{name:"AES-GCM"},!1,["encrypt","decrypt"]),e=>new x("Unable to import cryptography key",{cause:O(e)}));var ye=(t,e,r=1)=>{let n;return r===0?n=de(t,e):(typeof e=="string"&&(e=new TextEncoder().encode(e).buffer),n=me(t,e)),n};var Ce=re(_e());var Q=new Ce.default,g,De=!1;self.onmessage=t=>{ct(t),De||(De=!0,Q.once("OPERATION_FAILED",()=>{g&&g.terminate()}))};var ct=(t,e)=>{let{action:r}=t.data;switch(r){case 0:g=new Worker(M("cancel"),{type:"module"}),g.postMessage(t.data);break;case 1:g=new Worker(M("download"),{type:"module"}),g.postMessage(t.data);break;case 2:g=new Worker(M("infos"),{type:"module"}),g.postMessage(t.data);break;case 4:g=g||new Worker(M("remove"),{type:"module"}),g.postMessage(t.data);break;case 5:{g=g||new Worker(M("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}`)}},Se=()=>{Q.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),Q.once("OPERATION_FAILED",t=>{self.postMessage({event:"OPERATION_FAILED",error:t})})};var Pe=!1;self.onmessage=t=>{Pe||(Se(),Pe=!0);let{lufiFile:e,chunk:r}=t.data.args;r?e.uploadStatus!==2?ye(e.keys.client,r.buffer).map(n=>{self.postMessage({encryptedData:n,chunkIndex:r.index})}).mapErr(n=>{self.postMessage({error:n})}):self.postMessage({error:"File upload already failed"}):self.postMessage({error:O("Buffer cannot be undefined")})}; +var Me=Object.create;var ee=Object.defineProperty;var Re=Object.getOwnPropertyDescriptor;var Be=Object.getOwnPropertyNames;var Ie=Object.getPrototypeOf,je=Object.prototype.hasOwnProperty;var Te=(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 te=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var Ue=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Be(e))!je.call(t,o)&&o!==r&&ee(t,o,{get:()=>e[o],enumerable:!(n=Re(e,o))||n.enumerable});return t};var re=(t,e,r)=>(r=t!=null?Me(Ie(t)):{},Ue(e||!t||!t.__esModule?ee(r,"default",{value:t,enumerable:!0}):r,t));var he=te((Lt,S)=>{"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 ae(this,t,0)},decrypt:function(t){return ae(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 ae(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],_=a[2],N=a[3],W=a[4];for(h=0;h>>24]^y[i>>16&255]^_[s>>8&255]^N[e&255]^n[p],f=t[i>>>24]^y[s>>16&255]^_[e>>8&255]^N[o&255]^n[p+1],u=t[s>>>24]^y[e>>16&255]^_[o>>8&255]^N[i&255]^n[p+2],e=t[e>>>24]^y[o>>16&255]^_[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 X(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&&fe("seeded",Math.max(this.o,this.f)),fe("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:j(this,this.ma),mouseCollector:j(this,this.oa),keyboardCollector:j(this,this.la),accelerometerCollector:j(this,this.ea),touchCollector:j(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 j(t,e){return function(){e.apply(t,arguments)}}c.random=new c.prng(6);e:try{if(G=typeof S<"u"&&S.exports){try{J=Te("crypto")}catch{J=null}G=K=J}if(G&&K.randomBytes)T=K.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(U=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(U);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(U);else break e;c.random.addEntropy(U,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,K,U,G,J;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 R=typeof Reflect=="object"?Reflect:null,ge=R&&typeof R.apply=="function"?R.apply:function(e,r,n){return Function.prototype.apply.call(e,r,n)},q;R&&typeof R.ownKeys=="function"?q=R.ownKeys:Object.getOwnPropertySymbols?q=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:q=function(e){return Object.getOwnPropertyNames(e)};function et(t){console&&console.warn&&console.warn(t)}var we=Number.isNaN||function(e){return e!==e};function d(){d.init.call(this)}Z.exports=d;Z.exports.once=ot;d.EventEmitter=d;d.prototype._events=void 0;d.prototype._eventsCount=0;d.prototype._maxListeners=void 0;var ve=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 ve},set:function(t){if(typeof t!="number"||t<0||we(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");ve=t}});d.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0};d.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||we(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 Ee(t){return t._maxListeners===void 0?d.defaultMaxListeners:t._maxListeners}d.prototype.getMaxListeners=function(){return Ee(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")ge(f,this,r);else for(var u=f.length,l=ke(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,et(a)}return t}d.prototype.addListener=function(e,r){return Ae(this,e,r,!1)};d.prototype.on=d.prototype.addListener;d.prototype.prependListener=function(e,r){return Ae(this,e,r,!0)};function tt(){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 xe(t,e,r){var n={fired:!1,wrapFn:void 0,target:t,type:e,listener:r},o=tt.bind(n);return o.listener=r,n.wrapFn=o,o}d.prototype.once=function(e,r){return $(r),this.on(e,xe(this,e,r)),this};d.prototype.prependOnceListener=function(e,r){return $(r),this.prependListener(e,xe(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():rt(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 Le(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?nt(o):ke(o,o.length)}d.prototype.listeners=function(e){return Le(this,e,!0)};d.prototype.rawListeners=function(e){return Le(this,e,!1)};d.listenerCount=function(t,e){return typeof t.listenerCount=="function"?t.listenerCount(e):be.call(t,e)};d.prototype.listenerCount=be;function be(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 ke(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 Ne=new D("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");function B(t){return Ne.Encode(t)}var We=new D("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",!0);function H(t){return We.Decode(t)}var Ke={withStackTrace:!1},ie=(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 C(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 oe(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 b(t){return this instanceof b?(this.v=t,this):new b(t)}function Ge(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,_){i.push([p,m,y,_])>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 b?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 Je(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:b(t[o](s)),done:o==="return"}:i?i(s):s}:i}}function ze(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 oe=="function"?oe(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(C(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 qe(e)}static combineWithAllErrors(e){return $e(e)}map(e){return new t(this._promise.then(r=>C(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=>C(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=>C(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=>C(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=>C(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 Ge(this,arguments,function*(){return yield b(yield b(yield*Je(ze(yield b(this._promise.then(r=>r.safeUnwrap()))))))})}then(e,r){return this._promise.then(e,r)}},F=t=>new v(Promise.resolve(new w(t))),k=t=>new v(Promise.resolve(new E(t))),vt=v.fromPromise,wt=v.fromSafePromise,Et=v.fromThrowable,se=t=>{let e=L([]);for(let r of t)if(r.isErr()){e=A(r.error);break}else e.map(n=>n.push(r.value));return e},qe=t=>v.fromSafePromise(Promise.all(t)).andThen(se),ce=t=>{let e=L([]);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},$e=t=>v.fromSafePromise(Promise.all(t)).andThen(ce),Y;(function(t){function e(o,i){return(...s)=>{try{let a=o(...s);return L(a)}catch(a){return A(i?i(a):a)}}}t.fromThrowable=e;function r(o){return se(o)}t.combine=r;function n(o){return ce(o)}t.combineWithAllErrors=n})(Y||(Y={}));var L=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 L(e(this.value))}mapErr(e){return L(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 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 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 ie("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 k(this.error)}asyncAndThrough(e){return k(this.error)}asyncMap(e){return k(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 ie("Called `_unsafeUnwrap` on an Err",this,e)}_unsafeUnwrapErr(e){return this.error}},At=Y.fromThrowable;var pe=re(he());var P=class extends Error{context;constructor(e,r={}){let{cause:n,context:o}=r;super(e,{cause:n}),this.name=this.constructor.name,this.context=o}};var x=class extends P{};var z=class extends x{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 He=()=>typeof Deno<"u",M=t=>He()?new URL(`./worker/${t}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${t==="main"?`worker/${t}`:t}.js`));var de=(t,e)=>{try{let r=pe.default.encrypt(t,B(e));return F({algo:0,data:r,iv:JSON.parse(r).iv})}catch(r){return k(new z(void 0,{cause:O(r)}))}};var me=(t,e)=>Ve(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=>F({algo:1,data:B(o),iv:n}))}),Ve=t=>v.fromPromise(crypto.subtle.importKey("raw",H(t),{name:"AES-GCM"},!1,["encrypt","decrypt"]),e=>new x("Unable to import cryptography key",{cause:O(e)}));var ye=(t,e,r=1)=>{let n;return r===0?n=de(t,e):(typeof e=="string"&&(e=new TextEncoder().encode(e).buffer),n=me(t,e)),n};var Ce=re(_e());var Q=new Ce.default,g,De=!1;self.onmessage=t=>{ct(t),De||(De=!0,Q.once("OPERATION_FAILED",()=>{g&&g.terminate()}))};var ct=(t,e)=>{let{action:r}=t.data;switch(r){case 0:g=new Worker(M("cancel"),{type:"module"}),g.postMessage(t.data);break;case 1:g=new Worker(M("download"),{type:"module"}),g.postMessage(t.data);break;case 2:g=new Worker(M("infos"),{type:"module"}),g.postMessage(t.data);break;case 4:g=g||new Worker(M("remove"),{type:"module"}),g.postMessage(t.data);break;case 5:{g=g||new Worker(M("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}`)}},Se=()=>{Q.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),Q.once("OPERATION_FAILED",t=>{self.postMessage({event:"OPERATION_FAILED",error:t})})};var Pe=!1;self.onmessage=t=>{Pe||(Se(),Pe=!0);let{lufiFile:e,chunk:r}=t.data.args;r?e.uploadStatus!==2?ye(e.keys.client,r.buffer).map(n=>{self.postMessage({encryptedData:n,chunkIndex:r.index})}).mapErr(n=>{self.postMessage({error:n})}):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 6a0e2d6..bc5664f 100644 --- a/themes/default/public/js/worker/infos.js +++ b/themes/default/public/js/worker/infos.js @@ -1 +1 @@ -var Xe=Object.create;var ce=Object.defineProperty;var ze=Object.getOwnPropertyDescriptor;var Ge=Object.getOwnPropertyNames;var $e=Object.getPrototypeOf,Ke=Object.prototype.hasOwnProperty;var qe=(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 He=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ge(t))!Ke.call(e,o)&&o!==r&&ce(e,o,{get:()=>t[o],enumerable:!(n=ze(t,o))||n.enumerable});return e};var fe=(e,t,r)=>(r=e!=null?Xe($e(e)):{},He(t||!e||!e.__esModule?ce(r,"default",{value:e,enumerable:!0}):r,e));var xe=ae((er,te)=>{"use strict";var I=typeof Reflect=="object"?Reflect:null,pe=I&&typeof I.apply=="function"?I.apply:function(t,r,n){return Function.prototype.apply.call(t,r,n)},q;I&&typeof I.ownKeys=="function"?q=I.ownKeys:Object.getOwnPropertySymbols?q=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:q=function(t){return Object.getOwnPropertyNames(t)};function nt(e){console&&console.warn&&console.warn(e)}var ye=Number.isNaN||function(t){return t!==t};function p(){p.init.call(this)}te.exports=p;te.exports.once=ct;p.EventEmitter=p;p.prototype._events=void 0;p.prototype._eventsCount=0;p.prototype._maxListeners=void 0;var me=10;function H(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 me},set:function(e){if(typeof e!="number"||e<0||ye(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");me=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||ye(t))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+t+".");return this._maxListeners=t,this};function ge(e){return e._maxListeners===void 0?p.defaultMaxListeners:e._maxListeners}p.prototype.getMaxListeners=function(){return ge(this)};p.prototype.emit=function(t){for(var r=[],n=1;n0&&(s=r[0]),s instanceof Error)throw s;var 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")pe(f,this,r);else for(var u=f.length,l=Le(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,nt(a)}return e}p.prototype.addListener=function(t,r){return ve(this,t,r,!1)};p.prototype.on=p.prototype.addListener;p.prototype.prependListener=function(t,r){return ve(this,t,r,!0)};function ot(){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 we(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},o=ot.bind(n);return o.listener=r,n.wrapFn=o,o}p.prototype.once=function(t,r){return H(r),this.on(t,we(this,t,r)),this};p.prototype.prependOnceListener=function(t,r){return H(r),this.prependListener(t,we(this,t,r)),this};p.prototype.removeListener=function(t,r){var n,o,i,s,a;if(H(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():it(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 Ee(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?st(o):Le(o,o.length)}p.prototype.listeners=function(t){return Ee(this,t,!0)};p.prototype.rawListeners=function(t){return Ee(this,t,!1)};p.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):Ae.call(e,t)};p.prototype.listenerCount=Ae;function Ae(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?q(this._events):[]};function Le(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],T=a[2],$=a[3],K=a[4];for(h=0;h>>24]^g[i>>16&255]^T[s>>8&255]^$[t&255]^n[d],f=e[i>>>24]^g[s>>16&255]^T[t>>8&255]^$[o&255]^n[d+1],u=e[s>>>24]^g[t>>16&255]^T[o>>8&255]^$[i&255]^n[d+2],t=e[t>>>24]^g[o>>16&255]^T[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]=K[o>>>24]<<24^K[i>>16&255]<<16^K[s>>8&255]<<8^K[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 ne(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:X(this,this.ma),mouseCollector:X(this,this.oa),keyboardCollector:X(this,this.la),accelerometerCollector:X(this,this.ea),touchCollector:X(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 X(e,t){return function(){t.apply(e,arguments)}}c.random=new c.prng(6);e:try{if(Y=typeof B<"u"&&B.exports){try{Z=qe("crypto")}catch{Z=null}Y=V=Z}if(Y&&V.randomBytes)z=V.randomBytes(128),z=new Uint32Array(new Uint8Array(z).buffer),c.random.addEntropy(z,1024,"crypto['randomBytes']");else if(typeof window<"u"&&typeof Uint32Array<"u"){if(G=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(G);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(G);else break e;c.random.addEntropy(G,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 z,V,G,Y,Z;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 P(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 ue(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 C(e){return this instanceof C?(this.v=e,this):new C(e)}function Ye(e,t,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=r.apply(e,t||[]),o,i=[];return o={},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,T){i.push([d,y,g,T])>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 C?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 Ze(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:C(e[o](s)),done:o==="return"}:i?i(s):s}:i}}function Qe(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 ue=="function"?ue(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 v=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 O(r(o)));return new e(n)}static fromThrowable(t,r){return(...n)=>new e(P(this,void 0,void 0,function*(){try{return new L(yield t(...n))}catch(o){return new O(r?r(o):o)}}))}static combine(t){return et(t)}static combineWithAllErrors(t){return tt(t)}map(t){return new e(this._promise.then(r=>P(this,void 0,void 0,function*(){return r.isErr()?new O(r.error):new L(yield t(r.value))})))}andThrough(t){return new e(this._promise.then(r=>P(this,void 0,void 0,function*(){if(r.isErr())return new O(r.error);let n=yield t(r.value);return n.isErr()?new O(n.error):new L(r.value)})))}andTee(t){return new e(this._promise.then(r=>P(this,void 0,void 0,function*(){if(r.isErr())return new O(r.error);try{yield t(r.value)}catch{}return new L(r.value)})))}mapErr(t){return new e(this._promise.then(r=>P(this,void 0,void 0,function*(){return r.isOk()?new L(r.value):new O(yield t(r.error))})))}andThen(t){return new e(this._promise.then(r=>{if(r.isErr())return new O(r.error);let n=t(r.value);return n instanceof e?n._promise:n}))}orElse(t){return new e(this._promise.then(r=>P(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 Ye(this,arguments,function*(){return yield C(yield C(yield*Ze(Qe(yield C(this._promise.then(r=>r.safeUnwrap()))))))})}then(t,r){return this._promise.then(t,r)}},x=e=>new v(Promise.resolve(new L(e))),E=e=>new v(Promise.resolve(new O(e))),Rt=v.fromPromise,Tt=v.fromSafePromise,Pt=v.fromThrowable,le=e=>{let t=S([]);for(let r of e)if(r.isErr()){t=b(r.error);break}else t.map(n=>n.push(r.value));return t},et=e=>v.fromSafePromise(Promise.all(e)).andThen(le),de=e=>{let t=S([]);for(let r of e)r.isErr()&&t.isErr()?t.error.push(r.error):r.isErr()&&t.isOk()?t=b([r.error]):r.isOk()&&t.isOk()&&t.value.push(r.value);return t},tt=e=>v.fromSafePromise(Promise.all(e)).andThen(de),ee;(function(e){function t(o,i){return(...s)=>{try{let a=o(...s);return S(a)}catch(a){return b(i?i(a):a)}}}e.fromThrowable=t;function r(o){return le(o)}e.combine=r;function n(o){return de(o)}e.combineWithAllErrors=n})(ee||(ee={}));var S=e=>new L(e);function b(e){return new O(e)}var L=class{constructor(t){this.value=t}isOk(){return!0}isErr(){return!this.isOk()}map(t){return S(t(this.value))}mapErr(t){return S(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 S(this.value)}orElse(t){return S(this.value)}asyncAndThen(t){return t(this.value)}asyncAndThrough(t){return t(this.value).map(()=>this.value)}asyncMap(t){return v.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 he("Called `_unsafeUnwrapErr` on an Ok",this,t)}},O=class{constructor(t){this.error=t}isOk(){return!1}isErr(){return!this.isOk()}map(t){return b(this.error)}mapErr(t){return b(t(this.error))}andThrough(t){return b(this.error)}andTee(t){return b(this.error)}andThen(t){return b(this.error)}orElse(t){return t(this.error)}asyncAndThen(t){return 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 b(t),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(t){throw he("Called `_unsafeUnwrap` on an Err",this,t)}_unsafeUnwrapErr(t){return this.error}},Mt=ee.fromThrowable;var D=class extends Error{context;constructor(t,r={}){let{cause:n,context:o}=r;super(t,{cause:n}),this.name=this.constructor.name,this.context=o}};var k=class extends D{};var W=class extends k{message="An error occured while trying to connect to WebSocket"};var R=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 rt=()=>typeof Deno<"u",M=e=>rt()?new URL(`./worker/${e}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${e==="main"?`worker/${e}`:e}.js`));var De=fe(xe());var m=new De.default,w,ke=!1;self.onmessage=e=>{ut(e),ke||(ke=!0,m.once("OPERATION_FAILED",()=>{w&&w.terminate()}))};var N=(e,t)=>(Object.assign(e,t),typeof WorkerGlobalScope<"u"&&self.postMessage({event:"FILE_UPDATED",lufiFile:e}),e);var ut=(e,t)=>{let{action:r}=e.data;switch(r){case 0:w=new Worker(M("cancel"),{type:"module"}),w.postMessage(e.data);break;case 1:w=new Worker(M("download"),{type:"module"}),w.postMessage(e.data);break;case 2:w=new Worker(M("infos"),{type:"module"}),w.postMessage(e.data);break;case 4:w=w||new Worker(M("remove"),{type:"module"}),w.postMessage(e.data);break;case 5:{w=w||new Worker(M("upload"),{type:"module"}),w.postMessage(e.data);break}default:console.error("Action not found")}w.onmessage=n=>{t&&t(n),self.postMessage(n.data)},w.onerror=n=>{console.error(`Error: ${n.message}`)}},_e=()=>{m.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),m.once("OPERATION_FAILED",e=>{self.postMessage({event:"OPERATION_FAILED",error:e})})};var U=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 ht=new U("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");function F(e){return ht.Decode(e)}var lt=new U("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",!0);function re(e){return lt.Decode(e)}var Ie=fe(Pe());var _=class extends D{};var j=class extends _{message="Unable to decrypt the provided data"};var Ne=(e,t)=>{try{let r=typeof t=="string"?t:t.data;return x(F(Ie.default.decrypt(e,r)))}catch(r){return E(new j(void 0,{cause:R(r)}))}};var Ue=(e,t)=>mt(e).andThen(r=>v.fromPromise(crypto.subtle.decrypt({name:"AES-GCM",iv:t.iv},r,F(t.data)),n=>new j(void 0,{cause:R(n)})));var mt=e=>v.fromPromise(crypto.subtle.importKey("raw",re(e),{name:"AES-GCM"},!1,["encrypt","decrypt"]),t=>new _("Unable to import cryptography key",{cause:R(t)}));var Be=(e,t)=>t.algo===void 0||t.algo===0?Ne(e,t):Ue(e,t);var A={},je=5,vt=e=>(m.emit("UPLOAD_CANCELLED",e.success),x(void 0)),wt=(e,t)=>{let r=e.split("XXMOJOXX"),n=r.shift();if(n!==void 0){let o=JSON.parse(n);if(Dt(o)){let i=r.shift();if(i){let s=JSON.parse(i);return s.iv&&(s.iv=new Uint8Array(Object.values(s.iv))),Be(t.keys.client,s).andThen(a=>{let f=typeof a=="string"?new TextEncoder().encode(a).buffer:a;return o.part===0?(N(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")):N(t,{chunksReady:t.chunksReady+1}),m.emit("CHUNK_DOWNLOADED",f,o.part),++o.part===o.total?Ot(t).andThen(()=>(m.emit("DOWNLOAD_COMPLETE"),m.emit("SOCKET_OPERATION_TERMINATED"),x(void 0))):x(void 0)})}else{let s=new k("Can't retrieve metadata from data received by the server");return m.emit("OPERATION_FAILED",s),E(s)}}else{let i=new k(o.msg);return m.emit("OPERATION_FAILED",i),E(i)}}else{let o=new k("Can't retrieve metadata from data received by the server");return m.emit("OPERATION_FAILED",o),E(o)}},Et=(e,t)=>{if(e.success)return e.j===0&&(N(t,{keys:{client:t.keys.client,server:e.short},actionToken:e.token,queueIndex:e.i}),m.emit("UPLOAD_STARTED")),N(t,{chunksReady:t.chunksReady+1,createdAt:e.created_at}),m.emit("CHUNK_UPLOADED"),t.chunksReady===t.totalChunks&&(N(t,{uploadStatus:1}),m.emit("UPLOAD_COMPLETE"),m.emit("SOCKET_OPERATION_TERMINATED")),x(void 0);{let r=new k(e.msg);return m.emit("OPERATION_FAILED",r),E(r)}},At=(e,t)=>{let r=bt(e.data),n;if(r)if(!r.action&&r.msg){let o=new k(r.msg);return m.emit("OPERATION_FAILED",o),E(o)}else"delay"in r?n=Et(r,t):n=vt(r);else n=wt(e.data,t);return n},Lt=e=>A!==void 0&&A[e]!==void 0&&A[e].readyState===WebSocket.CONNECTING,ie=e=>A!==void 0&&A[e]!==void 0&&A[e].readyState===WebSocket.OPEN;var We=(e,t)=>{let r;return e.password?r={part:t,file_pwd:e.password}:r={part:t},se(Q(e),e,JSON.stringify(r))},Ot=e=>{let t;return e.password?t={ended:!0,file_pwd:e.password}:t={ended:!0},se(Q(e),e,JSON.stringify(t))};var se=(e,t,r)=>ie(e)?(A[e].onmessage=n=>At(n,t),A[e].send(r),x(void 0)):Fe(e).andThen(()=>se(e,t,r)),Fe=(e,t=0)=>(!ie(e)&&!Lt(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}`),Fe(e,t)):(m.emit("SOCKET_ONERROR"),E(new W(`Unable to connect to WebSocket ${e}.`)))),xt(e).andThen(()=>x(e)).orElse(r=>E(r))),xt=e=>v.fromPromise(new Promise((t,r)=>{ie(e)?t(void 0):(m.once("SOCKET_OPENED",()=>{t(void 0)}),m.on("SOCKET_ONERROR",()=>{r(new W)}))}),t=>R(t));var kt=(e,t)=>{let r=new URL(e);return r.protocol=r.protocol==="http:"?"ws:":"wss:",r.pathname+=t,r},Q=e=>kt(new URL(e.serverUrl),"download"+`/${e.keys.server}`).toString();var bt=e=>{try{let t=JSON.parse(e);if(t&&typeof t=="object")return t}catch{}return!1},Dt=e=>typeof e=="object"&&e!==null&&!("msg"in e);var Je=!1;self.onmessage=e=>{Je||(_e(),Je=!0),m.on("DOWNLOAD_STARTED",()=>{A[Q(e.data.args.lufiFile)].close(),self.postMessage({event:"INFOS_RETRIEVED"})}),St(e.data).mapErr(t=>{self.postMessage({event:"OPERATION_FAILED",error:t})})};var St=e=>We(e.args.lufiFile,0); +var Xe=Object.create;var ce=Object.defineProperty;var ze=Object.getOwnPropertyDescriptor;var Ge=Object.getOwnPropertyNames;var $e=Object.getPrototypeOf,Ke=Object.prototype.hasOwnProperty;var qe=(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 He=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ge(t))!Ke.call(e,o)&&o!==r&&ce(e,o,{get:()=>t[o],enumerable:!(n=ze(t,o))||n.enumerable});return e};var fe=(e,t,r)=>(r=e!=null?Xe($e(e)):{},He(t||!e||!e.__esModule?ce(r,"default",{value:e,enumerable:!0}):r,e));var xe=ae((er,te)=>{"use strict";var I=typeof Reflect=="object"?Reflect:null,pe=I&&typeof I.apply=="function"?I.apply:function(t,r,n){return Function.prototype.apply.call(t,r,n)},q;I&&typeof I.ownKeys=="function"?q=I.ownKeys:Object.getOwnPropertySymbols?q=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:q=function(t){return Object.getOwnPropertyNames(t)};function nt(e){console&&console.warn&&console.warn(e)}var ye=Number.isNaN||function(t){return t!==t};function p(){p.init.call(this)}te.exports=p;te.exports.once=ct;p.EventEmitter=p;p.prototype._events=void 0;p.prototype._eventsCount=0;p.prototype._maxListeners=void 0;var me=10;function H(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 me},set:function(e){if(typeof e!="number"||e<0||ye(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");me=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||ye(t))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+t+".");return this._maxListeners=t,this};function ge(e){return e._maxListeners===void 0?p.defaultMaxListeners:e._maxListeners}p.prototype.getMaxListeners=function(){return ge(this)};p.prototype.emit=function(t){for(var r=[],n=1;n0&&(s=r[0]),s instanceof Error)throw s;var 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")pe(f,this,r);else for(var u=f.length,l=Le(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,nt(a)}return e}p.prototype.addListener=function(t,r){return ve(this,t,r,!1)};p.prototype.on=p.prototype.addListener;p.prototype.prependListener=function(t,r){return ve(this,t,r,!0)};function ot(){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 we(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},o=ot.bind(n);return o.listener=r,n.wrapFn=o,o}p.prototype.once=function(t,r){return H(r),this.on(t,we(this,t,r)),this};p.prototype.prependOnceListener=function(t,r){return H(r),this.prependListener(t,we(this,t,r)),this};p.prototype.removeListener=function(t,r){var n,o,i,s,a;if(H(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():it(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 Ee(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?st(o):Le(o,o.length)}p.prototype.listeners=function(t){return Ee(this,t,!0)};p.prototype.rawListeners=function(t){return Ee(this,t,!1)};p.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):Ae.call(e,t)};p.prototype.listenerCount=Ae;function Ae(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?q(this._events):[]};function Le(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],P=a[2],$=a[3],K=a[4];for(h=0;h>>24]^g[i>>16&255]^P[s>>8&255]^$[t&255]^n[d],f=e[i>>>24]^g[s>>16&255]^P[t>>8&255]^$[o&255]^n[d+1],u=e[s>>>24]^g[t>>16&255]^P[o>>8&255]^$[i&255]^n[d+2],t=e[t>>>24]^g[o>>16&255]^P[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]=K[o>>>24]<<24^K[i>>16&255]<<16^K[s>>8&255]<<8^K[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 ne(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:X(this,this.ma),mouseCollector:X(this,this.oa),keyboardCollector:X(this,this.la),accelerometerCollector:X(this,this.ea),touchCollector:X(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 X(e,t){return function(){t.apply(e,arguments)}}c.random=new c.prng(6);e:try{if(Y=typeof j<"u"&&j.exports){try{Z=qe("crypto")}catch{Z=null}Y=V=Z}if(Y&&V.randomBytes)z=V.randomBytes(128),z=new Uint32Array(new Uint8Array(z).buffer),c.random.addEntropy(z,1024,"crypto['randomBytes']");else if(typeof window<"u"&&typeof Uint32Array<"u"){if(G=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(G);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(G);else break e;c.random.addEntropy(G,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 z,V,G,Y,Z;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 ue(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 C(e){return this instanceof C?(this.v=e,this):new C(e)}function Ye(e,t,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=r.apply(e,t||[]),o,i=[];return o={},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,P){i.push([d,y,g,P])>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 C?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 Ze(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:C(e[o](s)),done:o==="return"}:i?i(s):s}:i}}function Qe(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 ue=="function"?ue(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 v=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 O(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 O(r?r(o):o)}}))}static combine(t){return et(t)}static combineWithAllErrors(t){return tt(t)}map(t){return new e(this._promise.then(r=>T(this,void 0,void 0,function*(){return r.isErr()?new O(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 O(r.error);let n=yield t(r.value);return n.isErr()?new O(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 O(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 O(yield t(r.error))})))}andThen(t){return new e(this._promise.then(r=>{if(r.isErr())return new O(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 Ye(this,arguments,function*(){return yield C(yield C(yield*Ze(Qe(yield C(this._promise.then(r=>r.safeUnwrap()))))))})}then(t,r){return this._promise.then(t,r)}},x=e=>new v(Promise.resolve(new L(e))),E=e=>new v(Promise.resolve(new O(e))),Rt=v.fromPromise,Pt=v.fromSafePromise,Tt=v.fromThrowable,le=e=>{let t=S([]);for(let r of e)if(r.isErr()){t=k(r.error);break}else t.map(n=>n.push(r.value));return t},et=e=>v.fromSafePromise(Promise.all(e)).andThen(le),de=e=>{let t=S([]);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},tt=e=>v.fromSafePromise(Promise.all(e)).andThen(de),ee;(function(e){function t(o,i){return(...s)=>{try{let a=o(...s);return S(a)}catch(a){return k(i?i(a):a)}}}e.fromThrowable=t;function r(o){return le(o)}e.combine=r;function n(o){return de(o)}e.combineWithAllErrors=n})(ee||(ee={}));var S=e=>new L(e);function k(e){return new O(e)}var L=class{constructor(t){this.value=t}isOk(){return!0}isErr(){return!this.isOk()}map(t){return S(t(this.value))}mapErr(t){return S(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 S(this.value)}orElse(t){return S(this.value)}asyncAndThen(t){return t(this.value)}asyncAndThrough(t){return t(this.value).map(()=>this.value)}asyncMap(t){return v.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 he("Called `_unsafeUnwrapErr` on an Ok",this,t)}},O=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 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 k(t),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(t){throw he("Called `_unsafeUnwrap` on an Err",this,t)}_unsafeUnwrapErr(t){return this.error}},Mt=ee.fromThrowable;var D=class extends Error{context;constructor(t,r={}){let{cause:n,context:o}=r;super(t,{cause:n}),this.name=this.constructor.name,this.context=o}};var b=class extends D{};var W=class extends b{message="An error occured while trying to connect to WebSocket"};var R=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 rt=()=>typeof Deno<"u",M=e=>rt()?new URL(`./worker/${e}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${e==="main"?`worker/${e}`:e}.js`));var De=fe(xe());var m=new De.default,w,be=!1;self.onmessage=e=>{ut(e),be||(be=!0,m.once("OPERATION_FAILED",()=>{w&&w.terminate()}))};var N=(e,t)=>(Object.assign(e,t),typeof WorkerGlobalScope<"u"&&self.postMessage({event:"FILE_UPDATED",lufiFile:e}),e);var ut=(e,t)=>{let{action:r}=e.data;switch(r){case 0:w=new Worker(M("cancel"),{type:"module"}),w.postMessage(e.data);break;case 1:w=new Worker(M("download"),{type:"module"}),w.postMessage(e.data);break;case 2:w=new Worker(M("infos"),{type:"module"}),w.postMessage(e.data);break;case 4:w=w||new Worker(M("remove"),{type:"module"}),w.postMessage(e.data);break;case 5:{w=w||new Worker(M("upload"),{type:"module"}),w.postMessage(e.data);break}default:console.error("Action not found")}w.onmessage=n=>{t&&t(n),self.postMessage(n.data)},w.onerror=n=>{console.error(`Error: ${n.message}`)}},_e=()=>{m.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),m.once("OPERATION_FAILED",e=>{self.postMessage({event:"OPERATION_FAILED",error:e})})};var U=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 ht=new U("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");function F(e){return ht.Decode(e)}var lt=new U("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",!0);function re(e){return lt.Decode(e)}var Ie=fe(Te());var _=class extends D{};var B=class extends _{message="Unable to decrypt the provided data"};var Ne=(e,t)=>{try{let r=typeof t=="string"?t:t.data;return x(F(Ie.default.decrypt(e,r)))}catch(r){return E(new B(void 0,{cause:R(r)}))}};var Ue=(e,t)=>mt(e).andThen(r=>v.fromPromise(crypto.subtle.decrypt({name:"AES-GCM",iv:t.iv},r,F(t.data)),n=>new B(void 0,{cause:R(n)})));var mt=e=>v.fromPromise(crypto.subtle.importKey("raw",re(e),{name:"AES-GCM"},!1,["encrypt","decrypt"]),t=>new _("Unable to import cryptography key",{cause:R(t)}));var je=(e,t)=>t.algo===void 0||t.algo===0?Ne(e,t):Ue(e,t);var A={},Be=5,vt=e=>(m.emit("UPLOAD_CANCELLED",e.success),x(void 0)),wt=(e,t)=>{let r=e.split("XXMOJOXX"),n=r.shift();if(n!==void 0){let o=JSON.parse(n);if(Dt(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?(N(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")):N(t,{chunksReady:t.chunksReady+1}),m.emit("CHUNK_DOWNLOADED",f,o.part),++o.part===o.total?Ot(t).andThen(()=>(m.emit("DOWNLOAD_COMPLETE"),m.emit("SOCKET_OPERATION_TERMINATED"),x(void 0))):x(void 0)})}else{let s=new b("Can't retrieve metadata from data received by the server");return m.emit("OPERATION_FAILED",s),E(s)}}else{let i=new b(o.msg);return m.emit("OPERATION_FAILED",i),E(i)}}else{let o=new b("Can't retrieve metadata from data received by the server");return m.emit("OPERATION_FAILED",o),E(o)}},Et=(e,t)=>{if(e.success)return e.j===0&&(N(t,{keys:{client:t.keys.client,server:e.short},actionToken:e.token,queueIndex:e.i}),m.emit("UPLOAD_STARTED")),N(t,{chunksReady:t.chunksReady+1,createdAt:e.created_at}),m.emit("CHUNK_UPLOADED"),t.chunksReady===t.totalChunks&&(N(t,{uploadStatus:1}),m.emit("UPLOAD_COMPLETE"),m.emit("SOCKET_OPERATION_TERMINATED")),x(void 0);{let r=new b(e.msg);return m.emit("OPERATION_FAILED",r),E(r)}},At=(e,t)=>{let r=kt(e.data),n;if(r)if(!r.action&&r.msg){let o=new b(r.msg);return m.emit("OPERATION_FAILED",o),E(o)}else"delay"in r?n=Et(r,t):n=vt(r);else n=wt(e.data,t);return n},Lt=e=>A!==void 0&&A[e]!==void 0&&A[e].readyState===WebSocket.CONNECTING,ie=e=>A!==void 0&&A[e]!==void 0&&A[e].readyState===WebSocket.OPEN;var We=(e,t)=>{let r;return e.password?r={part:t,file_pwd:e.password}:r={part:t},se(Q(e),e,JSON.stringify(r))},Ot=e=>{let t;return e.password?t={ended:!0,file_pwd:e.password}:t={ended:!0},se(Q(e),e,JSON.stringify(t))};var se=(e,t,r)=>ie(e)?(A[e].onmessage=n=>At(n,t),A[e].send(r),x(void 0)):Fe(e).andThen(()=>se(e,t,r)),Fe=(e,t=0)=>(!ie(e)&&!Lt(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<=Be?(console.error(`An error happened while trying to connect to WebSocket ${e}. Trying again. ${t} / ${Be}`),Fe(e,t)):(m.emit("SOCKET_ONERROR"),E(new W(`Unable to connect to WebSocket ${e}.`)))),xt(e).andThen(()=>x(e)).orElse(r=>E(r))),xt=e=>v.fromPromise(new Promise((t,r)=>{ie(e)?t(void 0):(m.once("SOCKET_OPENED",()=>{t(void 0)}),m.on("SOCKET_ONERROR",()=>{r(new W)}))}),t=>R(t));var bt=(e,t)=>{let r=new URL(e);return r.protocol=r.protocol==="http:"?"ws:":"wss:",r.pathname+=t,r},Q=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},Dt=e=>typeof e=="object"&&e!==null&&!("msg"in e);var Je=!1;self.onmessage=e=>{Je||(_e(),Je=!0),m.on("DOWNLOAD_STARTED",()=>{A[Q(e.data.args.lufiFile)].close(),self.postMessage({event:"INFOS_RETRIEVED"})}),St(e.data).mapErr(t=>{self.postMessage({event:"OPERATION_FAILED",error:t})})};var St=e=>We(e.args.lufiFile,0); diff --git a/themes/default/public/js/worker/main.js b/themes/default/public/js/worker/main.js index 90b0984..3cdbc18 100644 --- a/themes/default/public/js/worker/main.js +++ b/themes/default/public/js/worker/main.js @@ -1 +1 @@ -var Y=Object.create;var C=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var ee=Object.getOwnPropertyNames;var re=Object.getPrototypeOf,te=Object.prototype.hasOwnProperty;var ne=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var oe=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ee(e))!te.call(r,o)&&o!==t&&C(r,o,{get:()=>e[o],enumerable:!(n=V(e,o))||n.enumerable});return r};var ie=(r,e,t)=>(t=r!=null?Y(re(r)):{},oe(e||!r||!r.__esModule?C(t,"default",{value:r,enumerable:!0}):t,r));var $=ne((ge,k)=>{"use strict";var O=typeof Reflect=="object"?Reflect:null,R=O&&typeof O.apply=="function"?O.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)},D;O&&typeof O.ownKeys=="function"?D=O.ownKeys:Object.getOwnPropertySymbols?D=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:D=function(e){return Object.getOwnPropertyNames(e)};function se(r){console&&console.warn&&console.warn(r)}var F=Number.isNaN||function(e){return e!==e};function u(){u.init.call(this)}k.exports=u;k.exports.once=ce;u.EventEmitter=u;u.prototype._events=void 0;u.prototype._eventsCount=0;u.prototype._maxListeners=void 0;var N=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(u,"defaultMaxListeners",{enumerable:!0,get:function(){return N},set:function(r){if(typeof r!="number"||r<0||F(r))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+r+".");N=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||F(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 S(r){return r._maxListeners===void 0?u.defaultMaxListeners:r._maxListeners}u.prototype.getMaxListeners=function(){return S(this)};u.prototype.emit=function(e){for(var t=[],n=1;n0&&(i=t[0]),i instanceof Error)throw i;var a=new Error("Unhandled error."+(i?" ("+i.message+")":""));throw a.context=i,a}var l=s[e];if(l===void 0)return!1;if(typeof l=="function")R(l,this,t);else for(var d=l.length,p=K(l,d),n=0;n0&&i.length>o&&!i.warned){i.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+i.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning",a.emitter=r,a.type=e,a.count=i.length,se(a)}return r}u.prototype.addListener=function(e,t){return U(this,e,t,!1)};u.prototype.on=u.prototype.addListener;u.prototype.prependListener=function(e,t){return U(this,e,t,!0)};function ue(){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=ue.bind(n);return o.listener=t,n.wrapFn=o,o}u.prototype.once=function(e,t){return A(t),this.on(e,W(this,e,t)),this};u.prototype.prependOnceListener=function(e,t){return A(t),this.prependListener(e,W(this,e,t)),this};u.prototype.removeListener=function(e,t){var n,o,s,i,a;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){a=n[i].listener,s=i;break}if(s<0)return this;s===0?n.shift():ae(n,s),n.length===1&&(o[e]=n[0]),o.removeListener!==void 0&&this.emit("removeListener",e,a||t)}return this};u.prototype.off=u.prototype.removeListener;u.prototype.removeAllListeners=function(e){var t,n,o;if(n=this._events,n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[e]),this;if(arguments.length===0){var s=Object.keys(n),i;for(o=0;o=0;o--)this.removeListener(e,t[o]);return this};function 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?fe(o):K(o,o.length)}u.prototype.listeners=function(e){return j(this,e,!0)};u.prototype.rawListeners=function(e){return j(this,e,!1)};u.listenerCount=function(r,e){return typeof r.listenerCount=="function"?r.listenerCount(e):J.call(r,e)};u.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}u.prototype.eventNames=function(){return this._eventsCount>0?D(this._events):[]};function K(r,e){for(var t=new Array(e),n=0;n(i[i.CANCEL=0]="CANCEL",i[i.DOWNLOAD=1]="DOWNLOAD",i[i.INFOS=2]="INFOS",i[i.PROVIDE_FILE=3]="PROVIDE_FILE",i[i.REMOVE=4]="REMOVE",i[i.UPLOAD=5]="UPLOAD",i))(I||{});var he={withStackTrace:!1},G=(r,e,t=he)=>{let n=e.isOk()?{type:"Ok",value:e.value}:{type:"Err",value:e.error},o=t.withStackTrace?new Error().stack:void 0;return{data:n,message:r,stack:o}};function g(r,e,t,n){function o(s){return s instanceof t?s:new t(function(i){i(s)})}return new(t||(t=Promise))(function(s,i){function a(p){try{d(n.next(p))}catch(L){i(L)}}function l(p){try{d(n.throw(p))}catch(L){i(L)}}function d(p){p.done?s(p.value):o(p.value).then(a,l)}d((n=n.apply(r,[])).next())})}function B(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 pe(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(f){n[f]&&(o[f]=function(_){return new Promise(function(P,X){s.push([f,_,P,X])>1||a(f,_)})})}function a(f,_){try{l(n[f](_))}catch(P){L(s[0][3],P)}}function l(f){f.value instanceof E?Promise.resolve(f.value.v).then(d,p):L(s[0][2],f)}function d(f){a("next",f)}function p(f){a("throw",f)}function L(f,_){f(_),s.shift(),s.length&&a(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:E(r[o](i)),done:o==="return"}:s?s(i):i}:s}}function de(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 B=="function"?B(r):r[Symbol.iterator](),t={},n("next"),n("throw"),n("return"),t[Symbol.asyncIterator]=function(){return this},t);function n(s){t[s]=r[s]&&function(i){return new Promise(function(a,l){i=r[s](i),o(a,l,i.done,i.value)})}}function o(s,i,a,l){Promise.resolve(l).then(function(d){s({value:d,done:a})},i)}}var v=class r{constructor(e){this._promise=e}static fromSafePromise(e){let t=e.then(n=>new m(n));return new r(t)}static fromPromise(e,t){let n=e.then(o=>new m(o)).catch(o=>new h(t(o)));return new r(n)}static fromThrowable(e,t){return(...n)=>new r(g(this,void 0,void 0,function*(){try{return new m(yield e(...n))}catch(o){return new h(t?t(o):o)}}))}static combine(e){return ve(e)}static combineWithAllErrors(e){return we(e)}map(e){return new r(this._promise.then(t=>g(this,void 0,void 0,function*(){return t.isErr()?new h(t.error):new m(yield e(t.value))})))}andThrough(e){return new r(this._promise.then(t=>g(this,void 0,void 0,function*(){if(t.isErr())return new h(t.error);let n=yield e(t.value);return n.isErr()?new h(n.error):new m(t.value)})))}andTee(e){return new r(this._promise.then(t=>g(this,void 0,void 0,function*(){if(t.isErr())return new h(t.error);try{yield e(t.value)}catch{}return new m(t.value)})))}mapErr(e){return new r(this._promise.then(t=>g(this,void 0,void 0,function*(){return t.isOk()?new m(t.value):new 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=>g(this,void 0,void 0,function*(){return t.isErr()?e(t.error):new m(t.value)})))}match(e,t){return this._promise.then(n=>n.match(e,t))}unwrapOr(e){return this._promise.then(t=>t.unwrapOr(e))}safeUnwrap(){return pe(this,arguments,function*(){return yield E(yield E(yield*me(de(yield E(this._promise.then(t=>t.safeUnwrap()))))))})}then(e,t){return this._promise.then(e,t)}};var x=r=>new v(Promise.resolve(new h(r))),xe=v.fromPromise,Pe=v.fromSafePromise,ke=v.fromThrowable,q=r=>{let e=y([]);for(let t of r)if(t.isErr()){e=w(t.error);break}else e.map(n=>n.push(t.value));return e},ve=r=>v.fromSafePromise(Promise.all(r)).andThen(q),z=r=>{let e=y([]);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},we=r=>v.fromSafePromise(Promise.all(r)).andThen(z),M;(function(r){function e(o,s){return(...i)=>{try{let a=o(...i);return y(a)}catch(a){return w(s?s(a):a)}}}r.fromThrowable=e;function t(o){return q(o)}r.combine=t;function n(o){return z(o)}r.combineWithAllErrors=n})(M||(M={}));var y=r=>new m(r);function w(r){return new h(r)}var m=class{constructor(e){this.value=e}isOk(){return!0}isErr(){return!this.isOk()}map(e){return y(e(this.value))}mapErr(e){return y(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 y(this.value)}orElse(e){return y(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 G("Called `_unsafeUnwrapErr` on an Ok",this,e)}},h=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 x(this.error)}asyncAndThrough(e){return x(this.error)}asyncMap(e){return x(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 G("Called `_unsafeUnwrap` on an Err",this,e)}_unsafeUnwrapErr(e){return this.error}},Ie=M.fromThrowable;var Ee=()=>typeof Deno<"u",b=r=>Ee()?new URL(`./worker/${r}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${r==="main"?`worker/${r}`:r}.js`));var T=new Z.default,c,Q=!1;self.onmessage=r=>{_e(r),Q||(Q=!0,T.once("OPERATION_FAILED",()=>{c&&c.terminate()}))};var Le=(r,e)=>(Object.assign(r,e),typeof WorkerGlobalScope<"u"&&self.postMessage({event:"FILE_UPDATED",lufiFile:r}),r),Qe=(r,e)=>{Le(r,{uploadStatus:2}),self.postMessage({event:"OPERATION_FAILED",error:e})},_e=(r,e)=>{let{action:t}=r.data;switch(t){case 0:c=new Worker(b("cancel"),{type:"module"}),c.postMessage(r.data);break;case 1:c=new Worker(b("download"),{type:"module"}),c.postMessage(r.data);break;case 2:c=new Worker(b("infos"),{type:"module"}),c.postMessage(r.data);break;case 4:c=c||new Worker(b("remove"),{type:"module"}),c.postMessage(r.data);break;case 5:{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}`)}},Ze=()=>{T.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),T.once("OPERATION_FAILED",r=>{self.postMessage({event:"OPERATION_FAILED",error:r})})},Xe=r=>typeof r=="object"&&r!==null&&"action"in r&&Object.values(I).includes(r.action);export{T as events,Ze as init,Xe as isWorkerActionMessage,Qe as sendFileError,Le as updateFile}; +var Y=Object.create;var C=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var ee=Object.getOwnPropertyNames;var re=Object.getPrototypeOf,te=Object.prototype.hasOwnProperty;var ne=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var oe=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ee(e))!te.call(r,o)&&o!==t&&C(r,o,{get:()=>e[o],enumerable:!(n=V(e,o))||n.enumerable});return r};var ie=(r,e,t)=>(t=r!=null?Y(re(r)):{},oe(e||!r||!r.__esModule?C(t,"default",{value:r,enumerable:!0}):t,r));var $=ne((Oe,k)=>{"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)},D;g&&typeof g.ownKeys=="function"?D=g.ownKeys:Object.getOwnPropertySymbols?D=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:D=function(e){return Object.getOwnPropertyNames(e)};function se(r){console&&console.warn&&console.warn(r)}var N=Number.isNaN||function(e){return e!==e};function u(){u.init.call(this)}k.exports=u;k.exports.once=ce;u.EventEmitter=u;u.prototype._events=void 0;u.prototype._eventsCount=0;u.prototype._maxListeners=void 0;var S=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(u,"defaultMaxListeners",{enumerable:!0,get:function(){return S},set:function(r){if(typeof r!="number"||r<0||N(r))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+r+".");S=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||N(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 F(r){return r._maxListeners===void 0?u.defaultMaxListeners:r._maxListeners}u.prototype.getMaxListeners=function(){return F(this)};u.prototype.emit=function(e){for(var t=[],n=1;n0&&(i=t[0]),i instanceof Error)throw i;var a=new Error("Unhandled error."+(i?" ("+i.message+")":""));throw a.context=i,a}var l=s[e];if(l===void 0)return!1;if(typeof l=="function")R(l,this,t);else for(var d=l.length,p=H(l,d),n=0;n0&&i.length>o&&!i.warned){i.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+i.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning",a.emitter=r,a.type=e,a.count=i.length,se(a)}return r}u.prototype.addListener=function(e,t){return U(this,e,t,!1)};u.prototype.on=u.prototype.addListener;u.prototype.prependListener=function(e,t){return U(this,e,t,!0)};function ue(){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=ue.bind(n);return o.listener=t,n.wrapFn=o,o}u.prototype.once=function(e,t){return A(t),this.on(e,W(this,e,t)),this};u.prototype.prependOnceListener=function(e,t){return A(t),this.prependListener(e,W(this,e,t)),this};u.prototype.removeListener=function(e,t){var n,o,s,i,a;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){a=n[i].listener,s=i;break}if(s<0)return this;s===0?n.shift():ae(n,s),n.length===1&&(o[e]=n[0]),o.removeListener!==void 0&&this.emit("removeListener",e,a||t)}return this};u.prototype.off=u.prototype.removeListener;u.prototype.removeAllListeners=function(e){var t,n,o;if(n=this._events,n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[e]),this;if(arguments.length===0){var s=Object.keys(n),i;for(o=0;o=0;o--)this.removeListener(e,t[o]);return this};function 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?fe(o):H(o,o.length)}u.prototype.listeners=function(e){return j(this,e,!0)};u.prototype.rawListeners=function(e){return j(this,e,!1)};u.listenerCount=function(r,e){return typeof r.listenerCount=="function"?r.listenerCount(e):J.call(r,e)};u.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}u.prototype.eventNames=function(){return this._eventsCount>0?D(this._events):[]};function H(r,e){for(var t=new Array(e),n=0;n(i[i.CANCEL=0]="CANCEL",i[i.DOWNLOAD=1]="DOWNLOAD",i[i.INFOS=2]="INFOS",i[i.PROVIDE_FILE=3]="PROVIDE_FILE",i[i.REMOVE=4]="REMOVE",i[i.UPLOAD=5]="UPLOAD",i))(M||{});var he={withStackTrace:!1},G=(r,e,t=he)=>{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 O(r,e,t,n){function o(s){return s instanceof t?s:new t(function(i){i(s)})}return new(t||(t=Promise))(function(s,i){function a(p){try{d(n.next(p))}catch(L){i(L)}}function l(p){try{d(n.throw(p))}catch(L){i(L)}}function d(p){p.done?s(p.value):o(p.value).then(a,l)}d((n=n.apply(r,[])).next())})}function B(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 pe(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(f){n[f]&&(o[f]=function(_){return new Promise(function(P,X){s.push([f,_,P,X])>1||a(f,_)})})}function a(f,_){try{l(n[f](_))}catch(P){L(s[0][3],P)}}function l(f){f.value instanceof E?Promise.resolve(f.value.v).then(d,p):L(s[0][2],f)}function d(f){a("next",f)}function p(f){a("throw",f)}function L(f,_){f(_),s.shift(),s.length&&a(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:E(r[o](i)),done:o==="return"}:s?s(i):i}:s}}function de(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 B=="function"?B(r):r[Symbol.iterator](),t={},n("next"),n("throw"),n("return"),t[Symbol.asyncIterator]=function(){return this},t);function n(s){t[s]=r[s]&&function(i){return new Promise(function(a,l){i=r[s](i),o(a,l,i.done,i.value)})}}function o(s,i,a,l){Promise.resolve(l).then(function(d){s({value:d,done:a})},i)}}var v=class r{constructor(e){this._promise=e}static fromSafePromise(e){let t=e.then(n=>new m(n));return new r(t)}static fromPromise(e,t){let n=e.then(o=>new m(o)).catch(o=>new h(t(o)));return new r(n)}static fromThrowable(e,t){return(...n)=>new r(O(this,void 0,void 0,function*(){try{return new m(yield e(...n))}catch(o){return new h(t?t(o):o)}}))}static combine(e){return ve(e)}static combineWithAllErrors(e){return we(e)}map(e){return new r(this._promise.then(t=>O(this,void 0,void 0,function*(){return t.isErr()?new h(t.error):new m(yield e(t.value))})))}andThrough(e){return new r(this._promise.then(t=>O(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 m(t.value)})))}andTee(e){return new r(this._promise.then(t=>O(this,void 0,void 0,function*(){if(t.isErr())return new h(t.error);try{yield e(t.value)}catch{}return new m(t.value)})))}mapErr(e){return new r(this._promise.then(t=>O(this,void 0,void 0,function*(){return t.isOk()?new m(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=>O(this,void 0,void 0,function*(){return t.isErr()?e(t.error):new m(t.value)})))}match(e,t){return this._promise.then(n=>n.match(e,t))}unwrapOr(e){return this._promise.then(t=>t.unwrapOr(e))}safeUnwrap(){return pe(this,arguments,function*(){return yield E(yield E(yield*me(de(yield E(this._promise.then(t=>t.safeUnwrap()))))))})}then(e,t){return this._promise.then(e,t)}};var x=r=>new v(Promise.resolve(new h(r))),xe=v.fromPromise,Pe=v.fromSafePromise,ke=v.fromThrowable,q=r=>{let e=y([]);for(let t of r)if(t.isErr()){e=w(t.error);break}else e.map(n=>n.push(t.value));return e},ve=r=>v.fromSafePromise(Promise.all(r)).andThen(q),z=r=>{let e=y([]);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},we=r=>v.fromSafePromise(Promise.all(r)).andThen(z),I;(function(r){function e(o,s){return(...i)=>{try{let a=o(...i);return y(a)}catch(a){return w(s?s(a):a)}}}r.fromThrowable=e;function t(o){return q(o)}r.combine=t;function n(o){return z(o)}r.combineWithAllErrors=n})(I||(I={}));var y=r=>new m(r);function w(r){return new h(r)}var m=class{constructor(e){this.value=e}isOk(){return!0}isErr(){return!this.isOk()}map(e){return y(e(this.value))}mapErr(e){return y(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 y(this.value)}orElse(e){return y(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 G("Called `_unsafeUnwrapErr` on an Ok",this,e)}},h=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 x(this.error)}asyncAndThrough(e){return x(this.error)}asyncMap(e){return x(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 G("Called `_unsafeUnwrap` on an Err",this,e)}_unsafeUnwrapErr(e){return this.error}},Me=I.fromThrowable;var Ee=()=>typeof Deno<"u",b=r=>Ee()?new URL(`./worker/${r}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${r==="main"?`worker/${r}`:r}.js`));var T=new Z.default,c,Q=!1;self.onmessage=r=>{_e(r),Q||(Q=!0,T.once("OPERATION_FAILED",()=>{c&&c.terminate()}))};var Le=(r,e)=>(Object.assign(r,e),typeof WorkerGlobalScope<"u"&&self.postMessage({event:"FILE_UPDATED",lufiFile:r}),r),Qe=(r,e)=>{Le(r,{uploadStatus:2}),self.postMessage({event:"OPERATION_FAILED",error:e})},_e=(r,e)=>{let{action:t}=r.data;switch(t){case 0:c=new Worker(b("cancel"),{type:"module"}),c.postMessage(r.data);break;case 1:c=new Worker(b("download"),{type:"module"}),c.postMessage(r.data);break;case 2:c=new Worker(b("infos"),{type:"module"}),c.postMessage(r.data);break;case 4:c=c||new Worker(b("remove"),{type:"module"}),c.postMessage(r.data);break;case 5:{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}`)}},Ze=()=>{T.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),T.once("OPERATION_FAILED",r=>{self.postMessage({event:"OPERATION_FAILED",error:r})})},Xe=r=>typeof r=="object"&&r!==null&&"action"in r&&Object.values(M).includes(r.action);export{T as events,Ze as init,Xe as isWorkerActionMessage,Qe as sendFileError,Le as updateFile}; diff --git a/themes/default/public/js/worker/remove.js b/themes/default/public/js/worker/remove.js index fea2fe3..9075416 100644 --- a/themes/default/public/js/worker/remove.js +++ b/themes/default/public/js/worker/remove.js @@ -1 +1 @@ -var ee=Object.create;var T=Object.defineProperty;var re=Object.getOwnPropertyDescriptor;var te=Object.getOwnPropertyNames;var ne=Object.getPrototypeOf,oe=Object.prototype.hasOwnProperty;var se=(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 te(e))!oe.call(r,o)&&o!==t&&T(r,o,{get:()=>e[o],enumerable:!(n=re(e,o))||n.enumerable});return r};var ue=(r,e,t)=>(t=r!=null?ee(ne(r)):{},ie(e||!r||!r.__esModule?T(t,"default",{value:r,enumerable:!0}):t,r));var Q=se((Ke,M)=>{"use strict";var b=typeof Reflect=="object"?Reflect:null,S=b&&typeof b.apply=="function"?b.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)},A;b&&typeof b.ownKeys=="function"?A=b.ownKeys:Object.getOwnPropertySymbols?A=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:A=function(e){return Object.getOwnPropertyNames(e)};function ve(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=Le;u.EventEmitter=u;u.prototype._events=void 0;u.prototype._eventsCount=0;u.prototype._maxListeners=void 0;var U=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 U},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+".");U=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 J(r){return r._maxListeners===void 0?u.defaultMaxListeners:r._maxListeners}u.prototype.getMaxListeners=function(){return J(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")S(l,this,t);else for(var v=l.length,m=G(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,ve(a)}return r}u.prototype.addListener=function(e,t){return $(this,e,t,!1)};u.prototype.on=u.prototype.addListener;u.prototype.prependListener=function(e,t){return $(this,e,t,!0)};function Ee(){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 K(r,e,t){var n={fired:!1,wrapFn:void 0,target:r,type:e,listener:t},o=Ee.bind(n);return o.listener=t,n.wrapFn=o,o}u.prototype.once=function(e,t){return k(t),this.on(e,K(this,e,t)),this};u.prototype.prependOnceListener=function(e,t){return k(t),this.prependListener(e,K(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():we(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 H(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?ye(o):G(o,o.length)}u.prototype.listeners=function(e){return H(this,e,!0)};u.prototype.rawListeners=function(e){return H(this,e,!1)};u.listenerCount=function(r,e){return typeof r.listenerCount=="function"?r.listenerCount(e):B.call(r,e)};u.prototype.listenerCount=B;function B(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 G(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 g(r,e,t,n){function o(i){return i instanceof t?i:new t(function(s){s(i)})}return new(t||(t=Promise))(function(i,s){function 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 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 y(r){return this instanceof y?(this.v=r,this):new y(r)}function fe(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(f){n[f]&&(o[f]=function(_){return new Promise(function(P,V){i.push([f,_,P,V])>1||a(f,_)})})}function a(f,_){try{l(n[f](_))}catch(P){L(i[0][3],P)}}function l(f){f.value instanceof y?Promise.resolve(f.value.v).then(v,m):L(i[0][2],f)}function v(f){a("next",f)}function m(f){a("throw",f)}function L(f,_){f(_),i.shift(),i.length&&a(i[0][0],i[0][1])}}function ce(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 le(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(g(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 he(e)}static combineWithAllErrors(e){return pe(e)}map(e){return new r(this._promise.then(t=>g(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=>g(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=>g(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=>g(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=>g(this,void 0,void 0,function*(){return t.isErr()?e(t.error):new d(t.value)})))}match(e,t){return this._promise.then(n=>n.match(e,t))}unwrapOr(e){return this._promise.then(t=>t.unwrapOr(e))}safeUnwrap(){return fe(this,arguments,function*(){return yield y(yield y(yield*ce(le(yield y(this._promise.then(t=>t.safeUnwrap()))))))})}then(e,t){return this._promise.then(e,t)}};var D=r=>new p(Promise.resolve(new h(r))),ke=p.fromPromise,Pe=p.fromSafePromise,xe=p.fromThrowable,F=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},he=r=>p.fromSafePromise(Promise.all(r)).andThen(F),N=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},pe=r=>p.fromSafePromise(Promise.all(r)).andThen(N),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 F(o)}r.combine=t;function n(o){return N(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 C("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 D(this.error)}asyncAndThrough(e){return D(this.error)}asyncMap(e){return D(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 C("Called `_unsafeUnwrap` on an Err",this,e)}_unsafeUnwrapErr(e){return this.error}},Me=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 de=()=>typeof Deno<"u",O=r=>de()?new URL(`./worker/${r}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${r==="main"?`worker/${r}`:r}.js`));var q=ue(Q());var I=new q.default,c,Z=!1;self.onmessage=r=>{Oe(r),Z||(Z=!0,I.once("OPERATION_FAILED",()=>{c&&c.terminate()}))};var Oe=(r,e)=>{let{action:t}=r.data;switch(t){case 0:c=new Worker(O("cancel"),{type:"module"}),c.postMessage(r.data);break;case 1:c=new Worker(O("download"),{type:"module"}),c.postMessage(r.data);break;case 2:c=new Worker(O("infos"),{type:"module"}),c.postMessage(r.data);break;case 4:c=c||new Worker(O("remove"),{type:"module"}),c.postMessage(r.data);break;case 5:{c=c||new Worker(O("upload"),{type:"module"}),c.postMessage(r.data);break}default:console.error("Action not found")}c.onmessage=n=>{e&&e(n),self.postMessage(n.data)},c.onerror=n=>{console.error(`Error: ${n.message}`)}},X=()=>{I.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),I.once("OPERATION_FAILED",r=>{self.postMessage({event:"OPERATION_FAILED",error:r})})};var Y=!1;self.onmessage=r=>{Y||(X(),Y=!0),be(r.data).map(()=>{self.postMessage({event:"FILE_REMOVED"})}).mapErr(e=>{self.postMessage({event:"OPERATION_FAILED",error:e})})};var be=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)); +var ee=Object.create;var T=Object.defineProperty;var re=Object.getOwnPropertyDescriptor;var te=Object.getOwnPropertyNames;var ne=Object.getPrototypeOf,oe=Object.prototype.hasOwnProperty;var se=(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 te(e))!oe.call(r,o)&&o!==t&&T(r,o,{get:()=>e[o],enumerable:!(n=re(e,o))||n.enumerable});return r};var ue=(r,e,t)=>(t=r!=null?ee(ne(r)):{},ie(e||!r||!r.__esModule?T(t,"default",{value:r,enumerable:!0}):t,r));var Q=se((He,M)=>{"use strict";var b=typeof Reflect=="object"?Reflect:null,W=b&&typeof b.apply=="function"?b.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)},A;b&&typeof b.ownKeys=="function"?A=b.ownKeys:Object.getOwnPropertySymbols?A=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:A=function(e){return Object.getOwnPropertyNames(e)};function ve(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=Le;u.EventEmitter=u;u.prototype._events=void 0;u.prototype._eventsCount=0;u.prototype._maxListeners=void 0;var U=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 U},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+".");U=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 J(r){return r._maxListeners===void 0?u.defaultMaxListeners:r._maxListeners}u.prototype.getMaxListeners=function(){return J(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")W(l,this,t);else for(var v=l.length,m=G(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,ve(a)}return r}u.prototype.addListener=function(e,t){return $(this,e,t,!1)};u.prototype.on=u.prototype.addListener;u.prototype.prependListener=function(e,t){return $(this,e,t,!0)};function ye(){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 H(r,e,t){var n={fired:!1,wrapFn:void 0,target:r,type:e,listener:t},o=ye.bind(n);return o.listener=t,n.wrapFn=o,o}u.prototype.once=function(e,t){return k(t),this.on(e,H(this,e,t)),this};u.prototype.prependOnceListener=function(e,t){return k(t),this.prependListener(e,H(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():Ee(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 K(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?we(o):G(o,o.length)}u.prototype.listeners=function(e){return K(this,e,!0)};u.prototype.rawListeners=function(e){return K(this,e,!1)};u.listenerCount=function(r,e){return typeof r.listenerCount=="function"?r.listenerCount(e):B.call(r,e)};u.prototype.listenerCount=B;function B(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 G(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 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 w(r){return this instanceof w?(this.v=r,this):new w(r)}function fe(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(f){n[f]&&(o[f]=function(g){return new Promise(function(P,V){i.push([f,g,P,V])>1||a(f,g)})})}function a(f,g){try{l(n[f](g))}catch(P){L(i[0][3],P)}}function l(f){f.value instanceof w?Promise.resolve(f.value.v).then(v,m):L(i[0][2],f)}function v(f){a("next",f)}function m(f){a("throw",f)}function L(f,g){f(g),i.shift(),i.length&&a(i[0][0],i[0][1])}}function ce(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:w(r[o](s)),done:o==="return"}:i?i(s):s}:i}}function le(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 he(e)}static combineWithAllErrors(e){return pe(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 fe(this,arguments,function*(){return yield w(yield w(yield*ce(le(yield w(this._promise.then(t=>t.safeUnwrap()))))))})}then(e,t){return this._promise.then(e,t)}};var D=r=>new p(Promise.resolve(new h(r))),ke=p.fromPromise,Pe=p.fromSafePromise,xe=p.fromThrowable,F=r=>{let e=E([]);for(let t of r)if(t.isErr()){e=y(t.error);break}else e.map(n=>n.push(t.value));return e},he=r=>p.fromSafePromise(Promise.all(r)).andThen(F),N=r=>{let e=E([]);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},pe=r=>p.fromSafePromise(Promise.all(r)).andThen(N),x;(function(r){function e(o,i){return(...s)=>{try{let a=o(...s);return E(a)}catch(a){return y(i?i(a):a)}}}r.fromThrowable=e;function t(o){return F(o)}r.combine=t;function n(o){return N(o)}r.combineWithAllErrors=n})(x||(x={}));var E=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 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 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 C("Called `_unsafeUnwrapErr` on an Ok",this,e)}},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 D(this.error)}asyncAndThrough(e){return D(this.error)}asyncMap(e){return D(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 C("Called `_unsafeUnwrap` on an Err",this,e)}_unsafeUnwrapErr(e){return this.error}},Me=x.fromThrowable;var S=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 de=()=>typeof Deno<"u",O=r=>de()?new URL(`./worker/${r}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${r==="main"?`worker/${r}`:r}.js`));var q=ue(Q());var I=new q.default,c,Z=!1;self.onmessage=r=>{Oe(r),Z||(Z=!0,I.once("OPERATION_FAILED",()=>{c&&c.terminate()}))};var Oe=(r,e)=>{let{action:t}=r.data;switch(t){case 0:c=new Worker(O("cancel"),{type:"module"}),c.postMessage(r.data);break;case 1:c=new Worker(O("download"),{type:"module"}),c.postMessage(r.data);break;case 2:c=new Worker(O("infos"),{type:"module"}),c.postMessage(r.data);break;case 4:c=c||new Worker(O("remove"),{type:"module"}),c.postMessage(r.data);break;case 5:{c=c||new Worker(O("upload"),{type:"module"}),c.postMessage(r.data);break}default:console.error("Action not found")}c.onmessage=n=>{e&&e(n),self.postMessage(n.data)},c.onerror=n=>{console.error(`Error: ${n.message}`)}},X=()=>{I.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),I.once("OPERATION_FAILED",r=>{self.postMessage({event:"OPERATION_FAILED",error:r})})};var Y=!1;self.onmessage=r=>{Y||(X(),Y=!0),be(r.data).map(()=>{self.postMessage({event:"FILE_REMOVED"})}).mapErr(e=>{self.postMessage({event:"OPERATION_FAILED",error:e})})};var be=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=>S(e)); diff --git a/themes/default/public/js/worker/upload.js b/themes/default/public/js/worker/upload.js index 467b3e4..be06e61 100644 --- a/themes/default/public/js/worker/upload.js +++ b/themes/default/public/js/worker/upload.js @@ -1 +1 @@ -var pt=Object.create;var Ce=Object.defineProperty;var mt=Object.getOwnPropertyDescriptor;var yt=Object.getOwnPropertyNames;var vt=Object.getPrototypeOf,gt=Object.prototype.hasOwnProperty;var wt=(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 pe=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var Et=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of yt(e))!gt.call(t,o)&&o!==r&&Ce(t,o,{get:()=>e[o],enumerable:!(n=mt(e,o))||n.enumerable});return t};var z=(t,e,r)=>(r=t!=null?pt(vt(t)):{},Et(e||!t||!t.__esModule?Ce(r,"default",{value:t,enumerable:!0}):r,t));var oe=pe((Pr,ye)=>{"use strict";var B=typeof Reflect=="object"?Reflect:null,Ie=B&&typeof B.apply=="function"?B.apply:function(e,r,n){return Function.prototype.apply.call(e,r,n)},re;B&&typeof B.ownKeys=="function"?re=B.ownKeys:Object.getOwnPropertySymbols?re=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:re=function(e){return Object.getOwnPropertyNames(e)};function kt(t){console&&console.warn&&console.warn(t)}var Ne=Number.isNaN||function(e){return e!==e};function y(){y.init.call(this)}ye.exports=y;ye.exports.once=Rt;y.EventEmitter=y;y.prototype._events=void 0;y.prototype._eventsCount=0;y.prototype._maxListeners=void 0;var Me=10;function ne(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 Me},set:function(t){if(typeof t!="number"||t<0||Ne(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");Me=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||Ne(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 Ue(t){return t._maxListeners===void 0?y.defaultMaxListeners:t._maxListeners}y.prototype.getMaxListeners=function(){return Ue(this)};y.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")Ie(u,this,r);else for(var f=u.length,h=ze(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,kt(c)}return t}y.prototype.addListener=function(e,r){return Be(this,e,r,!1)};y.prototype.on=y.prototype.addListener;y.prototype.prependListener=function(e,r){return Be(this,e,r,!0)};function Ct(){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 Fe(t,e,r){var n={fired:!1,wrapFn:void 0,target:t,type:e,listener:r},o=Ct.bind(n);return o.listener=r,n.wrapFn=o,o}y.prototype.once=function(e,r){return ne(r),this.on(e,Fe(this,e,r)),this};y.prototype.prependOnceListener=function(e,r){return ne(r),this.prependListener(e,Fe(this,e,r)),this};y.prototype.removeListener=function(e,r){var n,o,i,s,c;if(ne(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():Tt(n,i),n.length===1&&(o[e]=n[0]),o.removeListener!==void 0&&this.emit("removeListener",e,c||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 je(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?Pt(o):ze(o,o.length)}y.prototype.listeners=function(e){return je(this,e,!0)};y.prototype.rawListeners=function(e){return je(this,e,!1)};y.listenerCount=function(t,e){return typeof t.listenerCount=="function"?t.listenerCount(e):We.call(t,e)};y.prototype.listenerCount=We;function We(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?re(this._events):[]};function ze(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 Ve(this,t,0)},decrypt:function(t){return Ve(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 Ve(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,p=[0,0,0,0];c=t.s[r],t=c[0];var v=c[1],N=c[2],ee=c[3],te=c[4];for(l=0;l>>24]^v[i>>16&255]^N[s>>8&255]^ee[e&255]^n[d],u=t[i>>>24]^v[s>>16&255]^N[e>>8&255]^ee[o&255]^n[d+1],f=t[s>>>24]^v[e>>16&255]^N[o>>8&255]^ee[i&255]^n[d+2],e=t[e>>>24]^v[o>>16&255]^N[i>>8&255]^ee[s&255]^n[d+3],d+=4,o=c,i=u,s=f;for(l=0;4>l;l++)p[r?3&-l:l]=te[o>>>24]<<24^te[i>>16&255]<<16^te[s>>8&255]<<8^te[e&255]^n[d++],c=o,o=i,i=s,s=e,e=c;return p}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 ge(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],p=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)+(p^l&(d^p))+s[r],v=p,p=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]+p|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&&Xe("seeded",Math.max(this.o,this.f)),Xe("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:K(this,this.ma),mouseCollector:K(this,this.oa),keyboardCollector:K(this,this.la),accelerometerCollector:K(this,this.ea),touchCollector:K(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 K(t,e){return function(){e.apply(t,arguments)}}a.random=new a.prng(6);e:try{if(ce=typeof j<"u"&&j.exports){try{ue=wt("crypto")}catch{ue=null}ce=ae=ue}if(ce&&ae.randomBytes)V=ae.randomBytes(128),V=new Uint32Array(new Uint8Array(V).buffer),a.random.addEntropy(V,1024,"crypto['randomBytes']");else if(typeof window<"u"&&typeof Uint32Array<"u"){if(X=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(X);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(X);else break e;a.random.addEntropy(X,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 V,ae,X,ce,ue;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 nr=Object.prototype.hasOwnProperty,L="~";function H(){}Object.create&&(H.prototype=Object.create(null),new H().__proto__||(L=!1));function or(t,e,r){this.fn=t,this.context=e,this.once=r||!1}function ut(t,e,r,n,o){if(typeof r!="function")throw new TypeError("The listener must be a function");var i=new or(r,n||t,o),s=L?L+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 fe(t,e){--t._eventsCount===0?t._events=new H:delete t._events[e]}function A(){this._events=new H,this._eventsCount=0}A.prototype.eventNames=function(){var e=[],r,n;if(this._eventsCount===0)return e;for(n in r=this._events)nr.call(r,n)&&e.push(L?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(r)):e};A.prototype.listeners=function(e){var r=L?L+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 U(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,[])).next())})}function Te(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 Lt(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(p){return new Promise(function(v,N){i.push([d,p,v,N])>1||c(d,p)})})}function c(d,p){try{u(n[d](p))}catch(v){l(i[0][3],v)}}function u(d){d.value instanceof M?Promise.resolve(d.value.v).then(f,h):l(i[0][2],d)}function f(d){c("next",d)}function h(d){c("throw",d)}function l(d,p){d(p),i.shift(),i.length&&c(i[0][0],i[0][1])}}function Ot(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:o==="return"}:i?i(s):s}:i}}function bt(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 Te=="function"?Te(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 g=class t{constructor(e){this._promise=e}static fromSafePromise(e){let r=e.then(n=>new x(n));return new t(r)}static fromPromise(e,r){let n=e.then(o=>new x(o)).catch(o=>new _(r(o)));return new t(n)}static fromThrowable(e,r){return(...n)=>new t(U(this,void 0,void 0,function*(){try{return new x(yield e(...n))}catch(o){return new _(r?r(o):o)}}))}static combine(e){return xt(e)}static combineWithAllErrors(e){return _t(e)}map(e){return new t(this._promise.then(r=>U(this,void 0,void 0,function*(){return r.isErr()?new _(r.error):new x(yield e(r.value))})))}andThrough(e){return new t(this._promise.then(r=>U(this,void 0,void 0,function*(){if(r.isErr())return new _(r.error);let n=yield e(r.value);return n.isErr()?new _(n.error):new x(r.value)})))}andTee(e){return new t(this._promise.then(r=>U(this,void 0,void 0,function*(){if(r.isErr())return new _(r.error);try{yield e(r.value)}catch{}return new x(r.value)})))}mapErr(e){return new t(this._promise.then(r=>U(this,void 0,void 0,function*(){return r.isOk()?new x(r.value):new _(yield e(r.error))})))}andThen(e){return new t(this._promise.then(r=>{if(r.isErr())return new _(r.error);let n=e(r.value);return n instanceof t?n._promise:n}))}orElse(e){return new t(this._promise.then(r=>U(this,void 0,void 0,function*(){return r.isErr()?e(r.error):new x(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 Lt(this,arguments,function*(){return yield M(yield M(yield*Ot(bt(yield M(this._promise.then(r=>r.safeUnwrap()))))))})}then(e,r){return this._promise.then(e,r)}},O=t=>new g(Promise.resolve(new x(t))),w=t=>new g(Promise.resolve(new _(t))),cr=g.fromPromise,ur=g.fromSafePromise,fr=g.fromThrowable,Re=t=>{let e=S([]);for(let r of t)if(r.isErr()){e=k(r.error);break}else e.map(n=>n.push(r.value));return e},xt=t=>g.fromSafePromise(Promise.all(t)).andThen(Re),Se=t=>{let e=S([]);for(let r of t)r.isErr()&&e.isErr()?e.error.push(r.error):r.isErr()&&e.isOk()?e=k([r.error]):r.isOk()&&e.isOk()&&e.value.push(r.value);return e},_t=t=>g.fromSafePromise(Promise.all(t)).andThen(Se),me;(function(t){function e(o,i){return(...s)=>{try{let c=o(...s);return S(c)}catch(c){return k(i?i(c):c)}}}t.fromThrowable=e;function r(o){return Re(o)}t.combine=r;function n(o){return Se(o)}t.combineWithAllErrors=n})(me||(me={}));var S=t=>new x(t);function k(t){return new _(t)}var x=class{constructor(e){this.value=e}isOk(){return!0}isErr(){return!this.isOk()}map(e){return S(e(this.value))}mapErr(e){return S(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 S(this.value)}orElse(e){return S(this.value)}asyncAndThen(e){return e(this.value)}asyncAndThrough(e){return e(this.value).map(()=>this.value)}asyncMap(e){return g.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 Pe("Called `_unsafeUnwrapErr` on an Ok",this,e)}},_=class{constructor(e){this.error=e}isOk(){return!1}isErr(){return!this.isOk()}map(e){return k(this.error)}mapErr(e){return k(e(this.error))}andThrough(e){return k(this.error)}andTee(e){return k(this.error)}andThen(e){return k(this.error)}orElse(e){return e(this.error)}asyncAndThen(e){return w(this.error)}asyncAndThrough(e){return w(this.error)}asyncMap(e){return w(this.error)}unwrapOr(e){return e}match(e,r){return r(this.error)}safeUnwrap(){let e=this.error;return function*(){throw yield k(e),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(e){throw Pe("Called `_unsafeUnwrap` on an Err",this,e)}_unsafeUnwrapErr(e){return this.error}},lr=me.fromThrowable;var T=class extends Error{context;constructor(e,r={}){let{cause:n,context:o}=r;super(e,{cause:n}),this.name=this.constructor.name,this.context=o}};var D=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 Dt=()=>typeof Deno<"u",P=t=>Dt()?new URL(`./worker/${t}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${t==="main"?`worker/${t}`:t}.js`));var C=class extends T{};var J=class extends C{message="An error occured while trying to connect to WebSocket"};var $e=z(oe());var m=new $e.default,E,qe=!1;self.onmessage=t=>{Mt(t),qe||(qe=!0,m.once("OPERATION_FAILED",()=>{E&&E.terminate()}))};var R=(t,e)=>(Object.assign(t,e),typeof WorkerGlobalScope<"u"&&self.postMessage({event:"FILE_UPDATED",lufiFile:t}),t),q=(t,e)=>{R(t,{uploadStatus:2}),self.postMessage({event:"OPERATION_FAILED",error:e})},Mt=(t,e)=>{let{action:r}=t.data;switch(r){case 0:E=new Worker(P("cancel"),{type:"module"}),E.postMessage(t.data);break;case 1:E=new Worker(P("download"),{type:"module"}),E.postMessage(t.data);break;case 2:E=new Worker(P("infos"),{type:"module"}),E.postMessage(t.data);break;case 4:E=E||new Worker(P("remove"),{type:"module"}),E.postMessage(t.data);break;case 5:{E=E||new Worker(P("upload"),{type:"module"}),E.postMessage(t.data);break}default:console.error("Action not found")}E.onmessage=n=>{e&&e(n),self.postMessage(n.data)},E.onerror=n=>{console.error(`Error: ${n.message}`)}},Ge=()=>{m.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),m.once("OPERATION_FAILED",t=>{self.postMessage({event:"OPERATION_FAILED",error:t})})};var F=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 Nt=new F("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");function $(t){return Nt.Decode(t)}var Ut=new F("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",!0);function ve(t){return Ut.Decode(t)}var Ze=z(Ye());var I=class extends T{};var W=class extends I{message="Unable to decrypt the provided data"};var et=(t,e)=>{try{let r=typeof e=="string"?e:e.data;return O($(Ze.default.decrypt(t,r)))}catch(r){return w(new W(void 0,{cause:D(r)}))}};var tt=(t,e)=>jt(t).andThen(r=>g.fromPromise(crypto.subtle.decrypt({name:"AES-GCM",iv:e.iv},r,$(e.data)),n=>new W(void 0,{cause:D(n)})));var jt=t=>g.fromPromise(crypto.subtle.importKey("raw",ve(t),{name:"AES-GCM"},!1,["encrypt","decrypt"]),e=>new I("Unable to import cryptography key",{cause:D(e)}));var rt=(t,e)=>e.algo===void 0||e.algo===0?et(t,e):tt(t,e);var b={},ot=5,zt=t=>(m.emit("UPLOAD_CANCELLED",t.success),O(void 0)),Jt=(t,e)=>{let r=t.split("XXMOJOXX"),n=r.shift();if(n!==void 0){let o=JSON.parse(n);if(Qt(o)){let i=r.shift();if(i){let s=JSON.parse(i);return s.iv&&(s.iv=new Uint8Array(Object.values(s.iv))),rt(e.keys.client,s).andThen(c=>{let u=typeof c=="string"?new TextEncoder().encode(c).buffer:c;return o.part===0?(R(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}),m.emit("DOWNLOAD_STARTED")):R(e,{chunksReady:e.chunksReady+1}),m.emit("CHUNK_DOWNLOADED",u,o.part),++o.part===o.total?Kt(e).andThen(()=>(m.emit("DOWNLOAD_COMPLETE"),m.emit("SOCKET_OPERATION_TERMINATED"),O(void 0))):O(void 0)})}else{let s=new C("Can't retrieve metadata from data received by the server");return m.emit("OPERATION_FAILED",s),w(s)}}else{let i=new C(o.msg);return m.emit("OPERATION_FAILED",i),w(i)}}else{let o=new C("Can't retrieve metadata from data received by the server");return m.emit("OPERATION_FAILED",o),w(o)}},qt=(t,e)=>{if(t.success)return t.j===0&&(R(e,{keys:{client:e.keys.client,server:t.short},actionToken:t.token,queueIndex:t.i}),m.emit("UPLOAD_STARTED")),R(e,{chunksReady:e.chunksReady+1,createdAt:t.created_at}),m.emit("CHUNK_UPLOADED"),e.chunksReady===e.totalChunks&&(R(e,{uploadStatus:1}),m.emit("UPLOAD_COMPLETE"),m.emit("SOCKET_OPERATION_TERMINATED")),O(void 0);{let r=new C(t.msg);return m.emit("OPERATION_FAILED",r),w(r)}},$t=(t,e)=>{let r=Yt(t.data),n;if(r)if(!r.action&&r.msg){let o=new C(r.msg);return m.emit("OPERATION_FAILED",o),w(o)}else"delay"in r?n=qt(r,e):n=zt(r);else n=Jt(t.data,e);return n},Gt=t=>b!==void 0&&b[t]!==void 0&&b[t].readyState===WebSocket.CONNECTING,Ee=t=>b!==void 0&&b[t]!==void 0&&b[t].readyState===WebSocket.OPEN;var Kt=t=>{let e;return t.password?e={ended:!0,file_pwd:t.password}:e={ended:!0},Le(Xt(t),t,JSON.stringify(e))},Ae=(t,e,r)=>Le(Ht(t),t,`${JSON.stringify(e)}XXMOJOXX${JSON.stringify(r)}`),Le=(t,e,r)=>Ee(t)?(b[t].onmessage=n=>$t(n,e),b[t].send(r),O(void 0)):it(t).andThen(()=>Le(t,e,r)),it=(t,e=0)=>(!Ee(t)&&!Gt(t)&&(b[t]=new WebSocket(t),m.once("SOCKET_OPERATION_TERMINATED",()=>{b[t].close()}),m.once("OPERATION_FAILED",()=>{m.emit("SOCKET_OPERATION_TERMINATED")}),b[t].onopen=()=>{m.emit("SOCKET_OPENED")},b[t].onclose=()=>{},b[t].onerror=()=>++e<=ot?(console.error(`An error happened while trying to connect to WebSocket ${t}. Trying again. ${e} / ${ot}`),it(t,e)):(m.emit("SOCKET_ONERROR"),w(new J(`Unable to connect to WebSocket ${t}.`)))),Vt(t).andThen(()=>O(t)).orElse(r=>w(r))),Vt=t=>g.fromPromise(new Promise((e,r)=>{Ee(t)?e(void 0):(m.once("SOCKET_OPENED",()=>{e(void 0)}),m.on("SOCKET_ONERROR",()=>{r(new J)}))}),e=>D(e));var st=(t,e)=>{let r=new URL(t);return r.protocol=r.protocol==="http:"?"ws:":"wss:",r.pathname+=e,r},Xt=t=>st(new URL(t.serverUrl),"download"+`/${t.keys.server}`).toString(),Ht=t=>st(new URL(t.serverUrl),"upload").toString(),Yt=t=>{try{let e=JSON.parse(t);if(e&&typeof e=="object")return e}catch{}return!1},Qt=t=>typeof t=="object"&&t!==null&&!("msg"in t);var at=z(oe());var er=z(oe());var tr={},co=new at.default;var rr=()=>Object.values(tr).filter(t=>t.uploadStatus===4),ct=t=>Object.keys(rr()).indexOf(t);var be=z(ft(),1);var Y=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},xe=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},lt=t=>globalThis.DOMException===void 0?new xe(t):new DOMException(t),ht=t=>{let e=t.reason===void 0?lt("This operation was aborted."):t.reason;return e instanceof Error?e:lt(e)};function _e(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(ht(d));let p=()=>{h(ht(d))};d.addEventListener("abort",p,{once:!0}),t.finally(()=>{d.removeEventListener("abort",p)})}if(r===Number.POSITIVE_INFINITY){t.then(f,h);return}let l=new Y;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??`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 De(t,e,r){let n=0,o=t.length;for(;o>0;){let i=Math.trunc(o/2),s=n+i;r(t[s],e)<=0?(n=++s,o-=i+1):o=i}return n}var Q=class{#e=[];enqueue(e,r){r={priority:0,...r};let n={priority:r.priority,run:e};if(this.size&&this.#e[this.size-1].priority>=r.priority){this.#e.push(n);return}let o=De(this.#e,n,(i,s)=>s.priority-i.priority);this.#e.splice(o,0,n)}dequeue(){return this.#e.shift()?.run}filter(e){return this.#e.filter(r=>r.priority===e.priority).map(r=>r.run)}get size(){return this.#e.length}};var Z=class extends be.default{#e;#s;#i=0;#d;#a;#p=0;#r;#c;#t;#m;#n=0;#u;#o;#y;timeout;constructor(e){if(super(),e={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:Q,...e},!(typeof e.intervalCap=="number"&&e.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${e.intervalCap?.toString()??""}\` (${typeof e.intervalCap})`);if(e.interval===void 0||!(Number.isFinite(e.interval)&&e.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${e.interval?.toString()??""}\` (${typeof e.interval})`);this.#e=e.carryoverConcurrencyCount,this.#s=e.intervalCap===Number.POSITIVE_INFINITY||e.interval===0,this.#d=e.intervalCap,this.#a=e.interval,this.#t=new e.queueClass,this.#m=e.queueClass,this.concurrency=e.concurrency,this.timeout=e.timeout,this.#y=e.throwOnTimeout===!0,this.#o=e.autoStart===!1}get#w(){return this.#s||this.#i{this.#L()},r)),!0}return!1}#f(){if(this.#t.size===0)return this.#r&&clearInterval(this.#r),this.#r=void 0,this.emit("empty"),this.#n===0&&this.emit("idle"),!1;if(!this.#o){let e=!this.#O;if(this.#w&&this.#E){let r=this.#t.dequeue();return r?(this.emit("active"),r(),e&&this.#v(),!0):!1}}return!1}#v(){this.#s||this.#r!==void 0||(this.#r=setInterval(()=>{this.#g()},this.#a),this.#p=Date.now()+this.#a)}#g(){this.#i===0&&this.#n===0&&this.#r&&(clearInterval(this.#r),this.#r=void 0),this.#i=this.#e?this.#n:0,this.#l()}#l(){for(;this.#f(););}get concurrency(){return this.#u}set concurrency(e){if(!(typeof e=="number"&&e>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${e}\` (${typeof e})`);this.#u=e,this.#l()}async#b(e){return new Promise((r,n)=>{e.addEventListener("abort",()=>{n(e.reason)},{once:!0})})}async add(e,r={}){return r={timeout:this.timeout,throwOnTimeout:this.#y,...r},new Promise((n,o)=>{this.#t.enqueue(async()=>{this.#n++,this.#i++;try{r.signal?.throwIfAborted();let i=e({signal:r.signal});r.timeout&&(i=_e(Promise.resolve(i),{milliseconds:r.timeout})),r.signal&&(i=Promise.race([i,this.#b(r.signal)]));let s=await i;n(s),this.emit("completed",s)}catch(i){if(i instanceof Y&&!r.throwOnTimeout){n();return}o(i),this.emit("error",i)}finally{this.#A()}},r),this.emit("add"),this.#f()})}async addAll(e,r){return Promise.all(e.map(async n=>this.add(n,r)))}start(){return this.#o?(this.#o=!1,this.#l(),this):this}pause(){this.#o=!0}clear(){this.#t=new this.#m}async onEmpty(){this.#t.size!==0&&await this.#h("empty")}async onSizeLessThan(e){this.#t.sizethis.#t.size{let o=()=>{r&&!r()||(this.off(e,o),n())};this.on(e,o)})}get size(){return this.#t.size}sizeBy(e){return this.#t.filter(e).length}get pending(){return this.#n}get isPaused(){return this.#o}};var dt=!1,ke=8,le=new Z({concurrency:ke,autoStart:!1}),he=0,de=[];self.onmessage=t=>{let{chunk:e,lufiFile:r}=t.data.args;if(dt||(Ge(),dt=!0),e){if(de[e.index]=e,de.length===r.totalChunks)return m.once("UPLOAD_COMPLETE",()=>{self.postMessage({event:"UPLOAD_COMPLETE"})}),m.on("FILE_UPDATED",R),m.on("CHUNK_UPLOADED",()=>{self.postMessage({event:"CHUNK_UPLOADED"}),he--,hesr(t,ct(t.args.lufiFile.keys.client)),sr=(t,e)=>{let{lufiFile:r}=t.args,n=new Worker(P("encrypt"),{type:"module"});return m.on("UPLOAD_STARTED",()=>{n.onmessage=async o=>{if(o.data.encryptedData){let{encryptedData:i}=o.data;await le.add(async()=>{await Ae(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),he++,he===ke&&le.pause()})}le.start(),o.data.error&&(q(r,o.data.error),n.terminate())};for(let o=1;o{if(o.data.encryptedData){let{encryptedData:i}=o.data;Ae(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=>{q(r,s)})}o.data.error&&q(r,o.data.error)},t.args.chunk=de[0],n.postMessage(t),O(void 0)}; +var pt=Object.create;var Ce=Object.defineProperty;var mt=Object.getOwnPropertyDescriptor;var yt=Object.getOwnPropertyNames;var gt=Object.getPrototypeOf,vt=Object.prototype.hasOwnProperty;var wt=(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 pe=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var Et=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of yt(e))!vt.call(t,i)&&i!==r&&Ce(t,i,{get:()=>e[i],enumerable:!(n=mt(e,i))||n.enumerable});return t};var z=(t,e,r)=>(r=t!=null?pt(gt(t)):{},Et(e||!t||!t.__esModule?Ce(r,"default",{value:t,enumerable:!0}):r,t));var ie=pe((Pr,ye)=>{"use strict";var B=typeof Reflect=="object"?Reflect:null,Ie=B&&typeof B.apply=="function"?B.apply:function(e,r,n){return Function.prototype.apply.call(e,r,n)},re;B&&typeof B.ownKeys=="function"?re=B.ownKeys:Object.getOwnPropertySymbols?re=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:re=function(e){return Object.getOwnPropertyNames(e)};function kt(t){console&&console.warn&&console.warn(t)}var Ne=Number.isNaN||function(e){return e!==e};function y(){y.init.call(this)}ye.exports=y;ye.exports.once=Rt;y.EventEmitter=y;y.prototype._events=void 0;y.prototype._eventsCount=0;y.prototype._maxListeners=void 0;var Me=10;function ne(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 Me},set:function(t){if(typeof t!="number"||t<0||Ne(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");Me=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||Ne(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 Ue(t){return t._maxListeners===void 0?y.defaultMaxListeners:t._maxListeners}y.prototype.getMaxListeners=function(){return Ue(this)};y.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=o[e];if(u===void 0)return!1;if(typeof u=="function")Ie(u,this,r);else for(var f=u.length,h=ze(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(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");c.name="MaxListenersExceededWarning",c.emitter=t,c.type=e,c.count=s.length,kt(c)}return t}y.prototype.addListener=function(e,r){return Be(this,e,r,!1)};y.prototype.on=y.prototype.addListener;y.prototype.prependListener=function(e,r){return Be(this,e,r,!0)};function Ct(){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 Fe(t,e,r){var n={fired:!1,wrapFn:void 0,target:t,type:e,listener:r},i=Ct.bind(n);return i.listener=r,n.wrapFn=i,i}y.prototype.once=function(e,r){return ne(r),this.on(e,Fe(this,e,r)),this};y.prototype.prependOnceListener=function(e,r){return ne(r),this.prependListener(e,Fe(this,e,r)),this};y.prototype.removeListener=function(e,r){var n,i,o,s,c;if(ne(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){c=n[s].listener,o=s;break}if(o<0)return this;o===0?n.shift():Tt(n,o),n.length===1&&(i[e]=n[0]),i.removeListener!==void 0&&this.emit("removeListener",e,c||r)}return this};y.prototype.off=y.prototype.removeListener;y.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 je(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?Pt(i):ze(i,i.length)}y.prototype.listeners=function(e){return je(this,e,!0)};y.prototype.rawListeners=function(e){return je(this,e,!1)};y.listenerCount=function(t,e){return typeof t.listenerCount=="function"?t.listenerCount(e):We.call(t,e)};y.prototype.listenerCount=We;function We(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?re(this._events):[]};function ze(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,i,o=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),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^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],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]]};a.cipher.aes.prototype={encrypt:function(t){return Ve(this,t,0)},decrypt:function(t){return Ve(this,t,1)},s:[[[],[],[],[],[]],[[],[],[],[],[]]],O:function(){var t=this.s[0],e=this.s[1],r=t[4],n=e[4],i,o,s,c=[],u=[],f,h,l,d;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]]],d=16843009*h^65537*i^257*f^16843008*o,h=257*c[l]^16843008*l,i=0;4>i;i++)t[i][o]=h=h<<24^h>>>8,e[i][l]=d=d<<24^d>>>8;for(i=0;5>i;i++)t[i]=t[i].slice(0),e[i]=e[i].slice(0)}};function Ve(t,e,r){if(e.length!==4)throw new a.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 c,u,f,h=n.length/4-2,l,d=4,p=[0,0,0,0];c=t.s[r],t=c[0];var g=c[1],N=c[2],ee=c[3],te=c[4];for(l=0;l>>24]^g[o>>16&255]^N[s>>8&255]^ee[e&255]^n[d],u=t[o>>>24]^g[s>>16&255]^N[e>>8&255]^ee[i&255]^n[d+1],f=t[s>>>24]^g[e>>16&255]^N[i>>8&255]^ee[o&255]^n[d+2],e=t[e>>>24]^g[i>>16&255]^N[o>>8&255]^ee[s&255]^n[d+3],d+=4,i=c,o=u,s=f;for(l=0;4>l;l++)p[r?3&-l:l]=te[i>>>24]<<24^te[o>>16&255]<<16^te[s>>8&255]<<8^te[e&255]^n[d++],c=i,i=o,o=s,s=e,e=c;return p}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[i]<<32-e;return i=t.length?t[t.length-1]:0,t=a.bitArray.getPartial(i),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,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 a.codec.base32hex.toBits(t)}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=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=a.codec.base64.B,s=0,c;for(e&&(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(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(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 ve(t,e){var r,n,i,o=t.F,s=t.b,c=o[0],u=o[1],f=o[2],h=o[3],l=o[4],d=o[5],p=o[6],g=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+g+(l>>>6^l>>>11^l>>>25^l<<26^l<<21^l<<7)+(p^l&(d^p))+s[r],g=p,p=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;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]+d|0,o[6]=o[6]+p|0,o[7]=o[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(o=2;4>o&&f>>>8*o;o++);return o<15-u&&(o=15-u),r=c.clamp(r,8*(15-o)),e=a.mode.ccm.V(t,e,r,n,i,o),s=a.mode.ccm.C(t,s,r,e,i,o),c.concat(s.data,s.tag)},decrypt:function(t,e,r,n,i){i=i||64,n=n||[];var o=a.bitArray,s=o.bitLength(r)/8,f=o.bitLength(e),c=o.clamp(e,f-i),u=o.bitSlice(e,f-i),f=(f-i)/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=o.clamp(r,8*(15-e)),c=a.mode.ccm.C(t,c,r,u,i,e),t=a.mode.ccm.V(t,c.data,r,n,i,e),!o.equal(c.tag,t))throw new a.exception.corrupt("ccm: tag doesn't match");return c.data},na:function(t,e,r,n,i,o){var s=[],c=a.bitArray,u=c.i;if(n=[c.partial(8,(e.length?64:0)|n-2<<2|o-1)],n=c.concat(n,r),n[3]|=i,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;ei||16h&&(a.mode.ccm.fa(s/u),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:c.clamp(e,f)}}};a.mode.ocb2={name:"ocb2",encrypt:function(t,e,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(t.encrypt(r));var l,d=[];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),t.encrypt(o(n(o(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,i){var o=e.slice(0);return e=a.bitArray,n=n||[],t=a.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=a.bitArray,c=s.bitLength(o);if(i=i||128,n=n||[],i<=c?(e=s.bitSlice(o,c-i),o=s.bitSlice(o,0,c-i)):(e=o,o=[]),t=a.mode.gcm.C(!1,t,o,n,r,i),!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,i,o,s,c=a.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=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(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 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)),i=i||a.misc.hmac,t=new i(t);var o,s,c,u,f=[],h=a.bitArray;for(u=1;32*f.length<(n||1);u++){for(i=o=t.encrypt(h.concat(e,[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,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: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&&Xe("seeded",Math.max(this.o,this.f)),Xe("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:K(this,this.ma),mouseCollector:K(this,this.oa),keyboardCollector:K(this,this.la),accelerometerCollector:K(this,this.ea),touchCollector:K(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,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 K(t,e){return function(){e.apply(t,arguments)}}a.random=new a.prng(6);e:try{if(ce=typeof j<"u"&&j.exports){try{ue=wt("crypto")}catch{ue=null}ce=ae=ue}if(ce&&ae.randomBytes)V=ae.randomBytes(128),V=new Uint32Array(new Uint8Array(V).buffer),a.random.addEntropy(V,1024,"crypto['randomBytes']");else if(typeof window<"u"&&typeof Uint32Array<"u"){if(X=new Uint32Array(32),window.crypto&&window.crypto.getRandomValues)window.crypto.getRandomValues(X);else if(window.msCrypto&&window.msCrypto.getRandomValues)window.msCrypto.getRandomValues(X);else break e;a.random.addEntropy(X,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 V,ae,X,ce,ue;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 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 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||4{"use strict";var nr=Object.prototype.hasOwnProperty,L="~";function H(){}Object.create&&(H.prototype=Object.create(null),new H().__proto__||(L=!1));function ir(t,e,r){this.fn=t,this.context=e,this.once=r||!1}function ut(t,e,r,n,i){if(typeof r!="function")throw new TypeError("The listener must be a function");var o=new ir(r,n||t,i),s=L?L+e:e;return t._events[s]?t._events[s].fn?t._events[s]=[t._events[s],o]:t._events[s].push(o):(t._events[s]=o,t._eventsCount++),t}function fe(t,e){--t._eventsCount===0?t._events=new H:delete t._events[e]}function A(){this._events=new H,this._eventsCount=0}A.prototype.eventNames=function(){var e=[],r,n;if(this._eventsCount===0)return e;for(n in r=this._events)nr.call(r,n)&&e.push(L?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(r)):e};A.prototype.listeners=function(e){var r=L?L+e:e,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=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 U(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 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(t,[])).next())})}function Te(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 Lt(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(d){n[d]&&(i[d]=function(p){return new Promise(function(g,N){o.push([d,p,g,N])>1||c(d,p)})})}function c(d,p){try{u(n[d](p))}catch(g){l(o[0][3],g)}}function u(d){d.value instanceof M?Promise.resolve(d.value.v).then(f,h):l(o[0][2],d)}function f(d){c("next",d)}function h(d){c("throw",d)}function l(d,p){d(p),o.shift(),o.length&&c(o[0][0],o[0][1])}}function Ot(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:M(t[i](s)),done:i==="return"}:o?o(s):s}:o}}function bt(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 Te=="function"?Te(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(c,u){s=t[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 v=class t{constructor(e){this._promise=e}static fromSafePromise(e){let r=e.then(n=>new x(n));return new t(r)}static fromPromise(e,r){let n=e.then(i=>new x(i)).catch(i=>new _(r(i)));return new t(n)}static fromThrowable(e,r){return(...n)=>new t(U(this,void 0,void 0,function*(){try{return new x(yield e(...n))}catch(i){return new _(r?r(i):i)}}))}static combine(e){return xt(e)}static combineWithAllErrors(e){return _t(e)}map(e){return new t(this._promise.then(r=>U(this,void 0,void 0,function*(){return r.isErr()?new _(r.error):new x(yield e(r.value))})))}andThrough(e){return new t(this._promise.then(r=>U(this,void 0,void 0,function*(){if(r.isErr())return new _(r.error);let n=yield e(r.value);return n.isErr()?new _(n.error):new x(r.value)})))}andTee(e){return new t(this._promise.then(r=>U(this,void 0,void 0,function*(){if(r.isErr())return new _(r.error);try{yield e(r.value)}catch{}return new x(r.value)})))}mapErr(e){return new t(this._promise.then(r=>U(this,void 0,void 0,function*(){return r.isOk()?new x(r.value):new _(yield e(r.error))})))}andThen(e){return new t(this._promise.then(r=>{if(r.isErr())return new _(r.error);let n=e(r.value);return n instanceof t?n._promise:n}))}orElse(e){return new t(this._promise.then(r=>U(this,void 0,void 0,function*(){return r.isErr()?e(r.error):new x(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 Lt(this,arguments,function*(){return yield M(yield M(yield*Ot(bt(yield M(this._promise.then(r=>r.safeUnwrap()))))))})}then(e,r){return this._promise.then(e,r)}},O=t=>new v(Promise.resolve(new x(t))),w=t=>new v(Promise.resolve(new _(t))),cr=v.fromPromise,ur=v.fromSafePromise,fr=v.fromThrowable,Re=t=>{let e=S([]);for(let r of t)if(r.isErr()){e=k(r.error);break}else e.map(n=>n.push(r.value));return e},xt=t=>v.fromSafePromise(Promise.all(t)).andThen(Re),Se=t=>{let e=S([]);for(let r of t)r.isErr()&&e.isErr()?e.error.push(r.error):r.isErr()&&e.isOk()?e=k([r.error]):r.isOk()&&e.isOk()&&e.value.push(r.value);return e},_t=t=>v.fromSafePromise(Promise.all(t)).andThen(Se),me;(function(t){function e(i,o){return(...s)=>{try{let c=i(...s);return S(c)}catch(c){return k(o?o(c):c)}}}t.fromThrowable=e;function r(i){return Re(i)}t.combine=r;function n(i){return Se(i)}t.combineWithAllErrors=n})(me||(me={}));var S=t=>new x(t);function k(t){return new _(t)}var x=class{constructor(e){this.value=e}isOk(){return!0}isErr(){return!this.isOk()}map(e){return S(e(this.value))}mapErr(e){return S(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 S(this.value)}orElse(e){return S(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 Pe("Called `_unsafeUnwrapErr` on an Ok",this,e)}},_=class{constructor(e){this.error=e}isOk(){return!1}isErr(){return!this.isOk()}map(e){return k(this.error)}mapErr(e){return k(e(this.error))}andThrough(e){return k(this.error)}andTee(e){return k(this.error)}andThen(e){return k(this.error)}orElse(e){return e(this.error)}asyncAndThen(e){return w(this.error)}asyncAndThrough(e){return w(this.error)}asyncMap(e){return w(this.error)}unwrapOr(e){return e}match(e,r){return r(this.error)}safeUnwrap(){let e=this.error;return function*(){throw yield k(e),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(e){throw Pe("Called `_unsafeUnwrap` on an Err",this,e)}_unsafeUnwrapErr(e){return this.error}},lr=me.fromThrowable;var T=class extends Error{context;constructor(e,r={}){let{cause:n,context:i}=r;super(e,{cause:n}),this.name=this.constructor.name,this.context=i}};var D=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 Dt=()=>typeof Deno<"u",P=t=>Dt()?new URL(`./worker/${t}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${t==="main"?`worker/${t}`:t}.js`));var C=class extends T{};var J=class extends C{message="An error occured while trying to connect to WebSocket"};var $e=z(ie());var m=new $e.default,E,qe=!1;self.onmessage=t=>{Mt(t),qe||(qe=!0,m.once("OPERATION_FAILED",()=>{E&&E.terminate()}))};var R=(t,e)=>(Object.assign(t,e),typeof WorkerGlobalScope<"u"&&self.postMessage({event:"FILE_UPDATED",lufiFile:t}),t),q=(t,e)=>{R(t,{uploadStatus:2}),self.postMessage({event:"OPERATION_FAILED",error:e})},Mt=(t,e)=>{let{action:r}=t.data;switch(r){case 0:E=new Worker(P("cancel"),{type:"module"}),E.postMessage(t.data);break;case 1:E=new Worker(P("download"),{type:"module"}),E.postMessage(t.data);break;case 2:E=new Worker(P("infos"),{type:"module"}),E.postMessage(t.data);break;case 4:E=E||new Worker(P("remove"),{type:"module"}),E.postMessage(t.data);break;case 5:{E=E||new Worker(P("upload"),{type:"module"}),E.postMessage(t.data);break}default:console.error("Action not found")}E.onmessage=n=>{e&&e(n),self.postMessage(n.data)},E.onerror=n=>{console.error(`Error: ${n.message}`)}},Ge=()=>{m.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),m.once("OPERATION_FAILED",t=>{self.postMessage({event:"OPERATION_FAILED",error:t})})};var F=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,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 Nt=new F("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");function $(t){return Nt.Decode(t)}var Ut=new F("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",!0);function ge(t){return Ut.Decode(t)}var Ze=z(Ye());var I=class extends T{};var W=class extends I{message="Unable to decrypt the provided data"};var et=(t,e)=>{try{let r=typeof e=="string"?e:e.data;return O($(Ze.default.decrypt(t,r)))}catch(r){return w(new W(void 0,{cause:D(r)}))}};var tt=(t,e)=>jt(t).andThen(r=>v.fromPromise(crypto.subtle.decrypt({name:"AES-GCM",iv:e.iv},r,$(e.data)),n=>new W(void 0,{cause:D(n)})));var jt=t=>v.fromPromise(crypto.subtle.importKey("raw",ge(t),{name:"AES-GCM"},!1,["encrypt","decrypt"]),e=>new I("Unable to import cryptography key",{cause:D(e)}));var rt=(t,e)=>e.algo===void 0||e.algo===0?et(t,e):tt(t,e);var b={},it=5,zt=t=>(m.emit("UPLOAD_CANCELLED",t.success),O(void 0)),Jt=(t,e)=>{let r=t.split("XXMOJOXX"),n=r.shift();if(n!==void 0){let i=JSON.parse(n);if(Qt(i)){let o=r.shift();if(o){let s=JSON.parse(o);return s.iv&&(s.iv=new Uint8Array(Object.values(s.iv))),rt(e.keys.client,s).andThen(c=>{let u=typeof c=="string"?new TextEncoder().encode(c).buffer:c;return i.part===0?(R(e,{chunksReady:e.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}),m.emit("DOWNLOAD_STARTED")):R(e,{chunksReady:e.chunksReady+1}),m.emit("CHUNK_DOWNLOADED",u,i.part),++i.part===i.total?Kt(e).andThen(()=>(m.emit("DOWNLOAD_COMPLETE"),m.emit("SOCKET_OPERATION_TERMINATED"),O(void 0))):O(void 0)})}else{let s=new C("Can't retrieve metadata from data received by the server");return m.emit("OPERATION_FAILED",s),w(s)}}else{let o=new C(i.msg);return m.emit("OPERATION_FAILED",o),w(o)}}else{let i=new C("Can't retrieve metadata from data received by the server");return m.emit("OPERATION_FAILED",i),w(i)}},qt=(t,e)=>{if(t.success)return t.j===0&&(R(e,{keys:{client:e.keys.client,server:t.short},actionToken:t.token,queueIndex:t.i}),m.emit("UPLOAD_STARTED")),R(e,{chunksReady:e.chunksReady+1,createdAt:t.created_at}),m.emit("CHUNK_UPLOADED"),e.chunksReady===e.totalChunks&&(R(e,{uploadStatus:1}),m.emit("UPLOAD_COMPLETE"),m.emit("SOCKET_OPERATION_TERMINATED")),O(void 0);{let r=new C(t.msg);return m.emit("OPERATION_FAILED",r),w(r)}},$t=(t,e)=>{let r=Yt(t.data),n;if(r)if(!r.action&&r.msg){let i=new C(r.msg);return m.emit("OPERATION_FAILED",i),w(i)}else"delay"in r?n=qt(r,e):n=zt(r);else n=Jt(t.data,e);return n},Gt=t=>b!==void 0&&b[t]!==void 0&&b[t].readyState===WebSocket.CONNECTING,Ee=t=>b!==void 0&&b[t]!==void 0&&b[t].readyState===WebSocket.OPEN;var Kt=t=>{let e;return t.password?e={ended:!0,file_pwd:t.password}:e={ended:!0},Le(Xt(t),t,JSON.stringify(e))},Ae=(t,e,r)=>Le(Ht(t),t,`${JSON.stringify(e)}XXMOJOXX${JSON.stringify(r)}`),Le=(t,e,r)=>Ee(t)?(b[t].onmessage=n=>$t(n,e),b[t].send(r),O(void 0)):ot(t).andThen(()=>Le(t,e,r)),ot=(t,e=0)=>(!Ee(t)&&!Gt(t)&&(b[t]=new WebSocket(t),m.once("SOCKET_OPERATION_TERMINATED",()=>{b[t].close()}),m.once("OPERATION_FAILED",()=>{m.emit("SOCKET_OPERATION_TERMINATED")}),b[t].onopen=()=>{m.emit("SOCKET_OPENED")},b[t].onclose=()=>{},b[t].onerror=()=>++e<=it?(console.error(`An error happened while trying to connect to WebSocket ${t}. Trying again. ${e} / ${it}`),ot(t,e)):(m.emit("SOCKET_ONERROR"),w(new J(`Unable to connect to WebSocket ${t}.`)))),Vt(t).andThen(()=>O(t)).orElse(r=>w(r))),Vt=t=>v.fromPromise(new Promise((e,r)=>{Ee(t)?e(void 0):(m.once("SOCKET_OPENED",()=>{e(void 0)}),m.on("SOCKET_ONERROR",()=>{r(new J)}))}),e=>D(e));var st=(t,e)=>{let r=new URL(t);return r.protocol=r.protocol==="http:"?"ws:":"wss:",r.pathname+=e,r},Xt=t=>st(new URL(t.serverUrl),"download"+`/${t.keys.server}`).toString(),Ht=t=>st(new URL(t.serverUrl),"upload").toString(),Yt=t=>{try{let e=JSON.parse(t);if(e&&typeof e=="object")return e}catch{}return!1},Qt=t=>typeof t=="object"&&t!==null&&!("msg"in t);var at=z(ie());var er=z(ie());var tr={},fi=new at.default;var rr=()=>Object.values(tr).filter(t=>t.uploadStatus===4),ct=t=>Object.keys(rr()).indexOf(t);var be=z(ft(),1);var Y=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},xe=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},lt=t=>globalThis.DOMException===void 0?new xe(t):new DOMException(t),ht=t=>{let e=t.reason===void 0?lt("This operation was aborted."):t.reason;return e instanceof Error?e:lt(e)};function _e(t,e){let{milliseconds:r,fallback:n,message:i,customTimers:o={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(ht(d));let p=()=>{h(ht(d))};d.addEventListener("abort",p,{once:!0}),t.finally(()=>{d.removeEventListener("abort",p)})}if(r===Number.POSITIVE_INFINITY){t.then(f,h);return}let l=new Y;s=o.setTimeout.call(void 0,()=>{if(n){try{f(n())}catch(d){h(d)}return}typeof t.cancel=="function"&&t.cancel(),i===!1?f():i instanceof Error?h(i):(l.message=i??`Promise timed out after ${r} milliseconds`,h(l))},r),(async()=>{try{f(await t)}catch(d){h(d)}})()}).finally(()=>{u.clear()});return u.clear=()=>{o.clearTimeout.call(void 0,s),s=void 0},u}function De(t,e,r){let n=0,i=t.length;for(;i>0;){let o=Math.trunc(i/2),s=n+o;r(t[s],e)<=0?(n=++s,i-=o+1):i=o}return n}var Q=class{#e=[];enqueue(e,r){r={priority:0,...r};let n={priority:r.priority,run:e};if(this.size&&this.#e[this.size-1].priority>=r.priority){this.#e.push(n);return}let i=De(this.#e,n,(o,s)=>s.priority-o.priority);this.#e.splice(i,0,n)}dequeue(){return this.#e.shift()?.run}filter(e){return this.#e.filter(r=>r.priority===e.priority).map(r=>r.run)}get size(){return this.#e.length}};var Z=class extends be.default{#e;#s;#o=0;#d;#a;#p=0;#r;#c;#t;#m;#n=0;#u;#i;#y;timeout;constructor(e){if(super(),e={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:Q,...e},!(typeof e.intervalCap=="number"&&e.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${e.intervalCap?.toString()??""}\` (${typeof e.intervalCap})`);if(e.interval===void 0||!(Number.isFinite(e.interval)&&e.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${e.interval?.toString()??""}\` (${typeof e.interval})`);this.#e=e.carryoverConcurrencyCount,this.#s=e.intervalCap===Number.POSITIVE_INFINITY||e.interval===0,this.#d=e.intervalCap,this.#a=e.interval,this.#t=new e.queueClass,this.#m=e.queueClass,this.concurrency=e.concurrency,this.timeout=e.timeout,this.#y=e.throwOnTimeout===!0,this.#i=e.autoStart===!1}get#w(){return this.#s||this.#o{this.#L()},r)),!0}return!1}#f(){if(this.#t.size===0)return this.#r&&clearInterval(this.#r),this.#r=void 0,this.emit("empty"),this.#n===0&&this.emit("idle"),!1;if(!this.#i){let e=!this.#O;if(this.#w&&this.#E){let r=this.#t.dequeue();return r?(this.emit("active"),r(),e&&this.#g(),!0):!1}}return!1}#g(){this.#s||this.#r!==void 0||(this.#r=setInterval(()=>{this.#v()},this.#a),this.#p=Date.now()+this.#a)}#v(){this.#o===0&&this.#n===0&&this.#r&&(clearInterval(this.#r),this.#r=void 0),this.#o=this.#e?this.#n:0,this.#l()}#l(){for(;this.#f(););}get concurrency(){return this.#u}set concurrency(e){if(!(typeof e=="number"&&e>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${e}\` (${typeof e})`);this.#u=e,this.#l()}async#b(e){return new Promise((r,n)=>{e.addEventListener("abort",()=>{n(e.reason)},{once:!0})})}async add(e,r={}){return r={timeout:this.timeout,throwOnTimeout:this.#y,...r},new Promise((n,i)=>{this.#t.enqueue(async()=>{this.#n++,this.#o++;try{r.signal?.throwIfAborted();let o=e({signal:r.signal});r.timeout&&(o=_e(Promise.resolve(o),{milliseconds:r.timeout})),r.signal&&(o=Promise.race([o,this.#b(r.signal)]));let s=await o;n(s),this.emit("completed",s)}catch(o){if(o instanceof Y&&!r.throwOnTimeout){n();return}i(o),this.emit("error",o)}finally{this.#A()}},r),this.emit("add"),this.#f()})}async addAll(e,r){return Promise.all(e.map(async n=>this.add(n,r)))}start(){return this.#i?(this.#i=!1,this.#l(),this):this}pause(){this.#i=!0}clear(){this.#t=new this.#m}async onEmpty(){this.#t.size!==0&&await this.#h("empty")}async onSizeLessThan(e){this.#t.sizethis.#t.size{let i=()=>{r&&!r()||(this.off(e,i),n())};this.on(e,i)})}get size(){return this.#t.size}sizeBy(e){return this.#t.filter(e).length}get pending(){return this.#n}get isPaused(){return this.#i}};var dt=!1,ke=8,le=new Z({concurrency:ke,autoStart:!1}),he=0,de=[];self.onmessage=t=>{let{chunk:e,lufiFile:r}=t.data.args;if(dt||(Ge(),dt=!0),e){if(de[e.index]=e,de.length===r.totalChunks)return m.once("UPLOAD_COMPLETE",()=>{self.postMessage({event:"UPLOAD_COMPLETE"})}),m.on("FILE_UPDATED",R),m.on("CHUNK_UPLOADED",()=>{self.postMessage({event:"CHUNK_UPLOADED"}),he--,hesr(t,ct(t.args.lufiFile.keys.client)),sr=(t,e)=>{let{lufiFile:r}=t.args,n=new Worker(P("encrypt"),{type:"module"});return m.on("UPLOAD_STARTED",()=>{n.onmessage=async i=>{if(i.data.encryptedData){let{encryptedData:o}=i.data;await le.add(async()=>{await Ae(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:e,file_pwd:r.password},o),he++,he===ke&&le.pause()})}le.start(),i.data.error&&(q(r,i.data.error),n.terminate())};for(let i=1;i{if(i.data.encryptedData){let{encryptedData:o}=i.data;Ae(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:e,file_pwd:r.password},o).mapErr(s=>{q(r,s)})}i.data.error&&q(r,i.data.error)},t.args.chunk=de[0],n.postMessage(t),O(void 0)};