lufi/themes/default/public/js/worker/remove.js

2 lines
14 KiB
JavaScript

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;n<arguments.length;n++)t.push(arguments[n]);var o=e==="error",i=this._events;if(i!==void 0)o=o&&i.error===void 0;else if(!o)return!1;if(o){var s;if(t.length>0&&(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;n<v;++n)W(m[n],this,t);return!0};function $(r,e,t,n){var o,i,s;if(k(t),i=r._events,i===void 0?(i=r._events=Object.create(null),r._eventsCount=0):(i.newListener!==void 0&&(r.emit("newListener",e,t.listener?t.listener:t),i=r._events),s=i[e]),s===void 0)s=i[e]=t,++r._eventsCount;else if(typeof s=="function"?s=i[e]=n?[t,s]:[s,t]:n?s.unshift(t):s.push(t),o=J(r),o>0&&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<i.length;++o)s=i[o],s!=="removeListener"&&this.removeAllListeners(s);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(t=n[e],typeof t=="function")this.removeListener(e,t);else if(t!==void 0)for(o=t.length-1;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<e;++n)t[n]=r[n];return t}function Ee(r,e){for(;e+1<r.length;e++)r[e]=r[e+1];r.pop()}function we(r){for(var e=new Array(r.length),t=0;t<e.length;++t)e[t]=r[t].listener||r[t];return e}function Le(r,e){return new Promise(function(t,n){function o(s){r.removeListener(e,i),n(s)}function i(){typeof r.removeListener=="function"&&r.removeListener("error",o),t([].slice.call(arguments))}z(r,e,i,{once:!0}),e!=="error"&&ge(r,o,{once:!0})})}function ge(r,e,t){typeof r.on=="function"&&z(r,"error",e,t)}function z(r,e,t,n){if(typeof r.on=="function")n.once?r.once(e,t):r.on(e,t);else if(typeof r.addEventListener=="function")r.addEventListener(e,function o(i){n.once&&r.removeEventListener(e,o),t(i)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof r)}});var ae={withStackTrace:!1},C=(r,e,t=ae)=>{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));