diff --git a/crates/librqbit/webui/dist/assets/index.js b/crates/librqbit/webui/dist/assets/index.js index 2238725..ed57a3d 100644 --- a/crates/librqbit/webui/dist/assets/index.js +++ b/crates/librqbit/webui/dist/assets/index.js @@ -41,4 +41,4 @@ Error generating stack: `+o.message+` Copyright (c) 2018 Jed Watson. Licensed under the MIT License (MIT), see http://jedwatson.github.io/classnames -*/(function(e){(function(){var t={}.hasOwnProperty;function n(){for(var r=[],l=0;l=0)&&(n[l]=e[l]);return n}function sa(e){return"default"+e.charAt(0).toUpperCase()+e.substr(1)}function hh(e){var t=vh(e,"string");return typeof t=="symbol"?t:String(t)}function vh(e,t){if(typeof e!="object"||e===null)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||"default");if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}function yh(e,t,n){var r=y.useRef(e!==void 0),l=y.useState(t),o=l[0],i=l[1],u=e!==void 0,s=r.current;return r.current=u,!u&&s&&o!==t&&i(t),[u?e:o,y.useCallback(function(a){for(var m=arguments.length,h=new Array(m>1?m-1:0),d=1;d{o.target===e&&(l(),t(o))},n+r)}function Bh(e){e.offsetHeight}const fa=e=>!e||typeof e=="function"?e:t=>{e.current=t};function Hh(e,t){const n=fa(e),r=fa(t);return l=>{n&&n(l),r&&r(l)}}function mo(e,t){return y.useMemo(()=>Hh(e,t),[e,t])}function Vh(e){return e&&"setState"in e?Tn.findDOMNode(e):e??null}const Wh=Vt.forwardRef(({onEnter:e,onEntering:t,onEntered:n,onExit:r,onExiting:l,onExited:o,addEndListener:i,children:u,childRef:s,...a},m)=>{const h=y.useRef(null),d=mo(h,s),g=E=>{d(Vh(E))},w=E=>N=>{E&&h.current&&E(h.current,N)},k=y.useCallback(w(e),[e]),L=y.useCallback(w(t),[t]),p=y.useCallback(w(n),[n]),c=y.useCallback(w(r),[r]),v=y.useCallback(w(l),[l]),S=y.useCallback(w(o),[o]),T=y.useCallback(w(i),[i]);return f.jsx(zh,{ref:m,...a,onEnter:k,onEntered:p,onEntering:L,onExit:c,onExited:S,onExiting:v,addEndListener:T,nodeRef:h,children:typeof u=="function"?(E,N)=>u(E,{...N,ref:g}):Vt.cloneElement(u,{ref:g})})}),Qh=Wh;function Kh(e){const t=y.useRef(e);return y.useEffect(()=>{t.current=e},[e]),t}function Me(e){const t=Kh(e);return y.useCallback(function(...n){return t.current&&t.current(...n)},[t])}const Yf=e=>y.forwardRef((t,n)=>f.jsx("div",{...t,ref:n,className:M(t.className,e)})),Xf=Yf("h4");Xf.displayName="DivStyledAsH4";const Zf=y.forwardRef(({className:e,bsPrefix:t,as:n=Xf,...r},l)=>(t=H(t,"alert-heading"),f.jsx(n,{ref:l,className:M(e,t),...r})));Zf.displayName="AlertHeading";const Gh=Zf;function Yh(){return y.useState(null)}function Xh(){const e=y.useRef(!0),t=y.useRef(()=>e.current);return y.useEffect(()=>(e.current=!0,()=>{e.current=!1}),[]),t.current}function Zh(e){const t=y.useRef(null);return y.useEffect(()=>{t.current=e}),t.current}const Jh=typeof global<"u"&&global.navigator&&global.navigator.product==="ReactNative",qh=typeof document<"u",da=qh||Jh?y.useLayoutEffect:y.useEffect,bh=["as","disabled"];function ev(e,t){if(e==null)return{};var n={},r=Object.keys(e),l,o;for(o=0;o=0)&&(n[l]=e[l]);return n}function tv(e){return!e||e.trim()==="#"}function Hu({tagName:e,disabled:t,href:n,target:r,rel:l,role:o,onClick:i,tabIndex:u=0,type:s}){e||(n!=null||r!=null||l!=null?e="a":e="button");const a={tagName:e};if(e==="button")return[{type:s||"button",disabled:t},a];const m=d=>{if((t||e==="a"&&tv(n))&&d.preventDefault(),t){d.stopPropagation();return}i==null||i(d)},h=d=>{d.key===" "&&(d.preventDefault(),m(d))};return e==="a"&&(n||(n="#"),t&&(n=void 0)),[{role:o??"button",disabled:void 0,tabIndex:t?void 0:u,href:n,target:e==="a"?r:void 0,"aria-disabled":t||void 0,rel:e==="a"?l:void 0,onClick:m,onKeyDown:h},a]}const nv=y.forwardRef((e,t)=>{let{as:n,disabled:r}=e,l=ev(e,bh);const[o,{tagName:i}]=Hu(Object.assign({tagName:n,disabled:r},l));return f.jsx(i,Object.assign({},l,o,{ref:t}))});nv.displayName="Button";const rv=["onKeyDown"];function lv(e,t){if(e==null)return{};var n={},r=Object.keys(e),l,o;for(o=0;o=0)&&(n[l]=e[l]);return n}function ov(e){return!e||e.trim()==="#"}const Jf=y.forwardRef((e,t)=>{let{onKeyDown:n}=e,r=lv(e,rv);const[l]=Hu(Object.assign({tagName:"a"},r)),o=Me(i=>{l.onKeyDown(i),n==null||n(i)});return ov(r.href)||r.role==="button"?f.jsx("a",Object.assign({ref:t},r,l,{onKeyDown:o})):f.jsx("a",Object.assign({ref:t},r,{onKeyDown:n}))});Jf.displayName="Anchor";const iv=Jf,qf=y.forwardRef(({className:e,bsPrefix:t,as:n=iv,...r},l)=>(t=H(t,"alert-link"),f.jsx(n,{ref:l,className:M(e,t),...r})));qf.displayName="AlertLink";const uv=qf,sv={[St]:"show",[Ht]:"show"},bf=y.forwardRef(({className:e,children:t,transitionClasses:n={},onEnter:r,...l},o)=>{const i={in:!1,timeout:300,mountOnEnter:!1,unmountOnExit:!1,appear:!1,...l},u=y.useCallback((s,a)=>{Bh(s),r==null||r(s,a)},[r]);return f.jsx(Qh,{ref:o,addEndListener:Uh,...i,onEnter:u,childRef:t.ref,children:(s,a)=>y.cloneElement(t,{...a,className:M("fade",e,t.props.className,sv[s],n[s])})})});bf.displayName="Fade";const Ql=bf,av={"aria-label":ut.string,onClick:ut.func,variant:ut.oneOf(["white"])},Vu=y.forwardRef(({className:e,variant:t,"aria-label":n="Close",...r},l)=>f.jsx("button",{ref:l,type:"button",className:M("btn-close",t&&`btn-close-${t}`,e),"aria-label":n,...r}));Vu.displayName="CloseButton";Vu.propTypes=av;const ed=Vu,td=y.forwardRef((e,t)=>{const{bsPrefix:n,show:r=!0,closeLabel:l="Close alert",closeVariant:o,className:i,children:u,variant:s="primary",onClose:a,dismissible:m,transition:h=Ql,...d}=gh(e,{show:"onClose"}),g=H(n,"alert"),w=Me(p=>{a&&a(!1,p)}),k=h===!0?Ql:h,L=f.jsxs("div",{role:"alert",...k?void 0:d,ref:t,className:M(i,g,s&&`${g}-${s}`,m&&`${g}-dismissible`),children:[m&&f.jsx(ed,{onClick:w,"aria-label":l,variant:o}),u]});return k?f.jsx(k,{unmountOnExit:!0,...d,ref:void 0,in:r,children:L}):r?L:null});td.displayName="Alert";const pa=Object.assign(td,{Link:uv,Heading:Gh}),nd=y.forwardRef(({as:e,bsPrefix:t,variant:n="primary",size:r,active:l=!1,disabled:o=!1,className:i,...u},s)=>{const a=H(t,"btn"),[m,{tagName:h}]=Hu({tagName:e,disabled:o,...u}),d=h;return f.jsx(d,{...m,...u,ref:s,disabled:o,className:M(i,a,l&&"active",n&&`${a}-${n}`,r&&`${a}-${r}`,u.href&&o&&"disabled")})});nd.displayName="Button";const tn=nd;function cv(e){const t=y.useRef(e);return t.current=e,t}function rd(e){const t=cv(e);y.useEffect(()=>()=>t.current(),[])}function fv(e,t){let n=0;return y.Children.map(e,r=>y.isValidElement(r)?t(r,n++):r)}function dv(e,t){return y.Children.toArray(e).some(n=>y.isValidElement(n)&&n.type===t)}function pv({as:e,bsPrefix:t,className:n,...r}){t=H(t,"col");const l=Uf(),o=Bf(),i=[],u=[];return l.forEach(s=>{const a=r[s];delete r[s];let m,h,d;typeof a=="object"&&a!=null?{span:m,offset:h,order:d}=a:m=a;const g=s!==o?`-${s}`:"";m&&i.push(m===!0?`${t}${g}`:`${t}${g}-${m}`),d!=null&&u.push(`order${g}-${d}`),h!=null&&u.push(`offset${g}-${h}`)}),[{...r,className:M(n,...i,...u)},{as:e,bsPrefix:t,spans:i}]}const ld=y.forwardRef((e,t)=>{const[{className:n,...r},{as:l="div",bsPrefix:o,spans:i}]=pv(e);return f.jsx(l,{...r,ref:t,className:M(n,!i.length&&o)})});ld.displayName="Col";const Wu=ld,od=y.forwardRef(({bsPrefix:e,fluid:t=!1,as:n="div",className:r,...l},o)=>{const i=H(e,"container"),u=typeof t=="string"?`-${t}`:"-fluid";return f.jsx(n,{ref:o,...l,className:M(r,t?`${i}${u}`:i)})});od.displayName="Container";const mv=od;var hv=Function.prototype.bind.call(Function.prototype.call,[].slice);function dn(e,t){return hv(e.querySelectorAll(t))}function ma(e,t){if(e.contains)return e.contains(t);if(e.compareDocumentPosition)return e===t||!!(e.compareDocumentPosition(t)&16)}const vv="data-rr-ui-";function yv(e){return`${vv}${e}`}const id=y.createContext(Wn?window:void 0);id.Provider;function Qu(){return y.useContext(id)}const gv={type:ut.string,tooltip:ut.bool,as:ut.elementType},Ku=y.forwardRef(({as:e="div",className:t,type:n="valid",tooltip:r=!1,...l},o)=>f.jsx(e,{...l,ref:o,className:M(t,`${n}-${r?"tooltip":"feedback"}`)}));Ku.displayName="Feedback";Ku.propTypes=gv;const ud=Ku,wv=y.createContext({}),dt=wv,sd=y.forwardRef(({id:e,bsPrefix:t,className:n,type:r="checkbox",isValid:l=!1,isInvalid:o=!1,as:i="input",...u},s)=>{const{controlId:a}=y.useContext(dt);return t=H(t,"form-check-input"),f.jsx(i,{...u,ref:s,type:r,id:e||a,className:M(n,t,l&&"is-valid",o&&"is-invalid")})});sd.displayName="FormCheckInput";const ad=sd,cd=y.forwardRef(({bsPrefix:e,className:t,htmlFor:n,...r},l)=>{const{controlId:o}=y.useContext(dt);return e=H(e,"form-check-label"),f.jsx("label",{...r,ref:l,htmlFor:n||o,className:M(t,e)})});cd.displayName="FormCheckLabel";const Gi=cd,fd=y.forwardRef(({id:e,bsPrefix:t,bsSwitchPrefix:n,inline:r=!1,reverse:l=!1,disabled:o=!1,isValid:i=!1,isInvalid:u=!1,feedbackTooltip:s=!1,feedback:a,feedbackType:m,className:h,style:d,title:g="",type:w="checkbox",label:k,children:L,as:p="input",...c},v)=>{t=H(t,"form-check"),n=H(n,"form-switch");const{controlId:S}=y.useContext(dt),T=y.useMemo(()=>({controlId:e||S}),[S,e]),E=!L&&k!=null&&k!==!1||dv(L,Gi),N=f.jsx(ad,{...c,type:w==="switch"?"checkbox":w,ref:v,isValid:i,isInvalid:u,disabled:o,as:p});return f.jsx(dt.Provider,{value:T,children:f.jsx("div",{style:d,className:M(h,E&&t,r&&`${t}-inline`,l&&`${t}-reverse`,w==="switch"&&n),children:L||f.jsxs(f.Fragment,{children:[N,E&&f.jsx(Gi,{title:g,children:k}),a&&f.jsx(ud,{type:m,tooltip:s,children:a})]})})})});fd.displayName="FormCheck";const Kl=Object.assign(fd,{Input:ad,Label:Gi}),dd=y.forwardRef(({bsPrefix:e,type:t,size:n,htmlSize:r,id:l,className:o,isValid:i=!1,isInvalid:u=!1,plaintext:s,readOnly:a,as:m="input",...h},d)=>{const{controlId:g}=y.useContext(dt);return e=H(e,"form-control"),f.jsx(m,{...h,type:t,size:r,ref:d,readOnly:a,id:l||g,className:M(o,s?`${e}-plaintext`:e,n&&`${e}-${n}`,t==="color"&&`${e}-color`,i&&"is-valid",u&&"is-invalid")})});dd.displayName="FormControl";const Sv=Object.assign(dd,{Feedback:ud}),pd=y.forwardRef(({className:e,bsPrefix:t,as:n="div",...r},l)=>(t=H(t,"form-floating"),f.jsx(n,{ref:l,className:M(e,t),...r})));pd.displayName="FormFloating";const xv=pd,md=y.forwardRef(({controlId:e,as:t="div",...n},r)=>{const l=y.useMemo(()=>({controlId:e}),[e]);return f.jsx(dt.Provider,{value:l,children:f.jsx(t,{...n,ref:r})})});md.displayName="FormGroup";const hd=md,vd=y.forwardRef(({as:e="label",bsPrefix:t,column:n=!1,visuallyHidden:r=!1,className:l,htmlFor:o,...i},u)=>{const{controlId:s}=y.useContext(dt);t=H(t,"form-label");let a="col-form-label";typeof n=="string"&&(a=`${a} ${a}-${n}`);const m=M(l,t,r&&"visually-hidden",n&&a);return o=o||s,n?f.jsx(Wu,{ref:u,as:"label",className:m,htmlFor:o,...i}):f.jsx(e,{ref:u,className:m,htmlFor:o,...i})});vd.displayName="FormLabel";const kv=vd,yd=y.forwardRef(({bsPrefix:e,className:t,id:n,...r},l)=>{const{controlId:o}=y.useContext(dt);return e=H(e,"form-range"),f.jsx("input",{...r,type:"range",ref:l,className:M(t,e),id:n||o})});yd.displayName="FormRange";const Ev=yd,gd=y.forwardRef(({bsPrefix:e,size:t,htmlSize:n,className:r,isValid:l=!1,isInvalid:o=!1,id:i,...u},s)=>{const{controlId:a}=y.useContext(dt);return e=H(e,"form-select"),f.jsx("select",{...u,size:n,ref:s,className:M(r,e,t&&`${e}-${t}`,l&&"is-valid",o&&"is-invalid"),id:i||a})});gd.displayName="FormSelect";const Cv=gd,wd=y.forwardRef(({bsPrefix:e,className:t,as:n="small",muted:r,...l},o)=>(e=H(e,"form-text"),f.jsx(n,{...l,ref:o,className:M(t,e,r&&"text-muted")})));wd.displayName="FormText";const Nv=wd,Sd=y.forwardRef((e,t)=>f.jsx(Kl,{...e,ref:t,type:"switch"}));Sd.displayName="Switch";const Tv=Object.assign(Sd,{Input:Kl.Input,Label:Kl.Label}),xd=y.forwardRef(({bsPrefix:e,className:t,children:n,controlId:r,label:l,...o},i)=>(e=H(e,"form-floating"),f.jsxs(hd,{ref:i,className:M(t,e),controlId:r,...o,children:[n,f.jsx("label",{htmlFor:r,children:l})]})));xd.displayName="FloatingLabel";const _v=xd,jv={_ref:ut.any,validated:ut.bool,as:ut.elementType},Gu=y.forwardRef(({className:e,validated:t,as:n="form",...r},l)=>f.jsx(n,{...r,ref:l,className:M(e,t&&"was-validated")}));Gu.displayName="Form";Gu.propTypes=jv;const pe=Object.assign(Gu,{Group:hd,Control:Sv,Floating:xv,Check:Kl,Switch:Tv,Label:kv,Text:Nv,Range:Ev,Select:Cv,FloatingLabel:_v});var ul;function ha(e){if((!ul&&ul!==0||e)&&Wn){var t=document.createElement("div");t.style.position="absolute",t.style.top="-9999px",t.style.width="50px",t.style.height="50px",t.style.overflow="scroll",document.body.appendChild(t),ul=t.offsetWidth-t.clientWidth,document.body.removeChild(t)}return ul}function Vo(e){e===void 0&&(e=po());try{var t=e.activeElement;return!t||!t.nodeName?null:t}catch{return e.body}}function Lv(e=document){const t=e.defaultView;return Math.abs(t.innerWidth-e.documentElement.clientWidth)}const va=yv("modal-open");class Rv{constructor({ownerDocument:t,handleContainerOverflow:n=!0,isRTL:r=!1}={}){this.handleContainerOverflow=n,this.isRTL=r,this.modals=[],this.ownerDocument=t}getScrollbarWidth(){return Lv(this.ownerDocument)}getElement(){return(this.ownerDocument||document).body}setModalAttributes(t){}removeModalAttributes(t){}setContainerStyle(t){const n={overflow:"hidden"},r=this.isRTL?"paddingLeft":"paddingRight",l=this.getElement();t.style={overflow:l.style.overflow,[r]:l.style[r]},t.scrollBarWidth&&(n[r]=`${parseInt(Xt(l,r)||"0",10)+t.scrollBarWidth}px`),l.setAttribute(va,""),Xt(l,n)}reset(){[...this.modals].forEach(t=>this.remove(t))}removeContainerStyle(t){const n=this.getElement();n.removeAttribute(va),Object.assign(n.style,t.style)}add(t){let n=this.modals.indexOf(t);return n!==-1||(n=this.modals.length,this.modals.push(t),this.setModalAttributes(t),n!==0)||(this.state={scrollBarWidth:this.getScrollbarWidth(),style:{}},this.handleContainerOverflow&&this.setContainerStyle(this.state)),n}remove(t){const n=this.modals.indexOf(t);n!==-1&&(this.modals.splice(n,1),!this.modals.length&&this.handleContainerOverflow&&this.removeContainerStyle(this.state),this.removeModalAttributes(t))}isTopModal(t){return!!this.modals.length&&this.modals[this.modals.length-1]===t}}const Yu=Rv,Wo=(e,t)=>Wn?e==null?(t||po()).body:(typeof e=="function"&&(e=e()),e&&"current"in e&&(e=e.current),e&&("nodeType"in e||e.getBoundingClientRect)?e:null):null;function Ov(e,t){const n=Qu(),[r,l]=y.useState(()=>Wo(e,n==null?void 0:n.document));if(!r){const o=Wo(e);o&&l(o)}return y.useEffect(()=>{t&&r&&t(r)},[t,r]),y.useEffect(()=>{const o=Wo(e);o!==r&&l(o)},[e,r]),r}function Pv({children:e,in:t,onExited:n,mountOnEnter:r,unmountOnExit:l}){const o=y.useRef(null),i=y.useRef(t),u=Me(n);y.useEffect(()=>{t?i.current=!0:u(o.current)},[t,u]);const s=mo(o,e.ref),a=y.cloneElement(e,{ref:s});return t?a:l||!i.current&&r?null:a}function Fv({in:e,onTransition:t}){const n=y.useRef(null),r=y.useRef(!0),l=Me(t);return da(()=>{if(!n.current)return;let o=!1;return l({in:e,element:n.current,initial:r.current,isStale:()=>o}),()=>{o=!0}},[e,l]),da(()=>(r.current=!1,()=>{r.current=!0}),[]),n}function Mv({children:e,in:t,onExited:n,onEntered:r,transition:l}){const[o,i]=y.useState(!t);t&&o&&i(!1);const u=Fv({in:!!t,onTransition:a=>{const m=()=>{a.isStale()||(a.in?r==null||r(a.element,a.initial):(i(!0),n==null||n(a.element)))};Promise.resolve(l(a)).then(m,h=>{throw a.in||i(!0),h})}}),s=mo(u,e.ref);return o&&!t?null:y.cloneElement(e,{ref:s})}function ya(e,t,n){return e?f.jsx(e,Object.assign({},n)):t?f.jsx(Mv,Object.assign({},n,{transition:t})):f.jsx(Pv,Object.assign({},n))}function $v(e){return e.code==="Escape"||e.keyCode===27}const zv=["show","role","className","style","children","backdrop","keyboard","onBackdropClick","onEscapeKeyDown","transition","runTransition","backdropTransition","runBackdropTransition","autoFocus","enforceFocus","restoreFocus","restoreFocusOptions","renderDialog","renderBackdrop","manager","container","onShow","onHide","onExit","onExited","onExiting","onEnter","onEntering","onEntered"];function Iv(e,t){if(e==null)return{};var n={},r=Object.keys(e),l,o;for(o=0;o=0)&&(n[l]=e[l]);return n}let Qo;function Dv(e){return Qo||(Qo=new Yu({ownerDocument:e==null?void 0:e.document})),Qo}function Av(e){const t=Qu(),n=e||Dv(t),r=y.useRef({dialog:null,backdrop:null});return Object.assign(r.current,{add:()=>n.add(r.current),remove:()=>n.remove(r.current),isTopModal:()=>n.isTopModal(r.current),setDialogRef:y.useCallback(l=>{r.current.dialog=l},[]),setBackdropRef:y.useCallback(l=>{r.current.backdrop=l},[])})}const kd=y.forwardRef((e,t)=>{let{show:n=!1,role:r="dialog",className:l,style:o,children:i,backdrop:u=!0,keyboard:s=!0,onBackdropClick:a,onEscapeKeyDown:m,transition:h,runTransition:d,backdropTransition:g,runBackdropTransition:w,autoFocus:k=!0,enforceFocus:L=!0,restoreFocus:p=!0,restoreFocusOptions:c,renderDialog:v,renderBackdrop:S=K=>f.jsx("div",Object.assign({},K)),manager:T,container:E,onShow:N,onHide:j=()=>{},onExit:U,onExited:P,onExiting:ie,onEnter:Ke,onEntering:Ge,onEntered:on}=e,Qn=Iv(e,zv);const Le=Qu(),Ye=Ov(E),C=Av(T),R=Xh(),O=Zh(n),[I,A]=y.useState(!n),fe=y.useRef(null);y.useImperativeHandle(t,()=>C,[C]),Wn&&!O&&n&&(fe.current=Vo(Le==null?void 0:Le.document)),n&&I&&A(!1);const Re=Me(()=>{if(C.add(),sn.current=Wl(document,"keydown",ho),un.current=Wl(document,"focus",()=>setTimeout(Oe),!0),N&&N(),k){var K,Hr;const Yn=Vo((K=(Hr=C.dialog)==null?void 0:Hr.ownerDocument)!=null?K:Le==null?void 0:Le.document);C.dialog&&Yn&&!ma(C.dialog,Yn)&&(fe.current=Yn,C.dialog.focus())}}),et=Me(()=>{if(C.remove(),sn.current==null||sn.current(),un.current==null||un.current(),p){var K;(K=fe.current)==null||K.focus==null||K.focus(c),fe.current=null}});y.useEffect(()=>{!n||!Ye||Re()},[n,Ye,Re]),y.useEffect(()=>{I&&et()},[I,et]),rd(()=>{et()});const Oe=Me(()=>{if(!L||!R()||!C.isTopModal())return;const K=Vo(Le==null?void 0:Le.document);C.dialog&&K&&!ma(C.dialog,K)&&C.dialog.focus()}),ht=Me(K=>{K.target===K.currentTarget&&(a==null||a(K),u===!0&&j())}),ho=Me(K=>{s&&$v(K)&&C.isTopModal()&&(m==null||m(K),K.defaultPrevented||j())}),un=y.useRef(),sn=y.useRef(),Kn=(...K)=>{A(!0),P==null||P(...K)};if(!Ye)return null;const Br=Object.assign({role:r,ref:C.setDialogRef,"aria-modal":r==="dialog"?!0:void 0},Qn,{style:o,className:l,tabIndex:-1});let Gn=v?v(Br):f.jsx("div",Object.assign({},Br,{children:y.cloneElement(i,{role:"document"})}));Gn=ya(h,d,{unmountOnExit:!0,mountOnEnter:!0,appear:!0,in:!!n,onExit:U,onExiting:ie,onExited:Kn,onEnter:Ke,onEntering:Ge,onEntered:on,children:Gn});let Dt=null;return u&&(Dt=S({ref:C.setBackdropRef,onClick:ht}),Dt=ya(g,w,{in:!!n,appear:!0,mountOnEnter:!0,unmountOnExit:!0,children:Dt})),f.jsx(f.Fragment,{children:Tn.createPortal(f.jsxs(f.Fragment,{children:[Dt,Gn]}),Ye)})});kd.displayName="Modal";const Uv=Object.assign(kd,{Manager:Yu});function Bv(e,t){return e.classList?!!t&&e.classList.contains(t):(" "+(e.className.baseVal||e.className)+" ").indexOf(" "+t+" ")!==-1}function Hv(e,t){e.classList?e.classList.add(t):Bv(e,t)||(typeof e.className=="string"?e.className=e.className+" "+t:e.setAttribute("class",(e.className&&e.className.baseVal||"")+" "+t))}function ga(e,t){return e.replace(new RegExp("(^|\\s)"+t+"(?:\\s|$)","g"),"$1").replace(/\s+/g," ").replace(/^\s*|\s*$/g,"")}function Vv(e,t){e.classList?e.classList.remove(t):typeof e.className=="string"?e.className=ga(e.className,t):e.setAttribute("class",ga(e.className&&e.className.baseVal||"",t))}const pn={FIXED_CONTENT:".fixed-top, .fixed-bottom, .is-fixed, .sticky-top",STICKY_CONTENT:".sticky-top",NAVBAR_TOGGLER:".navbar-toggler"};class Wv extends Yu{adjustAndStore(t,n,r){const l=n.style[t];n.dataset[t]=l,Xt(n,{[t]:`${parseFloat(Xt(n,t))+r}px`})}restore(t,n){const r=n.dataset[t];r!==void 0&&(delete n.dataset[t],Xt(n,{[t]:r}))}setContainerStyle(t){super.setContainerStyle(t);const n=this.getElement();if(Hv(n,"modal-open"),!t.scrollBarWidth)return;const r=this.isRTL?"paddingLeft":"paddingRight",l=this.isRTL?"marginLeft":"marginRight";dn(n,pn.FIXED_CONTENT).forEach(o=>this.adjustAndStore(r,o,t.scrollBarWidth)),dn(n,pn.STICKY_CONTENT).forEach(o=>this.adjustAndStore(l,o,-t.scrollBarWidth)),dn(n,pn.NAVBAR_TOGGLER).forEach(o=>this.adjustAndStore(l,o,t.scrollBarWidth))}removeContainerStyle(t){super.removeContainerStyle(t);const n=this.getElement();Vv(n,"modal-open");const r=this.isRTL?"paddingLeft":"paddingRight",l=this.isRTL?"marginLeft":"marginRight";dn(n,pn.FIXED_CONTENT).forEach(o=>this.restore(r,o)),dn(n,pn.STICKY_CONTENT).forEach(o=>this.restore(l,o)),dn(n,pn.NAVBAR_TOGGLER).forEach(o=>this.restore(l,o))}}let Ko;function Qv(e){return Ko||(Ko=new Wv(e)),Ko}const Ed=y.forwardRef(({className:e,bsPrefix:t,as:n="div",...r},l)=>(t=H(t,"modal-body"),f.jsx(n,{ref:l,className:M(e,t),...r})));Ed.displayName="ModalBody";const Kv=Ed,Gv=y.createContext({onHide(){}}),Cd=Gv,Nd=y.forwardRef(({bsPrefix:e,className:t,contentClassName:n,centered:r,size:l,fullscreen:o,children:i,scrollable:u,...s},a)=>{e=H(e,"modal");const m=`${e}-dialog`,h=typeof o=="string"?`${e}-fullscreen-${o}`:`${e}-fullscreen`;return f.jsx("div",{...s,ref:a,className:M(m,t,l&&`${e}-${l}`,r&&`${m}-centered`,u&&`${m}-scrollable`,o&&h),children:f.jsx("div",{className:M(`${e}-content`,n),children:i})})});Nd.displayName="ModalDialog";const Td=Nd,_d=y.forwardRef(({className:e,bsPrefix:t,as:n="div",...r},l)=>(t=H(t,"modal-footer"),f.jsx(n,{ref:l,className:M(e,t),...r})));_d.displayName="ModalFooter";const Yv=_d,Xv=y.forwardRef(({closeLabel:e="Close",closeVariant:t,closeButton:n=!1,onHide:r,children:l,...o},i)=>{const u=y.useContext(Cd),s=Me(()=>{u==null||u.onHide(),r==null||r()});return f.jsxs("div",{ref:i,...o,children:[l,n&&f.jsx(ed,{"aria-label":e,variant:t,onClick:s})]})}),Zv=Xv,jd=y.forwardRef(({bsPrefix:e,className:t,closeLabel:n="Close",closeButton:r=!1,...l},o)=>(e=H(e,"modal-header"),f.jsx(Zv,{ref:o,...l,className:M(t,e),closeLabel:n,closeButton:r})));jd.displayName="ModalHeader";const Jv=jd,qv=Yf("h4"),Ld=y.forwardRef(({className:e,bsPrefix:t,as:n=qv,...r},l)=>(t=H(t,"modal-title"),f.jsx(n,{ref:l,className:M(e,t),...r})));Ld.displayName="ModalTitle";const bv=Ld;function ey(e){return f.jsx(Ql,{...e,timeout:null})}function ty(e){return f.jsx(Ql,{...e,timeout:null})}const Rd=y.forwardRef(({bsPrefix:e,className:t,style:n,dialogClassName:r,contentClassName:l,children:o,dialogAs:i=Td,"aria-labelledby":u,"aria-describedby":s,"aria-label":a,show:m=!1,animation:h=!0,backdrop:d=!0,keyboard:g=!0,onEscapeKeyDown:w,onShow:k,onHide:L,container:p,autoFocus:c=!0,enforceFocus:v=!0,restoreFocus:S=!0,restoreFocusOptions:T,onEntered:E,onExit:N,onExiting:j,onEnter:U,onEntering:P,onExited:ie,backdropClassName:Ke,manager:Ge,...on},Qn)=>{const[Le,Ye]=y.useState({}),[C,R]=y.useState(!1),O=y.useRef(!1),I=y.useRef(!1),A=y.useRef(null),[fe,Re]=Yh(),et=mo(Qn,Re),Oe=Me(L),ht=kh();e=H(e,"modal");const ho=y.useMemo(()=>({onHide:Oe}),[Oe]);function un(){return Ge||Qv({isRTL:ht})}function sn(z){if(!Wn)return;const an=un().getScrollbarWidth()>0,qu=z.scrollHeight>po(z).documentElement.clientHeight;Ye({paddingRight:an&&!qu?ha():void 0,paddingLeft:!an&&qu?ha():void 0})}const Kn=Me(()=>{fe&&sn(fe.dialog)});rd(()=>{Ki(window,"resize",Kn),A.current==null||A.current()});const Br=()=>{O.current=!0},Gn=z=>{O.current&&fe&&z.target===fe.dialog&&(I.current=!0),O.current=!1},Dt=()=>{R(!0),A.current=Gf(fe.dialog,()=>{R(!1)})},K=z=>{z.target===z.currentTarget&&Dt()},Hr=z=>{if(d==="static"){K(z);return}if(I.current||z.target!==z.currentTarget){I.current=!1;return}L==null||L()},Yn=z=>{g?w==null||w(z):(z.preventDefault(),d==="static"&&Dt())},Dd=(z,an)=>{z&&sn(z),U==null||U(z,an)},Ad=z=>{A.current==null||A.current(),N==null||N(z)},Ud=(z,an)=>{P==null||P(z,an),Kf(window,"resize",Kn)},Bd=z=>{z&&(z.style.display=""),ie==null||ie(z),Ki(window,"resize",Kn)},Hd=y.useCallback(z=>f.jsx("div",{...z,className:M(`${e}-backdrop`,Ke,!h&&"show")}),[h,Ke,e]),Ju={...n,...Le};Ju.display="block";const Vd=z=>f.jsx("div",{role:"dialog",...z,style:Ju,className:M(t,e,C&&`${e}-static`,!h&&"show"),onClick:d?Hr:void 0,onMouseUp:Gn,"aria-label":a,"aria-labelledby":u,"aria-describedby":s,children:f.jsx(i,{...on,onMouseDown:Br,className:r,contentClassName:l,children:o})});return f.jsx(Cd.Provider,{value:ho,children:f.jsx(Uv,{show:m,ref:et,backdrop:d,container:p,keyboard:!0,autoFocus:c,enforceFocus:v,restoreFocus:S,restoreFocusOptions:T,onEscapeKeyDown:Yn,onShow:k,onHide:L,onEnter:Dd,onEntering:Ud,onEntered:E,onExit:Ad,onExiting:j,onExited:Bd,manager:un(),transition:h?ey:void 0,backdropTransition:h?ty:void 0,renderBackdrop:Hd,renderDialog:Vd})})});Rd.displayName="Modal";const ge=Object.assign(Rd,{Body:Kv,Header:Jv,Title:bv,Footer:Yv,Dialog:Td,TRANSITION_DURATION:300,BACKDROP_TRANSITION_DURATION:150}),wa=1e3;function ny(e,t,n){const r=(e-t)/(n-t)*100;return Math.round(r*wa)/wa}function Sa({min:e,now:t,max:n,label:r,visuallyHidden:l,striped:o,animated:i,className:u,style:s,variant:a,bsPrefix:m,...h},d){return f.jsx("div",{ref:d,...h,role:"progressbar",className:M(u,`${m}-bar`,{[`bg-${a}`]:a,[`${m}-bar-animated`]:i,[`${m}-bar-striped`]:i||o}),style:{width:`${ny(t,e,n)}%`,...s},"aria-valuenow":t,"aria-valuemin":e,"aria-valuemax":n,children:l?f.jsx("span",{className:"visually-hidden",children:r}):r})}const Od=y.forwardRef(({isChild:e=!1,...t},n)=>{const r={min:0,max:100,animated:!1,visuallyHidden:!1,striped:!1,...t};if(r.bsPrefix=H(r.bsPrefix,"progress"),e)return Sa(r,n);const{min:l,now:o,max:i,label:u,visuallyHidden:s,striped:a,animated:m,bsPrefix:h,variant:d,className:g,children:w,...k}=r;return f.jsx("div",{ref:n,...k,className:M(g,h),children:w?fv(w,L=>y.cloneElement(L,{isChild:!0})):Sa({min:l,now:o,max:i,label:u,visuallyHidden:s,striped:a,animated:m,bsPrefix:h,variant:d},n)})});Od.displayName="ProgressBar";const ry=Od,Pd=y.forwardRef(({bsPrefix:e,className:t,as:n="div",...r},l)=>{const o=H(e,"row"),i=Uf(),u=Bf(),s=`${o}-cols`,a=[];return i.forEach(m=>{const h=r[m];delete r[m];let d;h!=null&&typeof h=="object"?{cols:d}=h:d=h;const g=m!==u?`-${m}`:"";d!=null&&a.push(`${s}${g}-${d}`)}),f.jsx(n,{ref:l,...r,className:M(t,o,...a)})});Pd.displayName="Row";const Fd=Pd,Md=y.forwardRef(({bsPrefix:e,variant:t,animation:n="border",size:r,as:l="div",className:o,...i},u)=>{e=H(e,"spinner");const s=`${e}-${n}`;return f.jsx(l,{ref:u,...i,className:M(o,s,r&&`${s}-${r}`,t&&`text-${t}`)})});Md.displayName="Spinner";const Un=Md,Gl="initializing",$d="paused",zd="live",ly="error";function Xu(e,t){let n,r=t;const l=async()=>{if(r=await e(),r==null)throw"asyncCallback returned null or undefined";o()};let o=()=>{n=setTimeout(l,r)};return o(),()=>{clearTimeout(n)}}function oy(e,t){let n;const r=async()=>{await e().then(()=>!1,()=>!0)&&l()};let l=o=>{n=setTimeout(r,o!==void 0?o:t)};return l(0),()=>clearTimeout(n)}const Go=({className:e,onClick:t,disabled:n,color:r})=>{const l=o=>{o.stopPropagation(),!n&&t()};return f.jsx("a",{className:`bi ${e} p-1`,onClick:l,href:"#"})},Mr=e=>{var r,l,o;let{error:t,remove:n}=e;return t==null?null:f.jsxs(pa,{variant:"danger",onClose:n,dismissible:n!=null,children:[f.jsx(pa.Heading,{children:t.text}),((r=t.details)==null?void 0:r.statusText)&&f.jsx("p",{children:f.jsx("strong",{children:(l=t.details)==null?void 0:l.statusText})}),f.jsx("pre",{children:(o=t.details)==null?void 0:o.text})]})},iy=({id:e,show:t,onHide:n})=>{if(!t)return null;const[r,l]=y.useState(!1),[o,i]=y.useState(null),[u,s]=y.useState(!1),a=y.useContext(Ur),m=y.useContext(ln),h=()=>{l(!1),i(null),s(!1),n()},d=()=>{s(!0),(r?m.delete:m.forget)(e).then(()=>{a.refreshTorrents(),h()}).catch(w=>{i({text:`Error deleting torrent id=${e}`,details:w}),s(!1)})};return f.jsxs(ge,{show:t,onHide:h,children:[f.jsx(ge.Header,{closeButton:!0,children:"Delete torrent"}),f.jsxs(ge.Body,{children:[f.jsx(pe,{children:f.jsx(pe.Group,{controlId:"delete-torrent",children:f.jsx(pe.Check,{type:"checkbox",label:"Also delete files",checked:r,onChange:()=>l(!r)})})}),o&&f.jsx(Mr,{error:o})]}),f.jsxs(ge.Footer,{children:[u&&f.jsx(Un,{}),f.jsx(tn,{variant:"primary",onClick:d,disabled:u,children:"OK"}),f.jsx(tn,{variant:"secondary",onClick:h,children:"Cancel"})]})]})},uy=({id:e,statsResponse:t})=>{let n=t.state,[r,l]=y.useState(!1),[o,i]=y.useState(!1),u=y.useContext(If);const s=n=="live",a=n=="paused"||n=="error",m=y.useContext(Ur),h=y.useContext(ln),d=()=>{l(!0),h.start(e).then(()=>{u.refresh()},L=>{m.setCloseableError({text:`Error starting torrent id=${e}`,details:L})}).finally(()=>l(!1))},g=()=>{l(!0),h.pause(e).then(()=>{u.refresh()},L=>{m.setCloseableError({text:`Error pausing torrent id=${e}`,details:L})}).finally(()=>l(!1))},w=()=>{l(!0),i(!0)},k=()=>{l(!1),i(!1)};return f.jsx(Fd,{children:f.jsxs(Wu,{children:[a&&f.jsx(Go,{className:"bi-play-circle",onClick:d,disabled:r,color:"success"}),s&&f.jsx(Go,{className:"bi-pause-circle",onClick:g,disabled:r}),f.jsx(Go,{className:"bi-x-circle",onClick:w,disabled:r,color:"danger"}),f.jsx(iy,{id:e,show:o,onHide:k})]})})};function Zu(e){if(e===0)return"0 Bytes";const t=1024,n=["Bytes","KB","MB","GB"],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/Math.pow(t,r)).toFixed(2))+" "+n[r]}const sy=({statsResponse:e})=>{var t,n;switch(e.state){case $d:return"Paused";case Gl:return"Checking files";case ly:return"Error"}return e.state!="live"||e.live===null?e.state:f.jsxs(f.Fragment,{children:[!e.finished&&f.jsxs("div",{className:"download-speed",children:["↓ ",(t=e.live.download_speed)==null?void 0:t.human_readable]}),f.jsxs("div",{className:"upload-speed",children:["↑ ",(n=e.live.upload_speed)==null?void 0:n.human_readable,e.live.snapshot.uploaded_bytes>0&&f.jsxs("span",{children:[" ","(",Zu(e.live.snapshot.uploaded_bytes),")"]})]})]})},yt=({size:e,label:t,children:n})=>f.jsxs(Wu,{md:e||1,className:"py-3",children:[f.jsx("div",{className:"fw-bold",children:t}),n]});function ay(e){return e.files.filter(n=>n.included).reduce((n,r)=>n.length>r.length?n:r).name}function cy(e){const t=Math.floor(e/3600),n=Math.floor(e%3600/60),r=e%60,l=(o,i)=>o>0?`${o}${i}`:"";return t>0?`${l(t,"h")} ${l(n,"m")}`.trim():n>0?`${l(n,"m")} ${l(r,"s")}`.trim():`${l(r,"s")}`.trim()}function fy(e){var n,r,l;let t=(l=(r=(n=e==null?void 0:e.live)==null?void 0:n.time_remaining)==null?void 0:r.duration)==null?void 0:l.secs;return t==null?"N/A":cy(t)}const dy=({id:e,detailsResponse:t,statsResponse:n})=>{const r=(n==null?void 0:n.state)??"",l=n==null?void 0:n.error,o=(n==null?void 0:n.total_bytes)??1,i=(n==null?void 0:n.progress_bytes)??0,u=(n==null?void 0:n.finished)||!1,s=l?100:i/o*100,a=(r==Gl||r==zd)&&!u,m=l?"Error":`${s.toFixed(2)}%`,h=l?"danger":u?"success":r==Gl?"warning":"primary",d=()=>{var k;let w=(k=n==null?void 0:n.live)==null?void 0:k.snapshot.peer_stats;return w?`${w.live} / ${w.seen}`:""};let g=[];return l?g.push("bg-warning"):e%2==0&&g.push("bg-light"),f.jsxs(Fd,{className:g.join(" "),children:[f.jsx(yt,{size:3,label:"Name",children:t?f.jsxs(f.Fragment,{children:[f.jsx("div",{className:"text-truncate",children:ay(t)}),l&&f.jsxs("p",{className:"text-danger",children:[f.jsx("strong",{children:"Error:"})," ",l]})]}):f.jsx(Un,{})}),n?f.jsxs(f.Fragment,{children:[f.jsx(yt,{label:"Size",children:`${Zu(o)} `}),f.jsx(yt,{size:2,label:(r==$d,"Progress"),children:f.jsx(ry,{now:s,label:m,animated:a,variant:h})}),f.jsx(yt,{size:2,label:"Speed",children:f.jsx(sy,{statsResponse:n})}),f.jsx(yt,{label:"ETA",children:fy(n)}),f.jsx(yt,{size:2,label:"Live / Seen",children:d()}),f.jsx(yt,{label:"Actions",children:f.jsx(uy,{id:e,statsResponse:n})})]}):f.jsx(yt,{label:"Loading stats",size:8,children:f.jsx(Un,{})})]})},py=({id:e,torrent:t})=>{const[n,r]=y.useState(null),[l,o]=y.useState(null),[i,u]=y.useState(0),s=y.useContext(ln),a=()=>{u(i+1)};return y.useEffect(()=>{if(n===null)return oy(async()=>{await s.getTorrentDetails(t.id).then(r)},1e3)},[n]),y.useEffect(()=>Xu(async()=>s.getTorrentStats(t.id).then(g=>(o(g),g)).then(g=>g.state==Gl||g.state==zd?1e3:1e4,()=>1e4),0),[i]),f.jsx(If.Provider,{value:{refresh:a},children:f.jsx(dy,{id:e,detailsResponse:n,statsResponse:l})})},my=e=>{if(e.torrents===null&&e.loading)return f.jsx(Un,{});if(e.torrents!==null)return e.torrents.length===0?f.jsx("div",{className:"text-center",children:f.jsx("p",{children:"No existing torrents found. Add them through buttons below."})}):f.jsx("div",{style:{fontSize:"smaller"},children:e.torrents.map(t=>f.jsx(py,{id:t.id,torrent:t},t.id))})},hy=e=>{let{onHide:t,listTorrentResponse:n,listTorrentError:r,listTorrentLoading:l,data:o}=e;const[i,u]=y.useState([]),[s,a]=y.useState(!1),[m,h]=y.useState(null),[d,g]=y.useState(!1),[w,k]=y.useState(""),L=y.useContext(Ur),p=y.useContext(ln);y.useEffect(()=>{console.log(n),u(n?n.details.files.map((E,N)=>N):[]),k((n==null?void 0:n.output_folder)||"")},[n]);const c=()=>{t(),u([]),h(null),a(!1)},v=E=>{i.includes(E)?u(i.filter(N=>N!==E)):u([...i,E])},S=async()=>{if(!n)return;a(!0);let E=n.seen_peers?n.seen_peers.slice(0,32):null,N={overwrite:!0,only_files:i,initial_peers:E,output_folder:w};d&&(N.peer_opts={connect_timeout:20,read_write_timeout:60}),p.uploadTorrent(o,N).then(()=>{t(),L.refreshTorrents()},j=>{h({text:"Error starting torrent",details:j})}).finally(()=>a(!1))},T=()=>{if(l)return f.jsx(Un,{});if(r)return f.jsx(Mr,{error:r});if(n)return f.jsxs(pe,{children:[f.jsxs("fieldset",{className:"mb-4",children:[f.jsx("legend",{children:"Pick the files to download"}),n.details.files.map((E,N)=>f.jsx(pe.Group,{controlId:`check-${N}`,children:f.jsx(pe.Check,{type:"checkbox",label:`${E.name} (${Zu(E.length)})`,checked:i.includes(N),onChange:()=>v(N)})},N))]}),f.jsxs("fieldset",{children:[f.jsx("legend",{children:"Options"}),f.jsxs(pe.Group,{controlId:"output-folder",className:"mb-3",children:[f.jsx(pe.Label,{children:"Output folder"}),f.jsx(pe.Control,{type:"text",value:w,onChange:E=>k(E.target.value)})]}),f.jsxs(pe.Group,{controlId:"unpopular-torrent",className:"mb-3",children:[f.jsx(pe.Check,{type:"checkbox",label:"Increase timeouts",checked:d,onChange:()=>g(!d)}),f.jsx("small",{id:"emailHelp",className:"form-text text-muted",children:"This might be useful for unpopular torrents with few peers. It will slow down fast torrents though."})]})]})]})};return f.jsxs(ge,{show:!0,onHide:c,size:"lg",children:[f.jsx(ge.Header,{closeButton:!0,children:f.jsx(ge.Title,{children:"Add torrent"})}),f.jsxs(ge.Body,{children:[T(),f.jsx(Mr,{error:m})]}),f.jsxs(ge.Footer,{children:[s&&f.jsx(Un,{}),f.jsx(tn,{variant:"primary",onClick:S,disabled:l||s||i.length==0,children:"OK"}),f.jsx(tn,{variant:"secondary",onClick:c,children:"Cancel"})]})]})},Id=({buttonText:e,onClick:t,data:n,resetData:r,variant:l})=>{const[o,i]=y.useState(!1),[u,s]=y.useState(null),[a,m]=y.useState(null),h=y.useContext(ln);y.useEffect(()=>{if(n===null)return;let g=setTimeout(async()=>{i(!0);try{const w=await h.uploadTorrent(n,{list_only:!0});s(w)}catch(w){m({text:"Error listing torrent files",details:w})}finally{i(!1)}},0);return()=>clearTimeout(g)},[n]);const d=()=>{r(),m(null),s(null),i(!1)};return f.jsxs(f.Fragment,{children:[f.jsx(tn,{variant:l,onClick:t,className:"m-1",children:e}),n&&f.jsx(hy,{onHide:d,listTorrentError:a,listTorrentResponse:u,data:n,listTorrentLoading:o})]})},vy=({show:e,setUrl:t,cancel:n})=>{let[r,l]=y.useState("");return f.jsxs(ge,{show:e,onHide:n,size:"lg",children:[f.jsx(ge.Header,{closeButton:!0,children:f.jsx(ge.Title,{children:"Add torrent"})}),f.jsx(ge.Body,{children:f.jsx(pe,{children:f.jsxs(pe.Group,{className:"mb-3",controlId:"url",children:[f.jsx(pe.Label,{children:"Enter magnet or HTTP(S) URL to the .torrent"}),f.jsx(pe.Control,{value:r,placeholder:"magnet:?xt=urn:btih:...",onChange:o=>{l(o.target.value)}})]})})}),f.jsxs(ge.Footer,{children:[f.jsx(tn,{variant:"primary",onClick:()=>{t(r),l("")},disabled:r.length==0,children:"OK"}),f.jsx(tn,{variant:"secondary",onClick:n,children:"Cancel"})]})]})},yy=()=>{let[e,t]=y.useState(null),[n,r]=y.useState(!1);return f.jsxs(f.Fragment,{children:[f.jsx(Id,{variant:"primary",buttonText:"Add Torrent from Magnet / URL",onClick:()=>{r(!0)},data:e,resetData:()=>t(null)}),f.jsx(vy,{show:n,setUrl:l=>{r(!1),t(l)},cancel:()=>{r(!1),t(null)}})]})},gy=()=>{const e=y.useRef(),[t,n]=y.useState(null),r=async()=>{var u;if(!((u=e==null?void 0:e.current)!=null&&u.files))return;const i=e.current.files[0];n(i)},l=()=>{e!=null&&e.current&&(e.current.value="",n(null))},o=()=>{e!=null&&e.current&&e.current.click()};return f.jsxs(f.Fragment,{children:[f.jsx("input",{type:"file",ref:e,accept:".torrent",onChange:r,className:"d-none"}),f.jsx(Id,{variant:"secondary",buttonText:"Upload .torrent File",onClick:o,data:t,resetData:l})]})},wy=()=>f.jsxs("div",{id:"buttons-container",className:"mt-3",children:[f.jsx(yy,{}),f.jsx(gy,{})]}),Sy=e=>{let t=y.useContext(Ur);return f.jsxs(mv,{children:[f.jsx(Mr,{error:e.closeableError,remove:()=>t.setCloseableError(null)}),f.jsx(Mr,{error:e.otherError}),f.jsx(my,{torrents:e.torrents,loading:e.torrentsLoading}),f.jsx(wy,{})]})},xy=e=>{const[t,n]=y.useState(null),[r,l]=y.useState(null),[o,i]=y.useState(null),[u,s]=y.useState(!1),a=y.useContext(ln),m=async()=>{s(!0);let d=await a.listTorrents().finally(()=>s(!1));i(d.torrents)};y.useEffect(()=>Xu(async()=>m().then(()=>(l(null),5e3),d=>(l({text:"Error refreshing torrents",details:d}),console.error(d),5e3)),0),[]);const h={setCloseableError:n,refreshTorrents:m};return f.jsx(Ur.Provider,{value:h,children:f.jsxs("div",{className:"text-center",children:[f.jsx("h1",{className:"mt-3 mb-4",children:e.title}),f.jsx(Sy,{closeableError:t,otherError:r,torrents:o,torrentsLoading:u})]})})},ky=window.origin==="null"||window.origin==="http://localhost:3031"?"http://localhost:3030":"",tt=async(e,t,n)=>{console.log(e,t);const r=ky+t,l={method:e,headers:{Accept:"application/json"},body:n};let o={method:e,path:t,text:""},i;try{i=await fetch(r,l)}catch{return o.text="network error",Promise.reject(o)}if(o.status=i.status,o.statusText=`${i.status} ${i.statusText}`,!i.ok){const s=await i.text();try{const a=JSON.parse(s);o.text=a.human_readable!==void 0?a.human_readable:JSON.stringify(a,null,2)}catch{o.text=s}return Promise.reject(o)}return await i.json()},xa={listTorrents:()=>tt("GET","/torrents"),getTorrentDetails:e=>tt("GET",`/torrents/${e}`),getTorrentStats:e=>tt("GET",`/torrents/${e}/stats/v1`),uploadTorrent:(e,t)=>{var r,l;let n="/torrents?&overwrite=true";return t!=null&&t.list_only&&(n+="&list_only=true"),(t==null?void 0:t.only_files)!=null&&(n+=`&only_files=${t.only_files.join(",")}`),(r=t==null?void 0:t.peer_opts)!=null&&r.connect_timeout&&(n+=`&peer_connect_timeout=${t.peer_opts.connect_timeout}`),(l=t==null?void 0:t.peer_opts)!=null&&l.read_write_timeout&&(n+=`&peer_read_write_timeout=${t.peer_opts.read_write_timeout}`),t!=null&&t.initial_peers&&(n+=`&initial_peers=${t.initial_peers.join(",")}`),t!=null&&t.output_folder&&(n+=`&output_folder=${t.output_folder}`),typeof e=="string"&&(n+="&is_url=true"),tt("POST",n,e)},pause:e=>tt("POST",`/torrents/${e}/pause`),start:e=>tt("POST",`/torrents/${e}/start`),forget:e=>tt("POST",`/torrents/${e}/forget`),delete:e=>tt("POST",`/torrents/${e}/delete`),getVersion:async()=>(await tt("GET","/")).version},Ey=()=>{let[e,t]=y.useState("rqbit web UI");return y.useEffect(()=>Xu(()=>xa.getVersion().then(r=>(t(`rqbit web UI - v${r}`),1e4),r=>1e3),0),[]),f.jsx(y.StrictMode,{children:f.jsx(ln.Provider,{value:xa,children:f.jsx(xy,{title:e})})})};Yo.createRoot(document.getElementById("app")).render(f.jsx(Ey,{})); +*/(function(e){(function(){var t={}.hasOwnProperty;function n(){for(var r=[],l=0;l=0)&&(n[l]=e[l]);return n}function sa(e){return"default"+e.charAt(0).toUpperCase()+e.substr(1)}function hh(e){var t=vh(e,"string");return typeof t=="symbol"?t:String(t)}function vh(e,t){if(typeof e!="object"||e===null)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||"default");if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}function yh(e,t,n){var r=y.useRef(e!==void 0),l=y.useState(t),o=l[0],i=l[1],u=e!==void 0,s=r.current;return r.current=u,!u&&s&&o!==t&&i(t),[u?e:o,y.useCallback(function(a){for(var m=arguments.length,h=new Array(m>1?m-1:0),d=1;d{o.target===e&&(l(),t(o))},n+r)}function Bh(e){e.offsetHeight}const fa=e=>!e||typeof e=="function"?e:t=>{e.current=t};function Hh(e,t){const n=fa(e),r=fa(t);return l=>{n&&n(l),r&&r(l)}}function mo(e,t){return y.useMemo(()=>Hh(e,t),[e,t])}function Vh(e){return e&&"setState"in e?Tn.findDOMNode(e):e??null}const Wh=Vt.forwardRef(({onEnter:e,onEntering:t,onEntered:n,onExit:r,onExiting:l,onExited:o,addEndListener:i,children:u,childRef:s,...a},m)=>{const h=y.useRef(null),d=mo(h,s),g=E=>{d(Vh(E))},w=E=>N=>{E&&h.current&&E(h.current,N)},k=y.useCallback(w(e),[e]),L=y.useCallback(w(t),[t]),p=y.useCallback(w(n),[n]),c=y.useCallback(w(r),[r]),v=y.useCallback(w(l),[l]),S=y.useCallback(w(o),[o]),T=y.useCallback(w(i),[i]);return f.jsx(zh,{ref:m,...a,onEnter:k,onEntered:p,onEntering:L,onExit:c,onExited:S,onExiting:v,addEndListener:T,nodeRef:h,children:typeof u=="function"?(E,N)=>u(E,{...N,ref:g}):Vt.cloneElement(u,{ref:g})})}),Qh=Wh;function Kh(e){const t=y.useRef(e);return y.useEffect(()=>{t.current=e},[e]),t}function Me(e){const t=Kh(e);return y.useCallback(function(...n){return t.current&&t.current(...n)},[t])}const Yf=e=>y.forwardRef((t,n)=>f.jsx("div",{...t,ref:n,className:M(t.className,e)})),Xf=Yf("h4");Xf.displayName="DivStyledAsH4";const Zf=y.forwardRef(({className:e,bsPrefix:t,as:n=Xf,...r},l)=>(t=H(t,"alert-heading"),f.jsx(n,{ref:l,className:M(e,t),...r})));Zf.displayName="AlertHeading";const Gh=Zf;function Yh(){return y.useState(null)}function Xh(){const e=y.useRef(!0),t=y.useRef(()=>e.current);return y.useEffect(()=>(e.current=!0,()=>{e.current=!1}),[]),t.current}function Zh(e){const t=y.useRef(null);return y.useEffect(()=>{t.current=e}),t.current}const Jh=typeof global<"u"&&global.navigator&&global.navigator.product==="ReactNative",qh=typeof document<"u",da=qh||Jh?y.useLayoutEffect:y.useEffect,bh=["as","disabled"];function ev(e,t){if(e==null)return{};var n={},r=Object.keys(e),l,o;for(o=0;o=0)&&(n[l]=e[l]);return n}function tv(e){return!e||e.trim()==="#"}function Hu({tagName:e,disabled:t,href:n,target:r,rel:l,role:o,onClick:i,tabIndex:u=0,type:s}){e||(n!=null||r!=null||l!=null?e="a":e="button");const a={tagName:e};if(e==="button")return[{type:s||"button",disabled:t},a];const m=d=>{if((t||e==="a"&&tv(n))&&d.preventDefault(),t){d.stopPropagation();return}i==null||i(d)},h=d=>{d.key===" "&&(d.preventDefault(),m(d))};return e==="a"&&(n||(n="#"),t&&(n=void 0)),[{role:o??"button",disabled:void 0,tabIndex:t?void 0:u,href:n,target:e==="a"?r:void 0,"aria-disabled":t||void 0,rel:e==="a"?l:void 0,onClick:m,onKeyDown:h},a]}const nv=y.forwardRef((e,t)=>{let{as:n,disabled:r}=e,l=ev(e,bh);const[o,{tagName:i}]=Hu(Object.assign({tagName:n,disabled:r},l));return f.jsx(i,Object.assign({},l,o,{ref:t}))});nv.displayName="Button";const rv=["onKeyDown"];function lv(e,t){if(e==null)return{};var n={},r=Object.keys(e),l,o;for(o=0;o=0)&&(n[l]=e[l]);return n}function ov(e){return!e||e.trim()==="#"}const Jf=y.forwardRef((e,t)=>{let{onKeyDown:n}=e,r=lv(e,rv);const[l]=Hu(Object.assign({tagName:"a"},r)),o=Me(i=>{l.onKeyDown(i),n==null||n(i)});return ov(r.href)||r.role==="button"?f.jsx("a",Object.assign({ref:t},r,l,{onKeyDown:o})):f.jsx("a",Object.assign({ref:t},r,{onKeyDown:n}))});Jf.displayName="Anchor";const iv=Jf,qf=y.forwardRef(({className:e,bsPrefix:t,as:n=iv,...r},l)=>(t=H(t,"alert-link"),f.jsx(n,{ref:l,className:M(e,t),...r})));qf.displayName="AlertLink";const uv=qf,sv={[St]:"show",[Ht]:"show"},bf=y.forwardRef(({className:e,children:t,transitionClasses:n={},onEnter:r,...l},o)=>{const i={in:!1,timeout:300,mountOnEnter:!1,unmountOnExit:!1,appear:!1,...l},u=y.useCallback((s,a)=>{Bh(s),r==null||r(s,a)},[r]);return f.jsx(Qh,{ref:o,addEndListener:Uh,...i,onEnter:u,childRef:t.ref,children:(s,a)=>y.cloneElement(t,{...a,className:M("fade",e,t.props.className,sv[s],n[s])})})});bf.displayName="Fade";const Ql=bf,av={"aria-label":ut.string,onClick:ut.func,variant:ut.oneOf(["white"])},Vu=y.forwardRef(({className:e,variant:t,"aria-label":n="Close",...r},l)=>f.jsx("button",{ref:l,type:"button",className:M("btn-close",t&&`btn-close-${t}`,e),"aria-label":n,...r}));Vu.displayName="CloseButton";Vu.propTypes=av;const ed=Vu,td=y.forwardRef((e,t)=>{const{bsPrefix:n,show:r=!0,closeLabel:l="Close alert",closeVariant:o,className:i,children:u,variant:s="primary",onClose:a,dismissible:m,transition:h=Ql,...d}=gh(e,{show:"onClose"}),g=H(n,"alert"),w=Me(p=>{a&&a(!1,p)}),k=h===!0?Ql:h,L=f.jsxs("div",{role:"alert",...k?void 0:d,ref:t,className:M(i,g,s&&`${g}-${s}`,m&&`${g}-dismissible`),children:[m&&f.jsx(ed,{onClick:w,"aria-label":l,variant:o}),u]});return k?f.jsx(k,{unmountOnExit:!0,...d,ref:void 0,in:r,children:L}):r?L:null});td.displayName="Alert";const pa=Object.assign(td,{Link:uv,Heading:Gh}),nd=y.forwardRef(({as:e,bsPrefix:t,variant:n="primary",size:r,active:l=!1,disabled:o=!1,className:i,...u},s)=>{const a=H(t,"btn"),[m,{tagName:h}]=Hu({tagName:e,disabled:o,...u}),d=h;return f.jsx(d,{...m,...u,ref:s,disabled:o,className:M(i,a,l&&"active",n&&`${a}-${n}`,r&&`${a}-${r}`,u.href&&o&&"disabled")})});nd.displayName="Button";const tn=nd;function cv(e){const t=y.useRef(e);return t.current=e,t}function rd(e){const t=cv(e);y.useEffect(()=>()=>t.current(),[])}function fv(e,t){let n=0;return y.Children.map(e,r=>y.isValidElement(r)?t(r,n++):r)}function dv(e,t){return y.Children.toArray(e).some(n=>y.isValidElement(n)&&n.type===t)}function pv({as:e,bsPrefix:t,className:n,...r}){t=H(t,"col");const l=Uf(),o=Bf(),i=[],u=[];return l.forEach(s=>{const a=r[s];delete r[s];let m,h,d;typeof a=="object"&&a!=null?{span:m,offset:h,order:d}=a:m=a;const g=s!==o?`-${s}`:"";m&&i.push(m===!0?`${t}${g}`:`${t}${g}-${m}`),d!=null&&u.push(`order${g}-${d}`),h!=null&&u.push(`offset${g}-${h}`)}),[{...r,className:M(n,...i,...u)},{as:e,bsPrefix:t,spans:i}]}const ld=y.forwardRef((e,t)=>{const[{className:n,...r},{as:l="div",bsPrefix:o,spans:i}]=pv(e);return f.jsx(l,{...r,ref:t,className:M(n,!i.length&&o)})});ld.displayName="Col";const Wu=ld,od=y.forwardRef(({bsPrefix:e,fluid:t=!1,as:n="div",className:r,...l},o)=>{const i=H(e,"container"),u=typeof t=="string"?`-${t}`:"-fluid";return f.jsx(n,{ref:o,...l,className:M(r,t?`${i}${u}`:i)})});od.displayName="Container";const mv=od;var hv=Function.prototype.bind.call(Function.prototype.call,[].slice);function dn(e,t){return hv(e.querySelectorAll(t))}function ma(e,t){if(e.contains)return e.contains(t);if(e.compareDocumentPosition)return e===t||!!(e.compareDocumentPosition(t)&16)}const vv="data-rr-ui-";function yv(e){return`${vv}${e}`}const id=y.createContext(Wn?window:void 0);id.Provider;function Qu(){return y.useContext(id)}const gv={type:ut.string,tooltip:ut.bool,as:ut.elementType},Ku=y.forwardRef(({as:e="div",className:t,type:n="valid",tooltip:r=!1,...l},o)=>f.jsx(e,{...l,ref:o,className:M(t,`${n}-${r?"tooltip":"feedback"}`)}));Ku.displayName="Feedback";Ku.propTypes=gv;const ud=Ku,wv=y.createContext({}),dt=wv,sd=y.forwardRef(({id:e,bsPrefix:t,className:n,type:r="checkbox",isValid:l=!1,isInvalid:o=!1,as:i="input",...u},s)=>{const{controlId:a}=y.useContext(dt);return t=H(t,"form-check-input"),f.jsx(i,{...u,ref:s,type:r,id:e||a,className:M(n,t,l&&"is-valid",o&&"is-invalid")})});sd.displayName="FormCheckInput";const ad=sd,cd=y.forwardRef(({bsPrefix:e,className:t,htmlFor:n,...r},l)=>{const{controlId:o}=y.useContext(dt);return e=H(e,"form-check-label"),f.jsx("label",{...r,ref:l,htmlFor:n||o,className:M(t,e)})});cd.displayName="FormCheckLabel";const Gi=cd,fd=y.forwardRef(({id:e,bsPrefix:t,bsSwitchPrefix:n,inline:r=!1,reverse:l=!1,disabled:o=!1,isValid:i=!1,isInvalid:u=!1,feedbackTooltip:s=!1,feedback:a,feedbackType:m,className:h,style:d,title:g="",type:w="checkbox",label:k,children:L,as:p="input",...c},v)=>{t=H(t,"form-check"),n=H(n,"form-switch");const{controlId:S}=y.useContext(dt),T=y.useMemo(()=>({controlId:e||S}),[S,e]),E=!L&&k!=null&&k!==!1||dv(L,Gi),N=f.jsx(ad,{...c,type:w==="switch"?"checkbox":w,ref:v,isValid:i,isInvalid:u,disabled:o,as:p});return f.jsx(dt.Provider,{value:T,children:f.jsx("div",{style:d,className:M(h,E&&t,r&&`${t}-inline`,l&&`${t}-reverse`,w==="switch"&&n),children:L||f.jsxs(f.Fragment,{children:[N,E&&f.jsx(Gi,{title:g,children:k}),a&&f.jsx(ud,{type:m,tooltip:s,children:a})]})})})});fd.displayName="FormCheck";const Kl=Object.assign(fd,{Input:ad,Label:Gi}),dd=y.forwardRef(({bsPrefix:e,type:t,size:n,htmlSize:r,id:l,className:o,isValid:i=!1,isInvalid:u=!1,plaintext:s,readOnly:a,as:m="input",...h},d)=>{const{controlId:g}=y.useContext(dt);return e=H(e,"form-control"),f.jsx(m,{...h,type:t,size:r,ref:d,readOnly:a,id:l||g,className:M(o,s?`${e}-plaintext`:e,n&&`${e}-${n}`,t==="color"&&`${e}-color`,i&&"is-valid",u&&"is-invalid")})});dd.displayName="FormControl";const Sv=Object.assign(dd,{Feedback:ud}),pd=y.forwardRef(({className:e,bsPrefix:t,as:n="div",...r},l)=>(t=H(t,"form-floating"),f.jsx(n,{ref:l,className:M(e,t),...r})));pd.displayName="FormFloating";const xv=pd,md=y.forwardRef(({controlId:e,as:t="div",...n},r)=>{const l=y.useMemo(()=>({controlId:e}),[e]);return f.jsx(dt.Provider,{value:l,children:f.jsx(t,{...n,ref:r})})});md.displayName="FormGroup";const hd=md,vd=y.forwardRef(({as:e="label",bsPrefix:t,column:n=!1,visuallyHidden:r=!1,className:l,htmlFor:o,...i},u)=>{const{controlId:s}=y.useContext(dt);t=H(t,"form-label");let a="col-form-label";typeof n=="string"&&(a=`${a} ${a}-${n}`);const m=M(l,t,r&&"visually-hidden",n&&a);return o=o||s,n?f.jsx(Wu,{ref:u,as:"label",className:m,htmlFor:o,...i}):f.jsx(e,{ref:u,className:m,htmlFor:o,...i})});vd.displayName="FormLabel";const kv=vd,yd=y.forwardRef(({bsPrefix:e,className:t,id:n,...r},l)=>{const{controlId:o}=y.useContext(dt);return e=H(e,"form-range"),f.jsx("input",{...r,type:"range",ref:l,className:M(t,e),id:n||o})});yd.displayName="FormRange";const Ev=yd,gd=y.forwardRef(({bsPrefix:e,size:t,htmlSize:n,className:r,isValid:l=!1,isInvalid:o=!1,id:i,...u},s)=>{const{controlId:a}=y.useContext(dt);return e=H(e,"form-select"),f.jsx("select",{...u,size:n,ref:s,className:M(r,e,t&&`${e}-${t}`,l&&"is-valid",o&&"is-invalid"),id:i||a})});gd.displayName="FormSelect";const Cv=gd,wd=y.forwardRef(({bsPrefix:e,className:t,as:n="small",muted:r,...l},o)=>(e=H(e,"form-text"),f.jsx(n,{...l,ref:o,className:M(t,e,r&&"text-muted")})));wd.displayName="FormText";const Nv=wd,Sd=y.forwardRef((e,t)=>f.jsx(Kl,{...e,ref:t,type:"switch"}));Sd.displayName="Switch";const Tv=Object.assign(Sd,{Input:Kl.Input,Label:Kl.Label}),xd=y.forwardRef(({bsPrefix:e,className:t,children:n,controlId:r,label:l,...o},i)=>(e=H(e,"form-floating"),f.jsxs(hd,{ref:i,className:M(t,e),controlId:r,...o,children:[n,f.jsx("label",{htmlFor:r,children:l})]})));xd.displayName="FloatingLabel";const _v=xd,jv={_ref:ut.any,validated:ut.bool,as:ut.elementType},Gu=y.forwardRef(({className:e,validated:t,as:n="form",...r},l)=>f.jsx(n,{...r,ref:l,className:M(e,t&&"was-validated")}));Gu.displayName="Form";Gu.propTypes=jv;const pe=Object.assign(Gu,{Group:hd,Control:Sv,Floating:xv,Check:Kl,Switch:Tv,Label:kv,Text:Nv,Range:Ev,Select:Cv,FloatingLabel:_v});var ul;function ha(e){if((!ul&&ul!==0||e)&&Wn){var t=document.createElement("div");t.style.position="absolute",t.style.top="-9999px",t.style.width="50px",t.style.height="50px",t.style.overflow="scroll",document.body.appendChild(t),ul=t.offsetWidth-t.clientWidth,document.body.removeChild(t)}return ul}function Vo(e){e===void 0&&(e=po());try{var t=e.activeElement;return!t||!t.nodeName?null:t}catch{return e.body}}function Lv(e=document){const t=e.defaultView;return Math.abs(t.innerWidth-e.documentElement.clientWidth)}const va=yv("modal-open");class Rv{constructor({ownerDocument:t,handleContainerOverflow:n=!0,isRTL:r=!1}={}){this.handleContainerOverflow=n,this.isRTL=r,this.modals=[],this.ownerDocument=t}getScrollbarWidth(){return Lv(this.ownerDocument)}getElement(){return(this.ownerDocument||document).body}setModalAttributes(t){}removeModalAttributes(t){}setContainerStyle(t){const n={overflow:"hidden"},r=this.isRTL?"paddingLeft":"paddingRight",l=this.getElement();t.style={overflow:l.style.overflow,[r]:l.style[r]},t.scrollBarWidth&&(n[r]=`${parseInt(Xt(l,r)||"0",10)+t.scrollBarWidth}px`),l.setAttribute(va,""),Xt(l,n)}reset(){[...this.modals].forEach(t=>this.remove(t))}removeContainerStyle(t){const n=this.getElement();n.removeAttribute(va),Object.assign(n.style,t.style)}add(t){let n=this.modals.indexOf(t);return n!==-1||(n=this.modals.length,this.modals.push(t),this.setModalAttributes(t),n!==0)||(this.state={scrollBarWidth:this.getScrollbarWidth(),style:{}},this.handleContainerOverflow&&this.setContainerStyle(this.state)),n}remove(t){const n=this.modals.indexOf(t);n!==-1&&(this.modals.splice(n,1),!this.modals.length&&this.handleContainerOverflow&&this.removeContainerStyle(this.state),this.removeModalAttributes(t))}isTopModal(t){return!!this.modals.length&&this.modals[this.modals.length-1]===t}}const Yu=Rv,Wo=(e,t)=>Wn?e==null?(t||po()).body:(typeof e=="function"&&(e=e()),e&&"current"in e&&(e=e.current),e&&("nodeType"in e||e.getBoundingClientRect)?e:null):null;function Ov(e,t){const n=Qu(),[r,l]=y.useState(()=>Wo(e,n==null?void 0:n.document));if(!r){const o=Wo(e);o&&l(o)}return y.useEffect(()=>{t&&r&&t(r)},[t,r]),y.useEffect(()=>{const o=Wo(e);o!==r&&l(o)},[e,r]),r}function Pv({children:e,in:t,onExited:n,mountOnEnter:r,unmountOnExit:l}){const o=y.useRef(null),i=y.useRef(t),u=Me(n);y.useEffect(()=>{t?i.current=!0:u(o.current)},[t,u]);const s=mo(o,e.ref),a=y.cloneElement(e,{ref:s});return t?a:l||!i.current&&r?null:a}function Fv({in:e,onTransition:t}){const n=y.useRef(null),r=y.useRef(!0),l=Me(t);return da(()=>{if(!n.current)return;let o=!1;return l({in:e,element:n.current,initial:r.current,isStale:()=>o}),()=>{o=!0}},[e,l]),da(()=>(r.current=!1,()=>{r.current=!0}),[]),n}function Mv({children:e,in:t,onExited:n,onEntered:r,transition:l}){const[o,i]=y.useState(!t);t&&o&&i(!1);const u=Fv({in:!!t,onTransition:a=>{const m=()=>{a.isStale()||(a.in?r==null||r(a.element,a.initial):(i(!0),n==null||n(a.element)))};Promise.resolve(l(a)).then(m,h=>{throw a.in||i(!0),h})}}),s=mo(u,e.ref);return o&&!t?null:y.cloneElement(e,{ref:s})}function ya(e,t,n){return e?f.jsx(e,Object.assign({},n)):t?f.jsx(Mv,Object.assign({},n,{transition:t})):f.jsx(Pv,Object.assign({},n))}function $v(e){return e.code==="Escape"||e.keyCode===27}const zv=["show","role","className","style","children","backdrop","keyboard","onBackdropClick","onEscapeKeyDown","transition","runTransition","backdropTransition","runBackdropTransition","autoFocus","enforceFocus","restoreFocus","restoreFocusOptions","renderDialog","renderBackdrop","manager","container","onShow","onHide","onExit","onExited","onExiting","onEnter","onEntering","onEntered"];function Iv(e,t){if(e==null)return{};var n={},r=Object.keys(e),l,o;for(o=0;o=0)&&(n[l]=e[l]);return n}let Qo;function Dv(e){return Qo||(Qo=new Yu({ownerDocument:e==null?void 0:e.document})),Qo}function Av(e){const t=Qu(),n=e||Dv(t),r=y.useRef({dialog:null,backdrop:null});return Object.assign(r.current,{add:()=>n.add(r.current),remove:()=>n.remove(r.current),isTopModal:()=>n.isTopModal(r.current),setDialogRef:y.useCallback(l=>{r.current.dialog=l},[]),setBackdropRef:y.useCallback(l=>{r.current.backdrop=l},[])})}const kd=y.forwardRef((e,t)=>{let{show:n=!1,role:r="dialog",className:l,style:o,children:i,backdrop:u=!0,keyboard:s=!0,onBackdropClick:a,onEscapeKeyDown:m,transition:h,runTransition:d,backdropTransition:g,runBackdropTransition:w,autoFocus:k=!0,enforceFocus:L=!0,restoreFocus:p=!0,restoreFocusOptions:c,renderDialog:v,renderBackdrop:S=K=>f.jsx("div",Object.assign({},K)),manager:T,container:E,onShow:N,onHide:j=()=>{},onExit:U,onExited:P,onExiting:ie,onEnter:Ke,onEntering:Ge,onEntered:on}=e,Qn=Iv(e,zv);const Le=Qu(),Ye=Ov(E),C=Av(T),R=Xh(),O=Zh(n),[I,A]=y.useState(!n),fe=y.useRef(null);y.useImperativeHandle(t,()=>C,[C]),Wn&&!O&&n&&(fe.current=Vo(Le==null?void 0:Le.document)),n&&I&&A(!1);const Re=Me(()=>{if(C.add(),sn.current=Wl(document,"keydown",ho),un.current=Wl(document,"focus",()=>setTimeout(Oe),!0),N&&N(),k){var K,Hr;const Yn=Vo((K=(Hr=C.dialog)==null?void 0:Hr.ownerDocument)!=null?K:Le==null?void 0:Le.document);C.dialog&&Yn&&!ma(C.dialog,Yn)&&(fe.current=Yn,C.dialog.focus())}}),et=Me(()=>{if(C.remove(),sn.current==null||sn.current(),un.current==null||un.current(),p){var K;(K=fe.current)==null||K.focus==null||K.focus(c),fe.current=null}});y.useEffect(()=>{!n||!Ye||Re()},[n,Ye,Re]),y.useEffect(()=>{I&&et()},[I,et]),rd(()=>{et()});const Oe=Me(()=>{if(!L||!R()||!C.isTopModal())return;const K=Vo(Le==null?void 0:Le.document);C.dialog&&K&&!ma(C.dialog,K)&&C.dialog.focus()}),ht=Me(K=>{K.target===K.currentTarget&&(a==null||a(K),u===!0&&j())}),ho=Me(K=>{s&&$v(K)&&C.isTopModal()&&(m==null||m(K),K.defaultPrevented||j())}),un=y.useRef(),sn=y.useRef(),Kn=(...K)=>{A(!0),P==null||P(...K)};if(!Ye)return null;const Br=Object.assign({role:r,ref:C.setDialogRef,"aria-modal":r==="dialog"?!0:void 0},Qn,{style:o,className:l,tabIndex:-1});let Gn=v?v(Br):f.jsx("div",Object.assign({},Br,{children:y.cloneElement(i,{role:"document"})}));Gn=ya(h,d,{unmountOnExit:!0,mountOnEnter:!0,appear:!0,in:!!n,onExit:U,onExiting:ie,onExited:Kn,onEnter:Ke,onEntering:Ge,onEntered:on,children:Gn});let Dt=null;return u&&(Dt=S({ref:C.setBackdropRef,onClick:ht}),Dt=ya(g,w,{in:!!n,appear:!0,mountOnEnter:!0,unmountOnExit:!0,children:Dt})),f.jsx(f.Fragment,{children:Tn.createPortal(f.jsxs(f.Fragment,{children:[Dt,Gn]}),Ye)})});kd.displayName="Modal";const Uv=Object.assign(kd,{Manager:Yu});function Bv(e,t){return e.classList?!!t&&e.classList.contains(t):(" "+(e.className.baseVal||e.className)+" ").indexOf(" "+t+" ")!==-1}function Hv(e,t){e.classList?e.classList.add(t):Bv(e,t)||(typeof e.className=="string"?e.className=e.className+" "+t:e.setAttribute("class",(e.className&&e.className.baseVal||"")+" "+t))}function ga(e,t){return e.replace(new RegExp("(^|\\s)"+t+"(?:\\s|$)","g"),"$1").replace(/\s+/g," ").replace(/^\s*|\s*$/g,"")}function Vv(e,t){e.classList?e.classList.remove(t):typeof e.className=="string"?e.className=ga(e.className,t):e.setAttribute("class",ga(e.className&&e.className.baseVal||"",t))}const pn={FIXED_CONTENT:".fixed-top, .fixed-bottom, .is-fixed, .sticky-top",STICKY_CONTENT:".sticky-top",NAVBAR_TOGGLER:".navbar-toggler"};class Wv extends Yu{adjustAndStore(t,n,r){const l=n.style[t];n.dataset[t]=l,Xt(n,{[t]:`${parseFloat(Xt(n,t))+r}px`})}restore(t,n){const r=n.dataset[t];r!==void 0&&(delete n.dataset[t],Xt(n,{[t]:r}))}setContainerStyle(t){super.setContainerStyle(t);const n=this.getElement();if(Hv(n,"modal-open"),!t.scrollBarWidth)return;const r=this.isRTL?"paddingLeft":"paddingRight",l=this.isRTL?"marginLeft":"marginRight";dn(n,pn.FIXED_CONTENT).forEach(o=>this.adjustAndStore(r,o,t.scrollBarWidth)),dn(n,pn.STICKY_CONTENT).forEach(o=>this.adjustAndStore(l,o,-t.scrollBarWidth)),dn(n,pn.NAVBAR_TOGGLER).forEach(o=>this.adjustAndStore(l,o,t.scrollBarWidth))}removeContainerStyle(t){super.removeContainerStyle(t);const n=this.getElement();Vv(n,"modal-open");const r=this.isRTL?"paddingLeft":"paddingRight",l=this.isRTL?"marginLeft":"marginRight";dn(n,pn.FIXED_CONTENT).forEach(o=>this.restore(r,o)),dn(n,pn.STICKY_CONTENT).forEach(o=>this.restore(l,o)),dn(n,pn.NAVBAR_TOGGLER).forEach(o=>this.restore(l,o))}}let Ko;function Qv(e){return Ko||(Ko=new Wv(e)),Ko}const Ed=y.forwardRef(({className:e,bsPrefix:t,as:n="div",...r},l)=>(t=H(t,"modal-body"),f.jsx(n,{ref:l,className:M(e,t),...r})));Ed.displayName="ModalBody";const Kv=Ed,Gv=y.createContext({onHide(){}}),Cd=Gv,Nd=y.forwardRef(({bsPrefix:e,className:t,contentClassName:n,centered:r,size:l,fullscreen:o,children:i,scrollable:u,...s},a)=>{e=H(e,"modal");const m=`${e}-dialog`,h=typeof o=="string"?`${e}-fullscreen-${o}`:`${e}-fullscreen`;return f.jsx("div",{...s,ref:a,className:M(m,t,l&&`${e}-${l}`,r&&`${m}-centered`,u&&`${m}-scrollable`,o&&h),children:f.jsx("div",{className:M(`${e}-content`,n),children:i})})});Nd.displayName="ModalDialog";const Td=Nd,_d=y.forwardRef(({className:e,bsPrefix:t,as:n="div",...r},l)=>(t=H(t,"modal-footer"),f.jsx(n,{ref:l,className:M(e,t),...r})));_d.displayName="ModalFooter";const Yv=_d,Xv=y.forwardRef(({closeLabel:e="Close",closeVariant:t,closeButton:n=!1,onHide:r,children:l,...o},i)=>{const u=y.useContext(Cd),s=Me(()=>{u==null||u.onHide(),r==null||r()});return f.jsxs("div",{ref:i,...o,children:[l,n&&f.jsx(ed,{"aria-label":e,variant:t,onClick:s})]})}),Zv=Xv,jd=y.forwardRef(({bsPrefix:e,className:t,closeLabel:n="Close",closeButton:r=!1,...l},o)=>(e=H(e,"modal-header"),f.jsx(Zv,{ref:o,...l,className:M(t,e),closeLabel:n,closeButton:r})));jd.displayName="ModalHeader";const Jv=jd,qv=Yf("h4"),Ld=y.forwardRef(({className:e,bsPrefix:t,as:n=qv,...r},l)=>(t=H(t,"modal-title"),f.jsx(n,{ref:l,className:M(e,t),...r})));Ld.displayName="ModalTitle";const bv=Ld;function ey(e){return f.jsx(Ql,{...e,timeout:null})}function ty(e){return f.jsx(Ql,{...e,timeout:null})}const Rd=y.forwardRef(({bsPrefix:e,className:t,style:n,dialogClassName:r,contentClassName:l,children:o,dialogAs:i=Td,"aria-labelledby":u,"aria-describedby":s,"aria-label":a,show:m=!1,animation:h=!0,backdrop:d=!0,keyboard:g=!0,onEscapeKeyDown:w,onShow:k,onHide:L,container:p,autoFocus:c=!0,enforceFocus:v=!0,restoreFocus:S=!0,restoreFocusOptions:T,onEntered:E,onExit:N,onExiting:j,onEnter:U,onEntering:P,onExited:ie,backdropClassName:Ke,manager:Ge,...on},Qn)=>{const[Le,Ye]=y.useState({}),[C,R]=y.useState(!1),O=y.useRef(!1),I=y.useRef(!1),A=y.useRef(null),[fe,Re]=Yh(),et=mo(Qn,Re),Oe=Me(L),ht=kh();e=H(e,"modal");const ho=y.useMemo(()=>({onHide:Oe}),[Oe]);function un(){return Ge||Qv({isRTL:ht})}function sn(z){if(!Wn)return;const an=un().getScrollbarWidth()>0,qu=z.scrollHeight>po(z).documentElement.clientHeight;Ye({paddingRight:an&&!qu?ha():void 0,paddingLeft:!an&&qu?ha():void 0})}const Kn=Me(()=>{fe&&sn(fe.dialog)});rd(()=>{Ki(window,"resize",Kn),A.current==null||A.current()});const Br=()=>{O.current=!0},Gn=z=>{O.current&&fe&&z.target===fe.dialog&&(I.current=!0),O.current=!1},Dt=()=>{R(!0),A.current=Gf(fe.dialog,()=>{R(!1)})},K=z=>{z.target===z.currentTarget&&Dt()},Hr=z=>{if(d==="static"){K(z);return}if(I.current||z.target!==z.currentTarget){I.current=!1;return}L==null||L()},Yn=z=>{g?w==null||w(z):(z.preventDefault(),d==="static"&&Dt())},Dd=(z,an)=>{z&&sn(z),U==null||U(z,an)},Ad=z=>{A.current==null||A.current(),N==null||N(z)},Ud=(z,an)=>{P==null||P(z,an),Kf(window,"resize",Kn)},Bd=z=>{z&&(z.style.display=""),ie==null||ie(z),Ki(window,"resize",Kn)},Hd=y.useCallback(z=>f.jsx("div",{...z,className:M(`${e}-backdrop`,Ke,!h&&"show")}),[h,Ke,e]),Ju={...n,...Le};Ju.display="block";const Vd=z=>f.jsx("div",{role:"dialog",...z,style:Ju,className:M(t,e,C&&`${e}-static`,!h&&"show"),onClick:d?Hr:void 0,onMouseUp:Gn,"aria-label":a,"aria-labelledby":u,"aria-describedby":s,children:f.jsx(i,{...on,onMouseDown:Br,className:r,contentClassName:l,children:o})});return f.jsx(Cd.Provider,{value:ho,children:f.jsx(Uv,{show:m,ref:et,backdrop:d,container:p,keyboard:!0,autoFocus:c,enforceFocus:v,restoreFocus:S,restoreFocusOptions:T,onEscapeKeyDown:Yn,onShow:k,onHide:L,onEnter:Dd,onEntering:Ud,onEntered:E,onExit:Ad,onExiting:j,onExited:Bd,manager:un(),transition:h?ey:void 0,backdropTransition:h?ty:void 0,renderBackdrop:Hd,renderDialog:Vd})})});Rd.displayName="Modal";const ge=Object.assign(Rd,{Body:Kv,Header:Jv,Title:bv,Footer:Yv,Dialog:Td,TRANSITION_DURATION:300,BACKDROP_TRANSITION_DURATION:150}),wa=1e3;function ny(e,t,n){const r=(e-t)/(n-t)*100;return Math.round(r*wa)/wa}function Sa({min:e,now:t,max:n,label:r,visuallyHidden:l,striped:o,animated:i,className:u,style:s,variant:a,bsPrefix:m,...h},d){return f.jsx("div",{ref:d,...h,role:"progressbar",className:M(u,`${m}-bar`,{[`bg-${a}`]:a,[`${m}-bar-animated`]:i,[`${m}-bar-striped`]:i||o}),style:{width:`${ny(t,e,n)}%`,...s},"aria-valuenow":t,"aria-valuemin":e,"aria-valuemax":n,children:l?f.jsx("span",{className:"visually-hidden",children:r}):r})}const Od=y.forwardRef(({isChild:e=!1,...t},n)=>{const r={min:0,max:100,animated:!1,visuallyHidden:!1,striped:!1,...t};if(r.bsPrefix=H(r.bsPrefix,"progress"),e)return Sa(r,n);const{min:l,now:o,max:i,label:u,visuallyHidden:s,striped:a,animated:m,bsPrefix:h,variant:d,className:g,children:w,...k}=r;return f.jsx("div",{ref:n,...k,className:M(g,h),children:w?fv(w,L=>y.cloneElement(L,{isChild:!0})):Sa({min:l,now:o,max:i,label:u,visuallyHidden:s,striped:a,animated:m,bsPrefix:h,variant:d},n)})});Od.displayName="ProgressBar";const ry=Od,Pd=y.forwardRef(({bsPrefix:e,className:t,as:n="div",...r},l)=>{const o=H(e,"row"),i=Uf(),u=Bf(),s=`${o}-cols`,a=[];return i.forEach(m=>{const h=r[m];delete r[m];let d;h!=null&&typeof h=="object"?{cols:d}=h:d=h;const g=m!==u?`-${m}`:"";d!=null&&a.push(`${s}${g}-${d}`)}),f.jsx(n,{ref:l,...r,className:M(t,o,...a)})});Pd.displayName="Row";const Fd=Pd,Md=y.forwardRef(({bsPrefix:e,variant:t,animation:n="border",size:r,as:l="div",className:o,...i},u)=>{e=H(e,"spinner");const s=`${e}-${n}`;return f.jsx(l,{ref:u,...i,className:M(o,s,r&&`${s}-${r}`,t&&`text-${t}`)})});Md.displayName="Spinner";const Un=Md,Gl="initializing",$d="paused",zd="live",ly="error";function Xu(e,t){let n,r=t;const l=async()=>{if(r=await e(),r==null)throw"asyncCallback returned null or undefined";o()};let o=()=>{n=setTimeout(l,r)};return o(),()=>{clearTimeout(n)}}function oy(e,t){let n;const r=async()=>{await e().then(()=>!1,()=>!0)&&l()};let l=o=>{n=setTimeout(r,o!==void 0?o:t)};return l(0),()=>clearTimeout(n)}const Go=({className:e,onClick:t,disabled:n,color:r})=>{const l=o=>{o.stopPropagation(),!n&&t()};return f.jsx("a",{className:`bi ${e} p-1`,onClick:l,href:"#"})},Mr=e=>{var r,l,o;let{error:t,remove:n}=e;return t==null?null:f.jsxs(pa,{variant:"danger",onClose:n,dismissible:n!=null,children:[f.jsx(pa.Heading,{children:t.text}),((r=t.details)==null?void 0:r.statusText)&&f.jsx("p",{children:f.jsx("strong",{children:(l=t.details)==null?void 0:l.statusText})}),f.jsx("pre",{children:(o=t.details)==null?void 0:o.text})]})},iy=({id:e,show:t,onHide:n})=>{if(!t)return null;const[r,l]=y.useState(!1),[o,i]=y.useState(null),[u,s]=y.useState(!1),a=y.useContext(Ur),m=y.useContext(ln),h=()=>{l(!1),i(null),s(!1),n()},d=()=>{s(!0),(r?m.delete:m.forget)(e).then(()=>{a.refreshTorrents(),h()}).catch(w=>{i({text:`Error deleting torrent id=${e}`,details:w}),s(!1)})};return f.jsxs(ge,{show:t,onHide:h,children:[f.jsx(ge.Header,{closeButton:!0,children:"Delete torrent"}),f.jsxs(ge.Body,{children:[f.jsx(pe,{children:f.jsx(pe.Group,{controlId:"delete-torrent",children:f.jsx(pe.Check,{type:"checkbox",label:"Also delete files",checked:r,onChange:()=>l(!r)})})}),o&&f.jsx(Mr,{error:o})]}),f.jsxs(ge.Footer,{children:[u&&f.jsx(Un,{}),f.jsx(tn,{variant:"primary",onClick:d,disabled:u,children:"OK"}),f.jsx(tn,{variant:"secondary",onClick:h,children:"Cancel"})]})]})},uy=({id:e,statsResponse:t})=>{let n=t.state,[r,l]=y.useState(!1),[o,i]=y.useState(!1),u=y.useContext(If);const s=n=="live",a=n=="paused"||n=="error",m=y.useContext(Ur),h=y.useContext(ln),d=()=>{l(!0),h.start(e).then(()=>{u.refresh()},L=>{m.setCloseableError({text:`Error starting torrent id=${e}`,details:L})}).finally(()=>l(!1))},g=()=>{l(!0),h.pause(e).then(()=>{u.refresh()},L=>{m.setCloseableError({text:`Error pausing torrent id=${e}`,details:L})}).finally(()=>l(!1))},w=()=>{l(!0),i(!0)},k=()=>{l(!1),i(!1)};return f.jsx(Fd,{children:f.jsxs(Wu,{children:[a&&f.jsx(Go,{className:"bi-play-circle",onClick:d,disabled:r,color:"success"}),s&&f.jsx(Go,{className:"bi-pause-circle",onClick:g,disabled:r}),f.jsx(Go,{className:"bi-x-circle",onClick:w,disabled:r,color:"danger"}),f.jsx(iy,{id:e,show:o,onHide:k})]})})};function Zu(e){if(e===0)return"0 Bytes";const t=1024,n=["Bytes","KB","MB","GB"],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/Math.pow(t,r)).toFixed(2))+" "+n[r]}const sy=({statsResponse:e})=>{var t,n;switch(e.state){case $d:return"Paused";case Gl:return"Checking files";case ly:return"Error"}return e.state!="live"||e.live===null?e.state:f.jsxs(f.Fragment,{children:[!e.finished&&f.jsxs("div",{className:"download-speed",children:["↓ ",(t=e.live.download_speed)==null?void 0:t.human_readable]}),f.jsxs("div",{className:"upload-speed",children:["↑ ",(n=e.live.upload_speed)==null?void 0:n.human_readable,e.live.snapshot.uploaded_bytes>0&&f.jsxs("span",{children:[" ","(",Zu(e.live.snapshot.uploaded_bytes),")"]})]})]})},yt=({size:e,label:t,children:n})=>f.jsxs(Wu,{md:e||1,className:"py-3",children:[f.jsx("div",{className:"fw-bold",children:t}),n]});function ay(e){return e.files.filter(n=>n.included).reduce((n,r)=>n.length>r.length?n:r).name}function cy(e){const t=Math.floor(e/3600),n=Math.floor(e%3600/60),r=e%60,l=(o,i)=>o>0?`${o}${i}`:"";return t>0?`${l(t,"h")} ${l(n,"m")}`.trim():n>0?`${l(n,"m")} ${l(r,"s")}`.trim():`${l(r,"s")}`.trim()}function fy(e){var n,r,l;let t=(l=(r=(n=e==null?void 0:e.live)==null?void 0:n.time_remaining)==null?void 0:r.duration)==null?void 0:l.secs;return t==null?"N/A":cy(t)}const dy=({id:e,detailsResponse:t,statsResponse:n})=>{const r=(n==null?void 0:n.state)??"",l=n==null?void 0:n.error,o=(n==null?void 0:n.total_bytes)??1,i=(n==null?void 0:n.progress_bytes)??0,u=(n==null?void 0:n.finished)||!1,s=l?100:i/o*100,a=(r==Gl||r==zd)&&!u,m=l?"Error":`${s.toFixed(2)}%`,h=l?"danger":u?"success":r==Gl?"warning":"primary",d=()=>{var k;let w=(k=n==null?void 0:n.live)==null?void 0:k.snapshot.peer_stats;return w?`${w.live} / ${w.seen}`:""};let g=[];return l?g.push("bg-warning"):e%2==0&&g.push("bg-light"),f.jsxs(Fd,{className:g.join(" "),children:[f.jsx(yt,{size:3,label:"Name",children:t?f.jsxs(f.Fragment,{children:[f.jsx("div",{className:"text-truncate",children:ay(t)}),l&&f.jsxs("p",{className:"text-danger",children:[f.jsx("strong",{children:"Error:"})," ",l]})]}):f.jsx(Un,{})}),n?f.jsxs(f.Fragment,{children:[f.jsx(yt,{label:"Size",children:`${Zu(o)} `}),f.jsx(yt,{size:2,label:(r==$d,"Progress"),children:f.jsx(ry,{now:s,label:m,animated:a,variant:h})}),f.jsx(yt,{size:2,label:"Speed",children:f.jsx(sy,{statsResponse:n})}),f.jsx(yt,{label:"ETA",children:fy(n)}),f.jsx(yt,{size:2,label:"Live / Seen",children:d()}),f.jsx(yt,{label:"Actions",children:f.jsx(uy,{id:e,statsResponse:n})})]}):f.jsx(yt,{label:"Loading stats",size:8,children:f.jsx(Un,{})})]})},py=({id:e,torrent:t})=>{const[n,r]=y.useState(null),[l,o]=y.useState(null),[i,u]=y.useState(0),s=y.useContext(ln),a=()=>{u(i+1)};return y.useEffect(()=>{if(n===null)return oy(async()=>{await s.getTorrentDetails(t.id).then(r)},1e3)},[n]),y.useEffect(()=>Xu(async()=>s.getTorrentStats(t.id).then(g=>(o(g),g)).then(g=>g.state==Gl||g.state==zd?1e3:1e4,()=>1e4),0),[i]),f.jsx(If.Provider,{value:{refresh:a},children:f.jsx(dy,{id:e,detailsResponse:n,statsResponse:l})})},my=e=>{if(e.torrents===null&&e.loading)return f.jsx(Un,{});if(e.torrents!==null)return e.torrents.length===0?f.jsx("div",{className:"text-center",children:f.jsx("p",{children:"No existing torrents found. Add them through buttons below."})}):f.jsx("div",{style:{fontSize:"smaller"},children:e.torrents.map(t=>f.jsx(py,{id:t.id,torrent:t},t.id))})},hy=e=>{let{onHide:t,listTorrentResponse:n,listTorrentError:r,listTorrentLoading:l,data:o}=e;const[i,u]=y.useState([]),[s,a]=y.useState(!1),[m,h]=y.useState(null),[d,g]=y.useState(!1),[w,k]=y.useState(""),L=y.useContext(Ur),p=y.useContext(ln);y.useEffect(()=>{console.log(n),u(n?n.details.files.map((E,N)=>N):[]),k((n==null?void 0:n.output_folder)||"")},[n]);const c=()=>{t(),u([]),h(null),a(!1)},v=E=>{i.includes(E)?u(i.filter(N=>N!==E)):u([...i,E])},S=async()=>{if(!n)return;a(!0);let E=n.seen_peers?n.seen_peers.slice(0,32):null,N={overwrite:!0,only_files:i,initial_peers:E,output_folder:w};d&&(N.peer_opts={connect_timeout:20,read_write_timeout:60}),p.uploadTorrent(o,N).then(()=>{t(),L.refreshTorrents()},j=>{h({text:"Error starting torrent",details:j})}).finally(()=>a(!1))},T=()=>{if(l)return f.jsx(Un,{});if(r)return f.jsx(Mr,{error:r});if(n)return f.jsxs(pe,{children:[f.jsxs("fieldset",{className:"mb-4",children:[f.jsx("legend",{children:"Pick the files to download"}),n.details.files.map((E,N)=>f.jsx(pe.Group,{controlId:`check-${N}`,children:f.jsx(pe.Check,{type:"checkbox",label:`${E.name} (${Zu(E.length)})`,checked:i.includes(N),onChange:()=>v(N)})},N))]}),f.jsxs("fieldset",{children:[f.jsx("legend",{children:"Options"}),f.jsxs(pe.Group,{controlId:"output-folder",className:"mb-3",children:[f.jsx(pe.Label,{children:"Output folder"}),f.jsx(pe.Control,{type:"text",value:w,onChange:E=>k(E.target.value)})]}),f.jsxs(pe.Group,{controlId:"unpopular-torrent",className:"mb-3",children:[f.jsx(pe.Check,{type:"checkbox",label:"Increase timeouts",checked:d,onChange:()=>g(!d)}),f.jsx("small",{id:"emailHelp",className:"form-text text-muted",children:"This might be useful for unpopular torrents with few peers. It will slow down fast torrents though."})]})]})]})};return f.jsxs(ge,{show:!0,onHide:c,size:"lg",children:[f.jsx(ge.Header,{closeButton:!0,children:f.jsx(ge.Title,{children:"Add torrent"})}),f.jsxs(ge.Body,{children:[T(),f.jsx(Mr,{error:m})]}),f.jsxs(ge.Footer,{children:[s&&f.jsx(Un,{}),f.jsx(tn,{variant:"primary",onClick:S,disabled:l||s||i.length==0,children:"OK"}),f.jsx(tn,{variant:"secondary",onClick:c,children:"Cancel"})]})]})},Id=({buttonText:e,onClick:t,data:n,resetData:r,variant:l})=>{const[o,i]=y.useState(!1),[u,s]=y.useState(null),[a,m]=y.useState(null),h=y.useContext(ln);y.useEffect(()=>{if(n===null)return;let g=setTimeout(async()=>{i(!0);try{const w=await h.uploadTorrent(n,{list_only:!0});s(w)}catch(w){m({text:"Error listing torrent files",details:w})}finally{i(!1)}},0);return()=>clearTimeout(g)},[n]);const d=()=>{r(),m(null),s(null),i(!1)};return f.jsxs(f.Fragment,{children:[f.jsx(tn,{variant:l,onClick:t,className:"m-1",children:e}),n&&f.jsx(hy,{onHide:d,listTorrentError:a,listTorrentResponse:u,data:n,listTorrentLoading:o})]})},vy=({show:e,setUrl:t,cancel:n})=>{let[r,l]=y.useState("");return f.jsxs(ge,{show:e,onHide:n,size:"lg",children:[f.jsx(ge.Header,{closeButton:!0,children:f.jsx(ge.Title,{children:"Add torrent"})}),f.jsx(ge.Body,{children:f.jsx(pe,{children:f.jsxs(pe.Group,{className:"mb-3",controlId:"url",children:[f.jsx(pe.Label,{children:"Enter magnet or HTTP(S) URL to the .torrent"}),f.jsx(pe.Control,{value:r,placeholder:"magnet:?xt=urn:btih:...",onChange:o=>{l(o.target.value)}})]})})}),f.jsxs(ge.Footer,{children:[f.jsx(tn,{variant:"primary",onClick:()=>{t(r),l("")},disabled:r.length==0,children:"OK"}),f.jsx(tn,{variant:"secondary",onClick:n,children:"Cancel"})]})]})},yy=()=>{let[e,t]=y.useState(null),[n,r]=y.useState(!1);return f.jsxs(f.Fragment,{children:[f.jsx(Id,{variant:"primary",buttonText:"Add Torrent from Magnet / URL",onClick:()=>{r(!0)},data:e,resetData:()=>t(null)}),f.jsx(vy,{show:n,setUrl:l=>{r(!1),t(l)},cancel:()=>{r(!1),t(null)}})]})},gy=()=>{const e=y.useRef(),[t,n]=y.useState(null),r=async()=>{var u;if(!((u=e==null?void 0:e.current)!=null&&u.files))return;const i=e.current.files[0];n(i)},l=()=>{e!=null&&e.current&&(e.current.value="",n(null))},o=()=>{e!=null&&e.current&&e.current.click()};return f.jsxs(f.Fragment,{children:[f.jsx("input",{type:"file",ref:e,accept:".torrent",onChange:r,className:"d-none"}),f.jsx(Id,{variant:"secondary",buttonText:"Upload .torrent File",onClick:o,data:t,resetData:l})]})},wy=()=>f.jsxs("div",{id:"buttons-container",className:"mt-3",children:[f.jsx(yy,{}),f.jsx(gy,{})]}),Sy=e=>{let t=y.useContext(Ur);return f.jsxs(mv,{children:[f.jsx(Mr,{error:e.closeableError,remove:()=>t.setCloseableError(null)}),f.jsx(Mr,{error:e.otherError}),f.jsx(my,{torrents:e.torrents,loading:e.torrentsLoading}),f.jsx(wy,{})]})},xy=e=>{const[t,n]=y.useState(null),[r,l]=y.useState(null),[o,i]=y.useState(null),[u,s]=y.useState(!1),a=y.useContext(ln),m=async()=>{s(!0);let d=await a.listTorrents().finally(()=>s(!1));i(d.torrents)};y.useEffect(()=>Xu(async()=>m().then(()=>(l(null),5e3),d=>(l({text:"Error refreshing torrents",details:d}),console.error(d),5e3)),0),[]);const h={setCloseableError:n,refreshTorrents:m};return f.jsx(Ur.Provider,{value:h,children:f.jsxs("div",{className:"text-center",children:[f.jsx("h1",{className:"mt-3 mb-4",children:e.title}),f.jsx(Sy,{closeableError:t,otherError:r,torrents:o,torrentsLoading:u})]})})},ky=window.origin==="null"||window.origin==="http://localhost:3031"?"http://localhost:3030":"",tt=async(e,t,n)=>{console.log(e,t);const r=ky+t,l={method:e,headers:{Accept:"application/json"},body:n};let o={method:e,path:t,text:""},i;try{i=await fetch(r,l)}catch{return o.text="network error",Promise.reject(o)}if(o.status=i.status,o.statusText=`${i.status} ${i.statusText}`,!i.ok){const s=await i.text();try{const a=JSON.parse(s);o.text=a.human_readable!==void 0?a.human_readable:JSON.stringify(a,null,2)}catch{o.text=s}return Promise.reject(o)}return await i.json()},xa={listTorrents:()=>tt("GET","/torrents"),getTorrentDetails:e=>tt("GET",`/torrents/${e}`),getTorrentStats:e=>tt("GET",`/torrents/${e}/stats/v1`),uploadTorrent:(e,t)=>{var r,l;let n="/torrents?&overwrite=true";return t!=null&&t.list_only&&(n+="&list_only=true"),(t==null?void 0:t.only_files)!=null&&(n+=`&only_files=${t.only_files.join(",")}`),(r=t==null?void 0:t.peer_opts)!=null&&r.connect_timeout&&(n+=`&peer_connect_timeout=${t.peer_opts.connect_timeout}`),(l=t==null?void 0:t.peer_opts)!=null&&l.read_write_timeout&&(n+=`&peer_read_write_timeout=${t.peer_opts.read_write_timeout}`),t!=null&&t.initial_peers&&(n+=`&initial_peers=${t.initial_peers.join(",")}`),t!=null&&t.output_folder&&(n+=`&output_folder=${t.output_folder}`),typeof e=="string"&&(n+="&is_url=true"),tt("POST",n,e)},pause:e=>tt("POST",`/torrents/${e}/pause`),start:e=>tt("POST",`/torrents/${e}/start`),forget:e=>tt("POST",`/torrents/${e}/forget`),delete:e=>tt("POST",`/torrents/${e}/delete`),getVersion:async()=>(await tt("GET","/")).version},Ey=()=>{let[e,t]=y.useState("rqbit web UI");return y.useEffect(()=>Xu(()=>xa.getVersion().then(r=>{const l=`rqbit web UI - v${r}`;return t(l),document.title=l,1e4},r=>1e3),0),[]),f.jsx(y.StrictMode,{children:f.jsx(ln.Provider,{value:xa,children:f.jsx(xy,{title:e})})})};Yo.createRoot(document.getElementById("app")).render(f.jsx(Ey,{})); diff --git a/crates/librqbit/webui/dist/index.html b/crates/librqbit/webui/dist/index.html index 1576e01..d421f85 100644 --- a/crates/librqbit/webui/dist/index.html +++ b/crates/librqbit/webui/dist/index.html @@ -3,7 +3,7 @@ - rqbit web 4.0.0-beta.0 + rqbit web - rqbit web 4.0.0-beta.0 + rqbit web { const refreshVersion = () => API.getVersion().then( (version) => { - setTitle(`rqbit web UI - v${version}`); + const title = `rqbit web UI - v${version}`; + setTitle(title); + document.title = title; return 10000; }, (e) => {