var ue=Object.create;var C=Object.defineProperty;var ae=Object.getOwnPropertyDescriptor;var fe=Object.getOwnPropertyNames;var ce=Object.getPrototypeOf,le=Object.prototype.hasOwnProperty;var he=(r,e,t)=>e in r?C(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var pe=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var me=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of fe(e))!le.call(r,o)&&o!==t&&C(r,o,{get:()=>e[o],enumerable:!(n=ae(e,o))||n.enumerable});return r};var de=(r,e,t)=>(t=r!=null?ue(ce(r)):{},me(e||!r||!r.__esModule?C(t,"default",{value:r,enumerable:!0}):t,r));var g=(r,e,t)=>he(r,typeof e!="symbol"?e+"":e,t);var ee=pe((Ke,U)=>{"use strict";var A=typeof Reflect=="object"?Reflect:null,$=A&&typeof A.apply=="function"?A.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)},P;A&&typeof A.ownKeys=="function"?P=A.ownKeys:Object.getOwnPropertySymbols?P=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:P=function(e){return Object.getOwnPropertyNames(e)};function ge(r){console&&console.warn&&console.warn(r)}var q=Number.isNaN||function(e){return e!==e};function u(){u.init.call(this)}U.exports=u;U.exports.once=Ae;u.EventEmitter=u;u.prototype._events=void 0;u.prototype._eventsCount=0;u.prototype._maxListeners=void 0;var G=10;function M(r){if(typeof r!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof r)}Object.defineProperty(u,"defaultMaxListeners",{enumerable:!0,get:function(){return G},set:function(r){if(typeof r!="number"||r<0||q(r))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+r+".");G=r}});u.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0};u.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||q(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this};function z(r){return r._maxListeners===void 0?u.defaultMaxListeners:r._maxListeners}u.prototype.getMaxListeners=function(){return z(this)};u.prototype.emit=function(e){for(var t=[],n=1;n0&&(i=t[0]),i instanceof Error)throw i;var a=new Error("Unhandled error."+(i?" ("+i.message+")":""));throw a.context=i,a}var l=s[e];if(l===void 0)return!1;if(typeof l=="function")$(l,this,t);else for(var v=l.length,m=K(l,v),n=0;n0&&i.length>o&&!i.warned){i.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+i.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning",a.emitter=r,a.type=e,a.count=i.length,ge(a)}return r}u.prototype.addListener=function(e,t){return Q(this,e,t,!1)};u.prototype.on=u.prototype.addListener;u.prototype.prependListener=function(e,t){return Q(this,e,t,!0)};function be(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function Z(r,e,t){var n={fired:!1,wrapFn:void 0,target:r,type:e,listener:t},o=be.bind(n);return o.listener=t,n.wrapFn=o,o}u.prototype.once=function(e,t){return M(t),this.on(e,Z(this,e,t)),this};u.prototype.prependOnceListener=function(e,t){return M(t),this.prependListener(e,Z(this,e,t)),this};u.prototype.removeListener=function(e,t){var n,o,s,i,a;if(M(t),o=this._events,o===void 0)return this;if(n=o[e],n===void 0)return this;if(n===t||n.listener===t)--this._eventsCount===0?this._events=Object.create(null):(delete o[e],o.removeListener&&this.emit("removeListener",e,n.listener||t));else if(typeof n!="function"){for(s=-1,i=n.length-1;i>=0;i--)if(n[i]===t||n[i].listener===t){a=n[i].listener,s=i;break}if(s<0)return this;s===0?n.shift():De(n,s),n.length===1&&(o[e]=n[0]),o.removeListener!==void 0&&this.emit("removeListener",e,a||t)}return this};u.prototype.off=u.prototype.removeListener;u.prototype.removeAllListeners=function(e){var t,n,o;if(n=this._events,n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[e]),this;if(arguments.length===0){var s=Object.keys(n),i;for(o=0;o=0;o--)this.removeListener(e,t[o]);return this};function X(r,e,t){var n=r._events;if(n===void 0)return[];var o=n[e];return o===void 0?[]:typeof o=="function"?t?[o.listener||o]:[o]:t?Oe(o):K(o,o.length)}u.prototype.listeners=function(e){return X(this,e,!0)};u.prototype.rawListeners=function(e){return X(this,e,!1)};u.listenerCount=function(r,e){return typeof r.listenerCount=="function"?r.listenerCount(e):Y.call(r,e)};u.prototype.listenerCount=Y;function Y(r){var e=this._events;if(e!==void 0){var t=e[r];if(typeof t=="function")return 1;if(t!==void 0)return t.length}return 0}u.prototype.eventNames=function(){return this._eventsCount>0?P(this._events):[]};function K(r,e){for(var t=new Array(e),n=0;n{let n=e.isOk()?{type:"Ok",value:e.value}:{type:"Err",value:e.error},o=t.withStackTrace?new Error().stack:void 0;return{data:n,message:r,stack:o}};function b(r,e,t,n){function o(s){return s instanceof t?s:new t(function(i){i(s)})}return new(t||(t=Promise))(function(s,i){function a(m){try{v(n.next(m))}catch(_){i(_)}}function l(m){try{v(n.throw(m))}catch(_){i(_)}}function v(m){m.done?s(m.value):o(m.value).then(a,l)}v((n=n.apply(r,e||[])).next())})}function N(r){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&r[e],n=0;if(t)return t.call(r);if(r&&typeof r.length=="number")return{next:function(){return r&&n>=r.length&&(r=void 0),{value:r&&r[n++],done:!r}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function E(r){return this instanceof E?(this.v=r,this):new E(r)}function W(r,e,t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=t.apply(r,e||[]),o,s=[];return o=Object.create((typeof AsyncIterator=="function"?AsyncIterator:Object).prototype),a("next"),a("throw"),a("return",i),o[Symbol.asyncIterator]=function(){return this},o;function i(f){return function(w){return Promise.resolve(w).then(f,_)}}function a(f,w){n[f]&&(o[f]=function(x){return new Promise(function(se,ie){s.push([f,x,se,ie])>1||l(f,x)})},w&&(o[f]=w(o[f])))}function l(f,w){try{v(n[f](w))}catch(x){j(s[0][3],x)}}function v(f){f.value instanceof E?Promise.resolve(f.value.v).then(m,_):j(s[0][2],f)}function m(f){l("next",f)}function _(f){l("throw",f)}function j(f,w){f(w),s.shift(),s.length&&l(s[0][0],s[0][1])}}function Ee(r){var e,t;return e={},n("next"),n("throw",function(o){throw o}),n("return"),e[Symbol.iterator]=function(){return this},e;function n(o,s){e[o]=r[o]?function(i){return(t=!t)?{value:E(r[o](i)),done:!1}:s?s(i):i}:s}}function ye(r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e=r[Symbol.asyncIterator],t;return e?e.call(r):(r=typeof N=="function"?N(r):r[Symbol.iterator](),t={},n("next"),n("throw"),n("return"),t[Symbol.asyncIterator]=function(){return this},t);function n(s){t[s]=r[s]&&function(i){return new Promise(function(a,l){i=r[s](i),o(a,l,i.done,i.value)})}}function o(s,i,a,l){Promise.resolve(l).then(function(v){s({value:v,done:a})},i)}}var p=class r{constructor(e){this._promise=e}static fromSafePromise(e){let t=e.then(n=>new d(n));return new r(t)}static fromPromise(e,t){let n=e.then(o=>new d(o)).catch(o=>new h(t(o)));return new r(n)}static fromThrowable(e,t){return(...n)=>new r(b(this,void 0,void 0,function*(){try{return new d(yield e(...n))}catch(o){return new h(t?t(o):o)}}))}static combine(e){return we(e)}static combineWithAllErrors(e){return Le(e)}map(e){return new r(this._promise.then(t=>b(this,void 0,void 0,function*(){return t.isErr()?new h(t.error):new d(yield e(t.value))})))}andThrough(e){return new r(this._promise.then(t=>b(this,void 0,void 0,function*(){if(t.isErr())return new h(t.error);let n=yield e(t.value);return n.isErr()?new h(n.error):new d(t.value)})))}andTee(e){return new r(this._promise.then(t=>b(this,void 0,void 0,function*(){if(t.isErr())return new h(t.error);try{yield e(t.value)}catch{}return new d(t.value)})))}mapErr(e){return new r(this._promise.then(t=>b(this,void 0,void 0,function*(){return t.isOk()?new d(t.value):new h(yield e(t.error))})))}andThen(e){return new r(this._promise.then(t=>{if(t.isErr())return new h(t.error);let n=e(t.value);return n instanceof r?n._promise:n}))}orElse(e){return new r(this._promise.then(t=>b(this,void 0,void 0,function*(){return t.isErr()?e(t.error):new d(t.value)})))}match(e,t){return this._promise.then(n=>n.match(e,t))}unwrapOr(e){return this._promise.then(t=>t.unwrapOr(e))}safeUnwrap(){return W(this,arguments,function*(){return yield E(yield E(yield*Ee(ye(yield E(this._promise.then(t=>t.safeUnwrap()))))))})}then(e,t){return this._promise.then(e,t)}[Symbol.asyncIterator](){return W(this,arguments,function*(){let t=yield E(this._promise);return t.isErr()&&(yield yield E(k(t.error))),yield E(t.value)})}};var k=r=>new p(Promise.resolve(new h(r))),Ce=p.fromPromise,Fe=p.fromSafePromise,Re=p.fromThrowable,H=r=>{let e=L([]);for(let t of r)if(t.isErr()){e=y(t.error);break}else e.map(n=>n.push(t.value));return e},we=r=>p.fromSafePromise(Promise.all(r)).andThen(H),B=r=>{let e=L([]);for(let t of r)t.isErr()&&e.isErr()?e.error.push(t.error):t.isErr()&&e.isOk()?e=y([t.error]):t.isOk()&&e.isOk()&&e.value.push(t.value);return e},Le=r=>p.fromSafePromise(Promise.all(r)).andThen(B),F;(function(r){function e(o,s){return(...i)=>{try{let a=o(...i);return L(a)}catch(a){return y(s?s(a):a)}}}r.fromThrowable=e;function t(o){return H(o)}r.combine=t;function n(o){return B(o)}r.combineWithAllErrors=n})(F||(F={}));var L=r=>new d(r);function y(r){return new h(r)}var d=class{constructor(e){this.value=e}isOk(){return!0}isErr(){return!this.isOk()}map(e){return L(e(this.value))}mapErr(e){return L(this.value)}andThen(e){return e(this.value)}andThrough(e){return e(this.value).map(t=>this.value)}andTee(e){try{e(this.value)}catch{}return L(this.value)}orElse(e){return L(this.value)}asyncAndThen(e){return e(this.value)}asyncAndThrough(e){return e(this.value).map(()=>this.value)}asyncMap(e){return p.fromSafePromise(e(this.value))}unwrapOr(e){return this.value}match(e,t){return e(this.value)}safeUnwrap(){let e=this.value;return function*(){return e}()}_unsafeUnwrap(e){return this.value}_unsafeUnwrapErr(e){throw J("Called `_unsafeUnwrapErr` on an Ok",this,e)}*[Symbol.iterator](){return this.value}},h=class{constructor(e){this.error=e}isOk(){return!1}isErr(){return!this.isOk()}map(e){return y(this.error)}mapErr(e){return y(e(this.error))}andThrough(e){return y(this.error)}andTee(e){return y(this.error)}andThen(e){return y(this.error)}orElse(e){return e(this.error)}asyncAndThen(e){return k(this.error)}asyncAndThrough(e){return k(this.error)}asyncMap(e){return k(this.error)}unwrapOr(e){return e}match(e,t){return t(this.error)}safeUnwrap(){let e=this.error;return function*(){throw yield y(e),new Error("Do not use this generator out of `safeTry`")}()}_unsafeUnwrap(e){throw J("Called `_unsafeUnwrap` on an Err",this,e)}_unsafeUnwrapErr(e){return this.error}*[Symbol.iterator](){let e=this;return yield e,e}},Ue=F.fromThrowable;var D=class extends Error{constructor(t,n={}){let{cause:o,context:s}=n;super(t,{cause:o});g(this,"context");this.name=this.constructor.name,this.context=s}};var R=r=>{if(r instanceof Error)return r;let e="[Unable to stringify the thrown value]";try{e=JSON.stringify(r)}catch{}return new Error(e)};var _e=()=>typeof Deno<"u";var O=r=>_e()?new URL(`./worker/${r}.ts`,new URL(".",import.meta.url).href):new URL(import.meta.resolve(`./${r==="main"?`worker/${r}`:r}.js`));var te=de(ee());var T=new te.default,c,re=!1;self.onmessage=r=>{Pe(r),re||(re=!0,T.once("OPERATION_FAILED",()=>{c&&c.terminate()}))};var Pe=(r,e)=>{let{action:t}=r.data;if(t===5||t===8)c.postMessage(r.data);else{switch(t){case 2:c=new Worker(O("cancel"),{type:"module"}),c.postMessage(r.data);break;case 3:c=new Worker(O("download"),{type:"module"}),c.postMessage(r.data);break;case 4:c=new Worker(O("infos"),{type:"module"}),c.postMessage(r.data);break;case 7:c=c||new Worker(O("remove"),{type:"module"}),c.postMessage(r.data);break;case 9:c=c||new Worker(O("upload"),{type:"module"}),c.postMessage(r.data);break;default:console.error("Action not found")}c.onmessage=n=>{e&&e(n),self.postMessage(n.data)},c.onerror=n=>{console.error(`Error: ${n.message}`)}}},ne=()=>{T.once("SOCKET_OPENED",()=>{self.postMessage({event:"SOCKET_OPENED"})}),T.once("OPERATION_FAILED",r=>{self.postMessage({event:"OPERATION_FAILED",error:r})})};var I=class extends D{};var S=class extends I{constructor(){super(...arguments);g(this,"message","Failed to remove the file")}};var oe=!1;self.onmessage=r=>{oe||(ne(),oe=!0),Me(r.data).map(()=>{self.postMessage({event:"FILE_REMOVED"})}).mapErr(e=>{self.postMessage({event:"OPERATION_FAILED",error:e})})};var Me=r=>p.fromPromise(new Promise((e,t)=>{let n=r.args.lufiFile;fetch(`${new URL(n.serverUrl).href}d/${n.keys.server}/${n.actionToken}`).then(o=>o.ok?e(void 0):t(new S(void 0,{cause:R(o.statusText)})))}),e=>R(e));