diff --git a/Makefile b/Makefile index f5aec57..38779f2 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,10 @@ webui-build: webui-deps @PHONY: devserver devserver: echo -n '' > /tmp/rqbit-log - CORS_DEBUG=1 cargo run --release -- --log-file /tmp/rqbit-log server start /tmp/scratch/ + CORS_DEBUG=1 cargo run --release -- \ + --log-file /tmp/rqbit-log \ + --log-file-rust-log=debug,librqbit=trace \ + server start /tmp/scratch/ @PHONY: clean clean: diff --git a/crates/librqbit/src/http_api.rs b/crates/librqbit/src/http_api.rs index 622df65..81a48ee 100644 --- a/crates/librqbit/src/http_api.rs +++ b/crates/librqbit/src/http_api.rs @@ -3,13 +3,14 @@ use axum::body::Bytes; use axum::extract::{Path, Query, State}; use axum::response::IntoResponse; use axum::routing::{get, post}; +use futures::TryStreamExt; use itertools::Itertools; use serde::{Deserialize, Serialize}; use std::net::SocketAddr; use std::str::FromStr; use std::time::Duration; -use tracing::{info, warn}; +use tracing::{debug, info, warn}; use axum::Router; @@ -187,7 +188,10 @@ impl HttpApi { } async fn stream_logs(State(state): State) -> Result { - let s = state.api_log_lines_stream()?; + let s = state.api_log_lines_stream()?.map_err(|e| { + debug!(error=%e, "stream_logs"); + e + }); Ok(axum::body::Body::from_stream(s)) } diff --git a/crates/librqbit/webui/dist/assets/index.js b/crates/librqbit/webui/dist/assets/index.js index 5a1e3c4..b9dbdca 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 pa(e){return"default"+e.charAt(0).toUpperCase()+e.substr(1)}function _h(e){var t=jh(e,"string");return typeof t=="symbol"?t:String(t)}function jh(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 Lh(e,t,n){var r=v.useRef(e!==void 0),l=v.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,v.useCallback(function(a){for(var h=arguments.length,p=new Array(h>1?h-1:0),d=1;d{o.target===e&&(l(),t(o))},n+r)}function bh(e){e.offsetHeight}const va=e=>!e||typeof e=="function"?e:t=>{e.current=t};function ev(e,t){const n=va(e),r=va(t);return l=>{n&&n(l),r&&r(l)}}function go(e,t){return v.useMemo(()=>ev(e,t),[e,t])}function tv(e){return e&&"setState"in e?jn.findDOMNode(e):e??null}const nv=he.forwardRef(({onEnter:e,onEntering:t,onEntered:n,onExit:r,onExiting:l,onExited:o,addEndListener:i,children:u,childRef:s,...a},h)=>{const p=v.useRef(null),d=go(p,s),w=E=>{d(tv(E))},y=E=>C=>{E&&p.current&&E(p.current,C)},x=v.useCallback(y(e),[e]),L=v.useCallback(y(t),[t]),m=v.useCallback(y(n),[n]),f=v.useCallback(y(r),[r]),g=v.useCallback(y(l),[l]),S=v.useCallback(y(o),[o]),N=v.useCallback(y(i),[i]);return c.jsx(Xh,{ref:h,...a,onEnter:x,onEntered:m,onEntering:L,onExit:f,onExited:S,onExiting:g,addEndListener:N,nodeRef:p,children:typeof u=="function"?(E,C)=>u(E,{...C,ref:w}):he.cloneElement(u,{ref:w})})}),rv=nv;function lv(e){const t=v.useRef(e);return v.useEffect(()=>{t.current=e},[e]),t}function ze(e){const t=lv(e);return v.useCallback(function(...n){return t.current&&t.current(...n)},[t])}const nd=e=>v.forwardRef((t,n)=>c.jsx("div",{...t,ref:n,className:M(t.className,e)})),rd=nd("h4");rd.displayName="DivStyledAsH4";const ld=v.forwardRef(({className:e,bsPrefix:t,as:n=rd,...r},l)=>(t=H(t,"alert-heading"),c.jsx(n,{ref:l,className:M(e,t),...r})));ld.displayName="AlertHeading";const ov=ld;function iv(){return v.useState(null)}function uv(){const e=v.useRef(!0),t=v.useRef(()=>e.current);return v.useEffect(()=>(e.current=!0,()=>{e.current=!1}),[]),t.current}function sv(e){const t=v.useRef(null);return v.useEffect(()=>{t.current=e}),t.current}const av=typeof global<"u"&&global.navigator&&global.navigator.product==="ReactNative",cv=typeof document<"u",ga=cv||av?v.useLayoutEffect:v.useEffect,fv=["as","disabled"];function dv(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 pv(e){return!e||e.trim()==="#"}function Gu({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 h=d=>{if((t||e==="a"&&pv(n))&&d.preventDefault(),t){d.stopPropagation();return}i==null||i(d)},p=d=>{d.key===" "&&(d.preventDefault(),h(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:h,onKeyDown:p},a]}const mv=v.forwardRef((e,t)=>{let{as:n,disabled:r}=e,l=dv(e,fv);const[o,{tagName:i}]=Gu(Object.assign({tagName:n,disabled:r},l));return c.jsx(i,Object.assign({},l,o,{ref:t}))});mv.displayName="Button";const hv=["onKeyDown"];function vv(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 gv(e){return!e||e.trim()==="#"}const od=v.forwardRef((e,t)=>{let{onKeyDown:n}=e,r=vv(e,hv);const[l]=Gu(Object.assign({tagName:"a"},r)),o=ze(i=>{l.onKeyDown(i),n==null||n(i)});return gv(r.href)||r.role==="button"?c.jsx("a",Object.assign({ref:t},r,l,{onKeyDown:o})):c.jsx("a",Object.assign({ref:t},r,{onKeyDown:n}))});od.displayName="Anchor";const yv=od,id=v.forwardRef(({className:e,bsPrefix:t,as:n=yv,...r},l)=>(t=H(t,"alert-link"),c.jsx(n,{ref:l,className:M(e,t),...r})));id.displayName="AlertLink";const wv=id,xv={[St]:"show",[Kt]:"show"},ud=v.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=v.useCallback((s,a)=>{bh(s),r==null||r(s,a)},[r]);return c.jsx(rv,{ref:o,addEndListener:qh,...i,onEnter:u,childRef:t.ref,children:(s,a)=>v.cloneElement(t,{...a,className:M("fade",e,t.props.className,xv[s],n[s])})})});ud.displayName="Fade";const Yl=ud,Sv={"aria-label":st.string,onClick:st.func,variant:st.oneOf(["white"])},Xu=v.forwardRef(({className:e,variant:t,"aria-label":n="Close",...r},l)=>c.jsx("button",{ref:l,type:"button",className:M("btn-close",t&&`btn-close-${t}`,e),"aria-label":n,...r}));Xu.displayName="CloseButton";Xu.propTypes=Sv;const sd=Xu,ad=v.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:h,transition:p=Yl,...d}=Oh(e,{show:"onClose"}),w=H(n,"alert"),y=ze(m=>{a&&a(!1,m)}),x=p===!0?Yl:p,L=c.jsxs("div",{role:"alert",...x?void 0:d,ref:t,className:M(i,w,s&&`${w}-${s}`,h&&`${w}-dismissible`),children:[h&&c.jsx(sd,{onClick:y,"aria-label":l,variant:o}),u]});return x?c.jsx(x,{unmountOnExit:!0,...d,ref:void 0,in:r,children:L}):r?L:null});ad.displayName="Alert";const ya=Object.assign(ad,{Link:wv,Heading:ov}),cd=v.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"),[h,{tagName:p}]=Gu({tagName:e,disabled:o,...u}),d=p;return c.jsx(d,{...h,...u,ref:s,disabled:o,className:M(i,a,l&&"active",n&&`${a}-${n}`,r&&`${a}-${r}`,u.href&&o&&"disabled")})});cd.displayName="Button";const $t=cd;function Ev(e){const t=v.useRef(e);return t.current=e,t}function fd(e){const t=Ev(e);v.useEffect(()=>()=>t.current(),[])}function kv(e,t){let n=0;return v.Children.map(e,r=>v.isValidElement(r)?t(r,n++):r)}function Cv(e,t){return v.Children.toArray(e).some(n=>v.isValidElement(n)&&n.type===t)}function Tv({as:e,bsPrefix:t,className:n,...r}){t=H(t,"col");const l=Xf(),o=Yf(),i=[],u=[];return l.forEach(s=>{const a=r[s];delete r[s];let h,p,d;typeof a=="object"&&a!=null?{span:h,offset:p,order:d}=a:h=a;const w=s!==o?`-${s}`:"";h&&i.push(h===!0?`${t}${w}`:`${t}${w}-${h}`),d!=null&&u.push(`order${w}-${d}`),p!=null&&u.push(`offset${w}-${p}`)}),[{...r,className:M(n,...i,...u)},{as:e,bsPrefix:t,spans:i}]}const dd=v.forwardRef((e,t)=>{const[{className:n,...r},{as:l="div",bsPrefix:o,spans:i}]=Tv(e);return c.jsx(l,{...r,ref:t,className:M(n,!i.length&&o)})});dd.displayName="Col";const Yu=dd,pd=v.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 c.jsx(n,{ref:o,...l,className:M(r,t?`${i}${u}`:i)})});pd.displayName="Container";const Nv=pd;var _v=Function.prototype.bind.call(Function.prototype.call,[].slice);function mn(e,t){return _v(e.querySelectorAll(t))}function wa(e,t){if(e.contains)return e.contains(t);if(e.compareDocumentPosition)return e===t||!!(e.compareDocumentPosition(t)&16)}const jv="data-rr-ui-";function Lv(e){return`${jv}${e}`}const md=v.createContext(Kn?window:void 0);md.Provider;function Zu(){return v.useContext(md)}const Ov={type:st.string,tooltip:st.bool,as:st.elementType},Ju=v.forwardRef(({as:e="div",className:t,type:n="valid",tooltip:r=!1,...l},o)=>c.jsx(e,{...l,ref:o,className:M(t,`${n}-${r?"tooltip":"feedback"}`)}));Ju.displayName="Feedback";Ju.propTypes=Ov;const hd=Ju,Rv=v.createContext({}),pt=Rv,vd=v.forwardRef(({id:e,bsPrefix:t,className:n,type:r="checkbox",isValid:l=!1,isInvalid:o=!1,as:i="input",...u},s)=>{const{controlId:a}=v.useContext(pt);return t=H(t,"form-check-input"),c.jsx(i,{...u,ref:s,type:r,id:e||a,className:M(n,t,l&&"is-valid",o&&"is-invalid")})});vd.displayName="FormCheckInput";const gd=vd,yd=v.forwardRef(({bsPrefix:e,className:t,htmlFor:n,...r},l)=>{const{controlId:o}=v.useContext(pt);return e=H(e,"form-check-label"),c.jsx("label",{...r,ref:l,htmlFor:n||o,className:M(t,e)})});yd.displayName="FormCheckLabel";const Ji=yd,wd=v.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:h,className:p,style:d,title:w="",type:y="checkbox",label:x,children:L,as:m="input",...f},g)=>{t=H(t,"form-check"),n=H(n,"form-switch");const{controlId:S}=v.useContext(pt),N=v.useMemo(()=>({controlId:e||S}),[S,e]),E=!L&&x!=null&&x!==!1||Cv(L,Ji),C=c.jsx(gd,{...f,type:y==="switch"?"checkbox":y,ref:g,isValid:i,isInvalid:u,disabled:o,as:m});return c.jsx(pt.Provider,{value:N,children:c.jsx("div",{style:d,className:M(p,E&&t,r&&`${t}-inline`,l&&`${t}-reverse`,y==="switch"&&n),children:L||c.jsxs(c.Fragment,{children:[C,E&&c.jsx(Ji,{title:w,children:x}),a&&c.jsx(hd,{type:h,tooltip:s,children:a})]})})})});wd.displayName="FormCheck";const Zl=Object.assign(wd,{Input:gd,Label:Ji}),xd=v.forwardRef(({bsPrefix:e,type:t,size:n,htmlSize:r,id:l,className:o,isValid:i=!1,isInvalid:u=!1,plaintext:s,readOnly:a,as:h="input",...p},d)=>{const{controlId:w}=v.useContext(pt);return e=H(e,"form-control"),c.jsx(h,{...p,type:t,size:r,ref:d,readOnly:a,id:l||w,className:M(o,s?`${e}-plaintext`:e,n&&`${e}-${n}`,t==="color"&&`${e}-color`,i&&"is-valid",u&&"is-invalid")})});xd.displayName="FormControl";const Pv=Object.assign(xd,{Feedback:hd}),Sd=v.forwardRef(({className:e,bsPrefix:t,as:n="div",...r},l)=>(t=H(t,"form-floating"),c.jsx(n,{ref:l,className:M(e,t),...r})));Sd.displayName="FormFloating";const Fv=Sd,Ed=v.forwardRef(({controlId:e,as:t="div",...n},r)=>{const l=v.useMemo(()=>({controlId:e}),[e]);return c.jsx(pt.Provider,{value:l,children:c.jsx(t,{...n,ref:r})})});Ed.displayName="FormGroup";const kd=Ed,Cd=v.forwardRef(({as:e="label",bsPrefix:t,column:n=!1,visuallyHidden:r=!1,className:l,htmlFor:o,...i},u)=>{const{controlId:s}=v.useContext(pt);t=H(t,"form-label");let a="col-form-label";typeof n=="string"&&(a=`${a} ${a}-${n}`);const h=M(l,t,r&&"visually-hidden",n&&a);return o=o||s,n?c.jsx(Yu,{ref:u,as:"label",className:h,htmlFor:o,...i}):c.jsx(e,{ref:u,className:h,htmlFor:o,...i})});Cd.displayName="FormLabel";const Mv=Cd,Td=v.forwardRef(({bsPrefix:e,className:t,id:n,...r},l)=>{const{controlId:o}=v.useContext(pt);return e=H(e,"form-range"),c.jsx("input",{...r,type:"range",ref:l,className:M(t,e),id:n||o})});Td.displayName="FormRange";const zv=Td,Nd=v.forwardRef(({bsPrefix:e,size:t,htmlSize:n,className:r,isValid:l=!1,isInvalid:o=!1,id:i,...u},s)=>{const{controlId:a}=v.useContext(pt);return e=H(e,"form-select"),c.jsx("select",{...u,size:n,ref:s,className:M(r,e,t&&`${e}-${t}`,l&&"is-valid",o&&"is-invalid"),id:i||a})});Nd.displayName="FormSelect";const Iv=Nd,_d=v.forwardRef(({bsPrefix:e,className:t,as:n="small",muted:r,...l},o)=>(e=H(e,"form-text"),c.jsx(n,{...l,ref:o,className:M(t,e,r&&"text-muted")})));_d.displayName="FormText";const $v=_d,jd=v.forwardRef((e,t)=>c.jsx(Zl,{...e,ref:t,type:"switch"}));jd.displayName="Switch";const Dv=Object.assign(jd,{Input:Zl.Input,Label:Zl.Label}),Ld=v.forwardRef(({bsPrefix:e,className:t,children:n,controlId:r,label:l,...o},i)=>(e=H(e,"form-floating"),c.jsxs(kd,{ref:i,className:M(t,e),controlId:r,...o,children:[n,c.jsx("label",{htmlFor:r,children:l})]})));Ld.displayName="FloatingLabel";const Av=Ld,Bv={_ref:st.any,validated:st.bool,as:st.elementType},qu=v.forwardRef(({className:e,validated:t,as:n="form",...r},l)=>c.jsx(n,{...r,ref:l,className:M(e,t&&"was-validated")}));qu.displayName="Form";qu.propTypes=Bv;const re=Object.assign(qu,{Group:kd,Control:Pv,Floating:Fv,Check:Zl,Switch:Dv,Label:Mv,Text:$v,Range:zv,Select:Iv,FloatingLabel:Av});var cl;function xa(e){if((!cl&&cl!==0||e)&&Kn){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),cl=t.offsetWidth-t.clientWidth,document.body.removeChild(t)}return cl}function Go(e){e===void 0&&(e=vo());try{var t=e.activeElement;return!t||!t.nodeName?null:t}catch{return e.body}}function Uv(e=document){const t=e.defaultView;return Math.abs(t.innerWidth-e.documentElement.clientWidth)}const Sa=Lv("modal-open");class Hv{constructor({ownerDocument:t,handleContainerOverflow:n=!0,isRTL:r=!1}={}){this.handleContainerOverflow=n,this.isRTL=r,this.modals=[],this.ownerDocument=t}getScrollbarWidth(){return Uv(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(qt(l,r)||"0",10)+t.scrollBarWidth}px`),l.setAttribute(Sa,""),qt(l,n)}reset(){[...this.modals].forEach(t=>this.remove(t))}removeContainerStyle(t){const n=this.getElement();n.removeAttribute(Sa),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 bu=Hv,Xo=(e,t)=>Kn?e==null?(t||vo()).body:(typeof e=="function"&&(e=e()),e&&"current"in e&&(e=e.current),e&&("nodeType"in e||e.getBoundingClientRect)?e:null):null;function Wv(e,t){const n=Zu(),[r,l]=v.useState(()=>Xo(e,n==null?void 0:n.document));if(!r){const o=Xo(e);o&&l(o)}return v.useEffect(()=>{t&&r&&t(r)},[t,r]),v.useEffect(()=>{const o=Xo(e);o!==r&&l(o)},[e,r]),r}function Vv({children:e,in:t,onExited:n,mountOnEnter:r,unmountOnExit:l}){const o=v.useRef(null),i=v.useRef(t),u=ze(n);v.useEffect(()=>{t?i.current=!0:u(o.current)},[t,u]);const s=go(o,e.ref),a=v.cloneElement(e,{ref:s});return t?a:l||!i.current&&r?null:a}function Qv({in:e,onTransition:t}){const n=v.useRef(null),r=v.useRef(!0),l=ze(t);return ga(()=>{if(!n.current)return;let o=!1;return l({in:e,element:n.current,initial:r.current,isStale:()=>o}),()=>{o=!0}},[e,l]),ga(()=>(r.current=!1,()=>{r.current=!0}),[]),n}function Kv({children:e,in:t,onExited:n,onEntered:r,transition:l}){const[o,i]=v.useState(!t);t&&o&&i(!1);const u=Qv({in:!!t,onTransition:a=>{const h=()=>{a.isStale()||(a.in?r==null||r(a.element,a.initial):(i(!0),n==null||n(a.element)))};Promise.resolve(l(a)).then(h,p=>{throw a.in||i(!0),p})}}),s=go(u,e.ref);return o&&!t?null:v.cloneElement(e,{ref:s})}function Ea(e,t,n){return e?c.jsx(e,Object.assign({},n)):t?c.jsx(Kv,Object.assign({},n,{transition:t})):c.jsx(Vv,Object.assign({},n))}function Gv(e){return e.code==="Escape"||e.keyCode===27}const Xv=["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 Yv(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 Yo;function Zv(e){return Yo||(Yo=new bu({ownerDocument:e==null?void 0:e.document})),Yo}function Jv(e){const t=Zu(),n=e||Zv(t),r=v.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:v.useCallback(l=>{r.current.dialog=l},[]),setBackdropRef:v.useCallback(l=>{r.current.backdrop=l},[])})}const Od=v.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:h,transition:p,runTransition:d,backdropTransition:w,runBackdropTransition:y,autoFocus:x=!0,enforceFocus:L=!0,restoreFocus:m=!0,restoreFocusOptions:f,renderDialog:g,renderBackdrop:S=K=>c.jsx("div",Object.assign({},K)),manager:N,container:E,onShow:C,onHide:_=()=>{},onExit:$,onExited:P,onExiting:se,onEnter:Ge,onEntering:Xe,onEntered:sn}=e,Gn=Yv(e,Xv);const Oe=Zu(),Ye=Wv(E),T=Jv(N),O=uv(),R=sv(n),[D,B]=v.useState(!n),pe=v.useRef(null);v.useImperativeHandle(t,()=>T,[T]),Kn&&!R&&n&&(pe.current=Go(Oe==null?void 0:Oe.document)),n&&D&&B(!1);const Re=ze(()=>{if(T.add(),cn.current=Xl(document,"keydown",wo),an.current=Xl(document,"focus",()=>setTimeout(Pe),!0),C&&C(),x){var K,Vr;const Zn=Go((K=(Vr=T.dialog)==null?void 0:Vr.ownerDocument)!=null?K:Oe==null?void 0:Oe.document);T.dialog&&Zn&&!wa(T.dialog,Zn)&&(pe.current=Zn,T.dialog.focus())}}),tt=ze(()=>{if(T.remove(),cn.current==null||cn.current(),an.current==null||an.current(),m){var K;(K=pe.current)==null||K.focus==null||K.focus(f),pe.current=null}});v.useEffect(()=>{!n||!Ye||Re()},[n,Ye,Re]),v.useEffect(()=>{D&&tt()},[D,tt]),fd(()=>{tt()});const Pe=ze(()=>{if(!L||!O()||!T.isTopModal())return;const K=Go(Oe==null?void 0:Oe.document);T.dialog&&K&&!wa(T.dialog,K)&&T.dialog.focus()}),vt=ze(K=>{K.target===K.currentTarget&&(a==null||a(K),u===!0&&_())}),wo=ze(K=>{s&&Gv(K)&&T.isTopModal()&&(h==null||h(K),K.defaultPrevented||_())}),an=v.useRef(),cn=v.useRef(),Xn=(...K)=>{B(!0),P==null||P(...K)};if(!Ye)return null;const Wr=Object.assign({role:r,ref:T.setDialogRef,"aria-modal":r==="dialog"?!0:void 0},Gn,{style:o,className:l,tabIndex:-1});let Yn=g?g(Wr):c.jsx("div",Object.assign({},Wr,{children:v.cloneElement(i,{role:"document"})}));Yn=Ea(p,d,{unmountOnExit:!0,mountOnEnter:!0,appear:!0,in:!!n,onExit:$,onExiting:se,onExited:Xn,onEnter:Ge,onEntering:Xe,onEntered:sn,children:Yn});let Ht=null;return u&&(Ht=S({ref:T.setBackdropRef,onClick:vt}),Ht=Ea(w,y,{in:!!n,appear:!0,mountOnEnter:!0,unmountOnExit:!0,children:Ht})),c.jsx(c.Fragment,{children:jn.createPortal(c.jsxs(c.Fragment,{children:[Ht,Yn]}),Ye)})});Od.displayName="Modal";const qv=Object.assign(Od,{Manager:bu});function bv(e,t){return e.classList?!!t&&e.classList.contains(t):(" "+(e.className.baseVal||e.className)+" ").indexOf(" "+t+" ")!==-1}function e0(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 ka(e,t){return e.replace(new RegExp("(^|\\s)"+t+"(?:\\s|$)","g"),"$1").replace(/\s+/g," ").replace(/^\s*|\s*$/g,"")}function t0(e,t){e.classList?e.classList.remove(t):typeof e.className=="string"?e.className=ka(e.className,t):e.setAttribute("class",ka(e.className&&e.className.baseVal||"",t))}const hn={FIXED_CONTENT:".fixed-top, .fixed-bottom, .is-fixed, .sticky-top",STICKY_CONTENT:".sticky-top",NAVBAR_TOGGLER:".navbar-toggler"};class n0 extends bu{adjustAndStore(t,n,r){const l=n.style[t];n.dataset[t]=l,qt(n,{[t]:`${parseFloat(qt(n,t))+r}px`})}restore(t,n){const r=n.dataset[t];r!==void 0&&(delete n.dataset[t],qt(n,{[t]:r}))}setContainerStyle(t){super.setContainerStyle(t);const n=this.getElement();if(e0(n,"modal-open"),!t.scrollBarWidth)return;const r=this.isRTL?"paddingLeft":"paddingRight",l=this.isRTL?"marginLeft":"marginRight";mn(n,hn.FIXED_CONTENT).forEach(o=>this.adjustAndStore(r,o,t.scrollBarWidth)),mn(n,hn.STICKY_CONTENT).forEach(o=>this.adjustAndStore(l,o,-t.scrollBarWidth)),mn(n,hn.NAVBAR_TOGGLER).forEach(o=>this.adjustAndStore(l,o,t.scrollBarWidth))}removeContainerStyle(t){super.removeContainerStyle(t);const n=this.getElement();t0(n,"modal-open");const r=this.isRTL?"paddingLeft":"paddingRight",l=this.isRTL?"marginLeft":"marginRight";mn(n,hn.FIXED_CONTENT).forEach(o=>this.restore(r,o)),mn(n,hn.STICKY_CONTENT).forEach(o=>this.restore(l,o)),mn(n,hn.NAVBAR_TOGGLER).forEach(o=>this.restore(l,o))}}let Zo;function r0(e){return Zo||(Zo=new n0(e)),Zo}const Rd=v.forwardRef(({className:e,bsPrefix:t,as:n="div",...r},l)=>(t=H(t,"modal-body"),c.jsx(n,{ref:l,className:M(e,t),...r})));Rd.displayName="ModalBody";const l0=Rd,o0=v.createContext({onHide(){}}),Pd=o0,Fd=v.forwardRef(({bsPrefix:e,className:t,contentClassName:n,centered:r,size:l,fullscreen:o,children:i,scrollable:u,...s},a)=>{e=H(e,"modal");const h=`${e}-dialog`,p=typeof o=="string"?`${e}-fullscreen-${o}`:`${e}-fullscreen`;return c.jsx("div",{...s,ref:a,className:M(h,t,l&&`${e}-${l}`,r&&`${h}-centered`,u&&`${h}-scrollable`,o&&p),children:c.jsx("div",{className:M(`${e}-content`,n),children:i})})});Fd.displayName="ModalDialog";const Md=Fd,zd=v.forwardRef(({className:e,bsPrefix:t,as:n="div",...r},l)=>(t=H(t,"modal-footer"),c.jsx(n,{ref:l,className:M(e,t),...r})));zd.displayName="ModalFooter";const i0=zd,u0=v.forwardRef(({closeLabel:e="Close",closeVariant:t,closeButton:n=!1,onHide:r,children:l,...o},i)=>{const u=v.useContext(Pd),s=ze(()=>{u==null||u.onHide(),r==null||r()});return c.jsxs("div",{ref:i,...o,children:[l,n&&c.jsx(sd,{"aria-label":e,variant:t,onClick:s})]})}),s0=u0,Id=v.forwardRef(({bsPrefix:e,className:t,closeLabel:n="Close",closeButton:r=!1,...l},o)=>(e=H(e,"modal-header"),c.jsx(s0,{ref:o,...l,className:M(t,e),closeLabel:n,closeButton:r})));Id.displayName="ModalHeader";const a0=Id,c0=nd("h4"),$d=v.forwardRef(({className:e,bsPrefix:t,as:n=c0,...r},l)=>(t=H(t,"modal-title"),c.jsx(n,{ref:l,className:M(e,t),...r})));$d.displayName="ModalTitle";const f0=$d;function d0(e){return c.jsx(Yl,{...e,timeout:null})}function p0(e){return c.jsx(Yl,{...e,timeout:null})}const Dd=v.forwardRef(({bsPrefix:e,className:t,style:n,dialogClassName:r,contentClassName:l,children:o,dialogAs:i=Md,"aria-labelledby":u,"aria-describedby":s,"aria-label":a,show:h=!1,animation:p=!0,backdrop:d=!0,keyboard:w=!0,onEscapeKeyDown:y,onShow:x,onHide:L,container:m,autoFocus:f=!0,enforceFocus:g=!0,restoreFocus:S=!0,restoreFocusOptions:N,onEntered:E,onExit:C,onExiting:_,onEnter:$,onEntering:P,onExited:se,backdropClassName:Ge,manager:Xe,...sn},Gn)=>{const[Oe,Ye]=v.useState({}),[T,O]=v.useState(!1),R=v.useRef(!1),D=v.useRef(!1),B=v.useRef(null),[pe,Re]=iv(),tt=go(Gn,Re),Pe=ze(L),vt=Mh();e=H(e,"modal");const wo=v.useMemo(()=>({onHide:Pe}),[Pe]);function an(){return Xe||r0({isRTL:vt})}function cn(I){if(!Kn)return;const fn=an().getScrollbarWidth()>0,rs=I.scrollHeight>vo(I).documentElement.clientHeight;Ye({paddingRight:fn&&!rs?xa():void 0,paddingLeft:!fn&&rs?xa():void 0})}const Xn=ze(()=>{pe&&cn(pe.dialog)});fd(()=>{Zi(window,"resize",Xn),B.current==null||B.current()});const Wr=()=>{R.current=!0},Yn=I=>{R.current&&pe&&I.target===pe.dialog&&(D.current=!0),R.current=!1},Ht=()=>{O(!0),B.current=td(pe.dialog,()=>{O(!1)})},K=I=>{I.target===I.currentTarget&&Ht()},Vr=I=>{if(d==="static"){K(I);return}if(D.current||I.target!==I.currentTarget){D.current=!1;return}L==null||L()},Zn=I=>{w?y==null||y(I):(I.preventDefault(),d==="static"&&Ht())},Zd=(I,fn)=>{I&&cn(I),$==null||$(I,fn)},Jd=I=>{B.current==null||B.current(),C==null||C(I)},qd=(I,fn)=>{P==null||P(I,fn),ed(window,"resize",Xn)},bd=I=>{I&&(I.style.display=""),se==null||se(I),Zi(window,"resize",Xn)},ep=v.useCallback(I=>c.jsx("div",{...I,className:M(`${e}-backdrop`,Ge,!p&&"show")}),[p,Ge,e]),ns={...n,...Oe};ns.display="block";const tp=I=>c.jsx("div",{role:"dialog",...I,style:ns,className:M(t,e,T&&`${e}-static`,!p&&"show"),onClick:d?Vr:void 0,onMouseUp:Yn,"aria-label":a,"aria-labelledby":u,"aria-describedby":s,children:c.jsx(i,{...sn,onMouseDown:Wr,className:r,contentClassName:l,children:o})});return c.jsx(Pd.Provider,{value:wo,children:c.jsx(qv,{show:h,ref:tt,backdrop:d,container:m,keyboard:!0,autoFocus:f,enforceFocus:g,restoreFocus:S,restoreFocusOptions:N,onEscapeKeyDown:Zn,onShow:x,onHide:L,onEnter:Zd,onEntering:qd,onEntered:E,onExit:Jd,onExiting:_,onExited:bd,manager:an(),transition:p?d0:void 0,backdropTransition:p?p0:void 0,renderBackdrop:ep,renderDialog:tp})})});Dd.displayName="Modal";const ee=Object.assign(Dd,{Body:l0,Header:a0,Title:f0,Footer:i0,Dialog:Md,TRANSITION_DURATION:300,BACKDROP_TRANSITION_DURATION:150}),Ca=1e3;function m0(e,t,n){const r=(e-t)/(n-t)*100;return Math.round(r*Ca)/Ca}function Ta({min:e,now:t,max:n,label:r,visuallyHidden:l,striped:o,animated:i,className:u,style:s,variant:a,bsPrefix:h,...p},d){return c.jsx("div",{ref:d,...p,role:"progressbar",className:M(u,`${h}-bar`,{[`bg-${a}`]:a,[`${h}-bar-animated`]:i,[`${h}-bar-striped`]:i||o}),style:{width:`${m0(t,e,n)}%`,...s},"aria-valuenow":t,"aria-valuemin":e,"aria-valuemax":n,children:l?c.jsx("span",{className:"visually-hidden",children:r}):r})}const Ad=v.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 Ta(r,n);const{min:l,now:o,max:i,label:u,visuallyHidden:s,striped:a,animated:h,bsPrefix:p,variant:d,className:w,children:y,...x}=r;return c.jsx("div",{ref:n,...x,className:M(w,p),children:y?kv(y,L=>v.cloneElement(L,{isChild:!0})):Ta({min:l,now:o,max:i,label:u,visuallyHidden:s,striped:a,animated:h,bsPrefix:p,variant:d},n)})});Ad.displayName="ProgressBar";const h0=Ad,Bd=v.forwardRef(({bsPrefix:e,className:t,as:n="div",...r},l)=>{const o=H(e,"row"),i=Xf(),u=Yf(),s=`${o}-cols`,a=[];return i.forEach(h=>{const p=r[h];delete r[h];let d;p!=null&&typeof p=="object"?{cols:d}=p:d=p;const w=h!==u?`-${h}`:"";d!=null&&a.push(`${s}${w}-${d}`)}),c.jsx(n,{ref:l,...r,className:M(t,o,...a)})});Bd.displayName="Row";const Ud=Bd,Hd=v.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 c.jsx(l,{ref:u,...i,className:M(o,s,r&&`${s}-${r}`,t&&`text-${t}`)})});Hd.displayName="Spinner";const Hn=Hd,Jl="initializing",Wd="paused",Vd="live",v0="error";function es(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 Qd(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 kl=e=>{const{onClick:t,disabled:n,color:r,children:l,className:o,...i}=e,u=a=>{a.stopPropagation(),!n&&t()},s=r?`text-${r}`:"";return c.jsx("a",{className:`p-1 ${s} ${o}`,onClick:u,href:"#",...i,children:l})},ln=e=>{var r,l,o;let{error:t,remove:n}=e;return t==null?null:c.jsxs(ya,{variant:"danger",onClose:n,dismissible:n!=null,children:[c.jsx(ya.Heading,{children:t.text}),((r=t.details)==null?void 0:r.statusText)&&c.jsx("p",{children:c.jsx("strong",{children:(l=t.details)==null?void 0:l.statusText})}),c.jsx("pre",{children:(o=t.details)==null?void 0:o.text})]})},g0=({id:e,show:t,onHide:n})=>{if(!t)return null;const[r,l]=v.useState(!1),[o,i]=v.useState(null),[u,s]=v.useState(!1),a=v.useContext(Hr),h=v.useContext(Ut),p=()=>{l(!1),i(null),s(!1),n()},d=()=>{s(!0),(r?h.delete:h.forget)(e).then(()=>{a.refreshTorrents(),p()}).catch(y=>{i({text:`Error deleting torrent id=${e}`,details:y}),s(!1)})};return c.jsxs(ee,{show:t,onHide:p,children:[c.jsx(ee.Header,{closeButton:!0,children:"Delete torrent"}),c.jsxs(ee.Body,{children:[c.jsx(re,{children:c.jsx(re.Group,{controlId:"delete-torrent",children:c.jsx(re.Check,{type:"checkbox",label:"Also delete files",checked:r,onChange:()=>l(!r)})})}),o&&c.jsx(ln,{error:o})]}),c.jsxs(ee.Footer,{children:[u&&c.jsx(Hn,{}),c.jsx($t,{variant:"primary",onClick:d,disabled:u,children:"OK"}),c.jsx($t,{variant:"secondary",onClick:p,children:"Cancel"})]})]})};var Kd={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},Na=he.createContext&&he.createContext(Kd),Mt=globalThis&&globalThis.__assign||function(){return Mt=Object.assign||function(e){for(var t,n=1,r=arguments.length;n{let n=t.state,[r,l]=v.useState(!1),[o,i]=v.useState(!1),u=v.useContext(Qf);const s=n=="live",a=n=="paused"||n=="error",h=v.useContext(Hr),p=v.useContext(Ut),d=()=>{l(!0),p.start(e).then(()=>{u.refresh()},L=>{h.setCloseableError({text:`Error starting torrent id=${e}`,details:L})}).finally(()=>l(!1))},w=()=>{l(!0),p.pause(e).then(()=>{u.refresh()},L=>{h.setCloseableError({text:`Error pausing torrent id=${e}`,details:L})}).finally(()=>l(!1))},y=()=>{l(!0),i(!0)},x=()=>{l(!1),i(!1)};return c.jsx(Ud,{children:c.jsxs(Yu,{children:[a&&c.jsx(kl,{onClick:d,disabled:r,color:"success",children:c.jsx(E0,{})}),s&&c.jsx(kl,{onClick:w,disabled:r,children:c.jsx(S0,{})}),c.jsx(kl,{onClick:y,disabled:r,color:"danger",children:c.jsx(k0,{})}),c.jsx(g0,{id:e,show:o,onHide:x})]})})};function ts(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 T0=({statsResponse:e})=>{var t,n;switch(e.state){case Wd:return"Paused";case Jl:return"Checking files";case v0:return"Error"}return e.state!="live"||e.live===null?e.state:c.jsxs(c.Fragment,{children:[!e.finished&&c.jsxs("div",{className:"download-speed",children:["↓ ",(t=e.live.download_speed)==null?void 0:t.human_readable]}),c.jsxs("div",{className:"upload-speed",children:["↑ ",(n=e.live.upload_speed)==null?void 0:n.human_readable,e.live.snapshot.uploaded_bytes>0&&c.jsxs("span",{children:[" ","(",ts(e.live.snapshot.uploaded_bytes),")"]})]})]})},yt=({size:e,label:t,children:n})=>c.jsxs(Yu,{md:e||1,className:"py-3",children:[c.jsx("div",{className:"fw-bold",children:t}),n]});function N0(e){return e.files.filter(n=>n.included).reduce((n,r)=>n.length>r.length?n:r).name}function _0(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 j0(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":_0(t)}const L0=({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==Jl||r==Vd)&&!u,h=l?"Error":`${s.toFixed(2)}%`,p=l?"danger":u?"success":r==Jl?"warning":"primary",d=()=>{var x;let y=(x=n==null?void 0:n.live)==null?void 0:x.snapshot.peer_stats;return y?`${y.live} / ${y.seen}`:""};let w=[];return l?w.push("bg-warning"):e%2==0&&w.push("bg-light"),c.jsxs(Ud,{className:w.join(" "),children:[c.jsx(yt,{size:3,label:"Name",children:t?c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"text-truncate",children:N0(t)}),l&&c.jsxs("p",{className:"text-danger",children:[c.jsx("strong",{children:"Error:"})," ",l]})]}):c.jsx(Hn,{})}),n?c.jsxs(c.Fragment,{children:[c.jsx(yt,{label:"Size",children:`${ts(o)} `}),c.jsx(yt,{size:2,label:(r==Wd,"Progress"),children:c.jsx(h0,{now:s,label:h,animated:a,variant:p})}),c.jsx(yt,{size:2,label:"Speed",children:c.jsx(T0,{statsResponse:n})}),c.jsx(yt,{label:"ETA",children:j0(n)}),c.jsx(yt,{size:2,label:"Live / Seen",children:d()}),c.jsx(yt,{label:"Actions",children:c.jsx(C0,{id:e,statsResponse:n})})]}):c.jsx(yt,{label:"Loading stats",size:8,children:c.jsx(Hn,{})})]})},O0=({id:e,torrent:t})=>{const[n,r]=v.useState(null),[l,o]=v.useState(null),[i,u]=v.useState(0),s=v.useContext(Ut),a=()=>{u(i+1)};return v.useEffect(()=>{if(n===null)return Qd(async()=>{await s.getTorrentDetails(t.id).then(r)},1e3)},[n]),v.useEffect(()=>es(async()=>s.getTorrentStats(t.id).then(w=>(o(w),w)).then(w=>w.state==Jl||w.state==Vd?1e3:1e4,()=>1e4),0),[i]),c.jsx(Qf.Provider,{value:{refresh:a},children:c.jsx(L0,{id:e,detailsResponse:n,statsResponse:l})})},R0=e=>{if(e.torrents===null&&e.loading)return c.jsx(Hn,{});if(e.torrents!==null)return e.torrents.length===0?c.jsx("div",{className:"text-center",children:c.jsx("p",{children:"No existing torrents found. Add them through buttons below."})}):c.jsx("div",{style:{fontSize:"smaller"},children:e.torrents.map(t=>c.jsx(O0,{id:t.id,torrent:t},t.id))})},P0=e=>{let{onHide:t,listTorrentResponse:n,listTorrentError:r,listTorrentLoading:l,data:o}=e;const[i,u]=v.useState([]),[s,a]=v.useState(!1),[h,p]=v.useState(null),[d,w]=v.useState(!1),[y,x]=v.useState(""),L=v.useContext(Hr),m=v.useContext(Ut);v.useEffect(()=>{console.log(n),u(n?n.details.files.map((E,C)=>C):[]),x((n==null?void 0:n.output_folder)||"")},[n]);const f=()=>{t(),u([]),p(null),a(!1)},g=E=>{i.includes(E)?u(i.filter(C=>C!==E)):u([...i,E])},S=async()=>{if(!n)return;a(!0);let E=n.seen_peers?n.seen_peers.slice(0,32):null,C={overwrite:!0,only_files:i,initial_peers:E,output_folder:y};d&&(C.peer_opts={connect_timeout:20,read_write_timeout:60}),m.uploadTorrent(o,C).then(()=>{t(),L.refreshTorrents()},_=>{p({text:"Error starting torrent",details:_})}).finally(()=>a(!1))},N=()=>{if(l)return c.jsx(Hn,{});if(r)return c.jsx(ln,{error:r});if(n)return c.jsxs(re,{children:[c.jsxs("fieldset",{className:"mb-4",children:[c.jsx("legend",{children:"Pick the files to download"}),n.details.files.map((E,C)=>c.jsx(re.Group,{controlId:`check-${C}`,children:c.jsx(re.Check,{type:"checkbox",label:`${E.name} (${ts(E.length)})`,checked:i.includes(C),onChange:()=>g(C)})},C))]}),c.jsxs("fieldset",{children:[c.jsx("legend",{children:"Options"}),c.jsxs(re.Group,{controlId:"output-folder",className:"mb-3",children:[c.jsx(re.Label,{children:"Output folder"}),c.jsx(re.Control,{type:"text",value:y,onChange:E=>x(E.target.value)})]}),c.jsxs(re.Group,{controlId:"unpopular-torrent",className:"mb-3",children:[c.jsx(re.Check,{type:"checkbox",label:"Increase timeouts",checked:d,onChange:()=>w(!d)}),c.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 c.jsxs(ee,{show:!0,onHide:f,size:"lg",children:[c.jsx(ee.Header,{closeButton:!0,children:c.jsx(ee.Title,{children:"Add torrent"})}),c.jsxs(ee.Body,{children:[N(),c.jsx(ln,{error:h})]}),c.jsxs(ee.Footer,{children:[s&&c.jsx(Hn,{}),c.jsx($t,{variant:"primary",onClick:S,disabled:l||s||i.length==0,children:"OK"}),c.jsx($t,{variant:"secondary",onClick:f,children:"Cancel"})]})]})},Xd=({buttonText:e,onClick:t,data:n,resetData:r,variant:l})=>{const[o,i]=v.useState(!1),[u,s]=v.useState(null),[a,h]=v.useState(null),p=v.useContext(Ut);v.useEffect(()=>{if(n===null)return;let w=setTimeout(async()=>{i(!0);try{const y=await p.uploadTorrent(n,{list_only:!0});s(y)}catch(y){h({text:"Error listing torrent files",details:y})}finally{i(!1)}},0);return()=>clearTimeout(w)},[n]);const d=()=>{r(),h(null),s(null),i(!1)};return c.jsxs(c.Fragment,{children:[c.jsx($t,{variant:l,onClick:t,className:"m-1",children:e}),n&&c.jsx(P0,{onHide:d,listTorrentError:a,listTorrentResponse:u,data:n,listTorrentLoading:o})]})},F0=({show:e,setUrl:t,cancel:n})=>{let[r,l]=v.useState("");return c.jsxs(ee,{show:e,onHide:n,size:"lg",children:[c.jsx(ee.Header,{closeButton:!0,children:c.jsx(ee.Title,{children:"Add torrent"})}),c.jsx(ee.Body,{children:c.jsx(re,{children:c.jsxs(re.Group,{className:"mb-3",controlId:"url",children:[c.jsx(re.Label,{children:"Enter magnet or HTTP(S) URL to the .torrent"}),c.jsx(re.Control,{value:r,placeholder:"magnet:?xt=urn:btih:...",onChange:o=>{l(o.target.value)}})]})})}),c.jsxs(ee.Footer,{children:[c.jsx($t,{variant:"primary",onClick:()=>{t(r),l("")},disabled:r.length==0,children:"OK"}),c.jsx($t,{variant:"secondary",onClick:n,children:"Cancel"})]})]})},M0=()=>{let[e,t]=v.useState(null),[n,r]=v.useState(!1);return c.jsxs(c.Fragment,{children:[c.jsx(Xd,{variant:"primary",buttonText:"Add Torrent from Magnet / URL",onClick:()=>{r(!0)},data:e,resetData:()=>t(null)}),c.jsx(F0,{show:n,setUrl:l=>{r(!1),t(l)},cancel:()=>{r(!1),t(null)}})]})},z0=()=>{const e=v.useRef(),[t,n]=v.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 c.jsxs(c.Fragment,{children:[c.jsx("input",{type:"file",ref:e,accept:".torrent",onChange:r,className:"d-none"}),c.jsx(Xd,{variant:"secondary",buttonText:"Upload .torrent File",onClick:o,data:t,resetData:l})]})},I0=()=>c.jsxs("div",{id:"buttons-container",className:"mt-3",children:[c.jsx(M0,{}),c.jsx(z0,{})]}),$0=e=>{let t=v.useContext(Hr);return c.jsxs(Nv,{children:[c.jsx(ln,{error:e.closeableError,remove:()=>t.setCloseableError(null)}),c.jsx(ln,{error:e.otherError}),c.jsx(R0,{torrents:e.torrents,loading:e.torrentsLoading}),c.jsx(I0,{})]})};var D0="Expected a function",_a=0/0,A0="[object Symbol]",B0=/^\s+|\s+$/g,U0=/^[-+]0x[0-9a-f]+$/i,H0=/^0b[01]+$/i,W0=/^0o[0-7]+$/i,V0=parseInt,Q0=typeof Qr=="object"&&Qr&&Qr.Object===Object&&Qr,K0=typeof self=="object"&&self&&self.Object===Object&&self,G0=Q0||K0||Function("return this")(),X0=Object.prototype,Y0=X0.toString,Z0=Math.max,J0=Math.min,Jo=function(){return G0.Date.now()};function q0(e,t,n){var r,l,o,i,u,s,a=0,h=!1,p=!1,d=!0;if(typeof e!="function")throw new TypeError(D0);t=ja(t)||0,qi(n)&&(h=!!n.leading,p="maxWait"in n,o=p?Z0(ja(n.maxWait)||0,t):o,d="trailing"in n?!!n.trailing:d);function w(E){var C=r,_=l;return r=l=void 0,a=E,i=e.apply(_,C),i}function y(E){return a=E,u=setTimeout(m,t),h?w(E):i}function x(E){var C=E-s,_=E-a,$=t-C;return p?J0($,o-_):$}function L(E){var C=E-s,_=E-a;return s===void 0||C>=t||C<0||p&&_>=o}function m(){var E=Jo();if(L(E))return f(E);u=setTimeout(m,x(E))}function f(E){return u=void 0,d&&r?w(E):(r=l=void 0,i)}function g(){u!==void 0&&clearTimeout(u),a=0,r=s=l=u=void 0}function S(){return u===void 0?i:f(Jo())}function N(){var E=Jo(),C=L(E);if(r=arguments,l=this,s=E,C){if(u===void 0)return y(s);if(p)return u=setTimeout(m,t),w(s)}return u===void 0&&(u=setTimeout(m,t)),i}return N.cancel=g,N.flush=S,N}function qi(e){var t=typeof e;return!!e&&(t=="object"||t=="function")}function b0(e){return!!e&&typeof e=="object"}function eg(e){return typeof e=="symbol"||b0(e)&&Y0.call(e)==A0}function ja(e){if(typeof e=="number")return e;if(eg(e))return _a;if(qi(e)){var t=typeof e.valueOf=="function"?e.valueOf():e;e=qi(t)?t+"":t}if(typeof e!="string")return e===0?e:+e;e=e.replace(B0,"");var n=H0.test(e);return n||W0.test(e)?V0(e.slice(2),n?2:8):U0.test(e)?_a:+e}var tg=q0;const ng=Ir(tg),rg=({span:e})=>{let t=Object.entries(e).filter(([n,r])=>n!="name");return t.length==0?null:c.jsxs(c.Fragment,{children:["{",t.map(([n,r])=>c.jsxs("span",{children:[n," = ",r]},n)).reduce((n,r)=>c.jsxs(c.Fragment,{children:[n,", ",r]})),"}"]})},lg=({span:e})=>c.jsxs(c.Fragment,{children:[c.jsx("span",{className:"fw-bold",children:e.name}),c.jsx(rg,{span:e})]}),og=({fields:e})=>c.jsxs("span",{className:`m-1 ${e.message.match(/error|fail/g)?"text-danger":"text-muted"}`,children:[e.message,Object.entries(e).filter(([t,n])=>t!="message").map(([t,n])=>c.jsxs("span",{className:"m-1",children:[c.jsx("span",{className:"fst-italic fw-bold",children:t}),"=",n]},t))]}),ig=he.memo(({line:e})=>{var r;const t=e,n=l=>{switch(l){case"DEBUG":return"text-primary";case"INFO":return"text-success";case"WARN":return"text-warning";case"ERROR":return"text-danger";default:return"text-muted"}};return c.jsxs("p",{className:"font-monospace m-0 text-break",style:{fontSize:"10px"},children:[c.jsx("span",{className:"m-1",children:t.timestamp}),c.jsx("span",{className:`m-1 ${n(t.level)}`,children:t.level}),c.jsx("span",{className:"m-1",children:(r=t.spans)==null?void 0:r.map((l,o)=>c.jsx(lg,{span:l},o))}),c.jsx("span",{className:"m-1 text-muted",children:t.target}),c.jsx(og,{fields:t.fields})]})}),ug=(e,t)=>{if(e.length===0)return t;if(t.length===0)return e;const n=new Uint8Array(e.length+t.length);return n.set(e),n.set(t,e.length),n},sg=(e,t,n)=>{const r=new AbortController,l=r.signal;let o=!1;const i=()=>{console.log("cancelling fetch"),o=!0,r.abort()},u=async()=>{let a=await fetch(e,{signal:l});if(!a.ok){let d=await a.text();throw n({text:"error fetching logs",details:{statusText:a.statusText,text:d}}),new Error("retry")}if(!a.body){n({text:"error fetching logs: ReadableStream not supported."});return}n(null);const h=a.body.getReader();let p=new Uint8Array;for(;;){const{done:d,value:w}=await h.read();if(d)throw n({text:"log stream terminated"}),new Error("retry");p=ug(p,w);for(let y;(y=p.indexOf(10))!==-1;){let x=p.slice(0,y),L=new TextDecoder().decode(x);t(L),p=p.slice(y+1)}}};let s=Qd(()=>u().then(()=>{},a=>{if(!o)throw n({text:"error streaming logs",details:{text:a.toString()}}),a}),1e3);return()=>{i(),s()}},ag=({url:e,maxLines:t})=>{const[n,r]=v.useState([]),[l,o]=v.useState(null),[i,u]=v.useState(""),s=v.useRef(null),a=t??1e3,h=v.useCallback(y=>{r(x=>[{id:x.length==0?0:x[0].id+1,content:y,parsed:JSON.parse(y),show:s.current?!!y.match(s.current):!0},...x.slice(0,a-1)])},[s.current,t]),p=v.useRef(h);p.current=h;const d=ng(y=>{let x=null;try{x=new RegExp(y)}catch{return}s.current=x,r(L=>{let m=[...L];for(let f of m)f.show=!!f.content.match(x);return m})},200),w=y=>{u(y),d(y)};return v.useEffect(()=>d.cancel,[]),v.useEffect(()=>sg(e,y=>p.current(y),o),[e]),c.jsxs("div",{children:[c.jsx(ln,{error:l}),c.jsxs("div",{className:"mb-3",children:["Showing last ",a," logs since this window was opened"]}),c.jsx(re,{children:c.jsx(re.Group,{className:"mb-3",children:c.jsx(re.Control,{type:"text",value:i,name:"filter",placeholder:"Enter filter (regex)",onChange:y=>w(y.target.value)})})}),n.map(y=>c.jsx("div",{hidden:!y.show,children:c.jsx(ig,{line:y.parsed},y.id)}))]})},cg=({show:e,onClose:t})=>{let r=v.useContext(Ut).getStreamLogsUrl();return c.jsxs(ee,{size:"xl",show:e,onHide:t,children:[c.jsx(ee.Header,{closeButton:!0,children:c.jsx(ee.Title,{children:"rqbit server logs"})}),c.jsx(ee.Body,{children:r?c.jsx(ag,{url:r}):c.jsx(ln,{error:{text:"HTTP API not available to stream logs"}})}),c.jsx(ee.Footer,{children:c.jsx($t,{variant:"primary",onClick:t,children:"Close"})})]})},fg=e=>{const[t,n]=v.useState(null),[r,l]=v.useState(null),[o,i]=v.useState(null),[u,s]=v.useState(!1);let[a,h]=v.useState(!1);const p=v.useContext(Ut),d=async()=>{s(!0);let y=await p.listTorrents().finally(()=>s(!1));i(y.torrents)};v.useEffect(()=>es(async()=>d().then(()=>(l(null),5e3),y=>(l({text:"Error refreshing torrents",details:y}),console.error(y),5e3)),0),[]);const w={setCloseableError:n,refreshTorrents:d};return c.jsxs(Hr.Provider,{value:w,children:[c.jsxs("div",{className:"text-center",children:[c.jsx("h1",{className:"mt-3 mb-4",children:e.title}),c.jsx($0,{closeableError:t,otherError:r,torrents:o,torrentsLoading:u})]}),c.jsxs("div",{className:"position-absolute top-0 start-0 p-1",children:[e.menuButtons&&e.menuButtons.map((y,x)=>c.jsx("span",{children:y},x)),c.jsx(kl,{onClick:()=>h(!0),children:c.jsx(x0,{})})]}),c.jsx(cg,{show:a,onClose:()=>h(!1)})]})},Yd=window.origin==="null"||window.origin==="http://localhost:3031"?"http://localhost:3030":"",nt=async(e,t,n)=>{console.log(e,t);const r=Yd+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()},La={getStreamLogsUrl:()=>Yd+"/stream_logs",listTorrents:()=>nt("GET","/torrents"),getTorrentDetails:e=>nt("GET",`/torrents/${e}`),getTorrentStats:e=>nt("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"),nt("POST",n,e)},pause:e=>nt("POST",`/torrents/${e}/pause`),start:e=>nt("POST",`/torrents/${e}/start`),forget:e=>nt("POST",`/torrents/${e}/forget`),delete:e=>nt("POST",`/torrents/${e}/delete`),getVersion:async()=>(await nt("GET","/")).version},dg=()=>{let[e,t]=v.useState("rqbit web UI");return v.useEffect(()=>es(()=>La.getVersion().then(r=>{const l=`rqbit web UI - v${r}`;return t(l),document.title=l,1e4},r=>1e3),0),[]),c.jsx(v.StrictMode,{children:c.jsx(Ut.Provider,{value:La,children:c.jsx(fg,{title:e})})})};qo.createRoot(document.getElementById("app")).render(c.jsx(dg,{})); +*/(function(e){(function(){var t={}.hasOwnProperty;function n(){for(var r=[],l=0;l=0)&&(n[l]=e[l]);return n}function pa(e){return"default"+e.charAt(0).toUpperCase()+e.substr(1)}function _h(e){var t=jh(e,"string");return typeof t=="symbol"?t:String(t)}function jh(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 Lh(e,t,n){var r=v.useRef(e!==void 0),l=v.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,v.useCallback(function(a){for(var h=arguments.length,p=new Array(h>1?h-1:0),d=1;d{o.target===e&&(l(),t(o))},n+r)}function bh(e){e.offsetHeight}const va=e=>!e||typeof e=="function"?e:t=>{e.current=t};function ev(e,t){const n=va(e),r=va(t);return l=>{n&&n(l),r&&r(l)}}function go(e,t){return v.useMemo(()=>ev(e,t),[e,t])}function tv(e){return e&&"setState"in e?jn.findDOMNode(e):e??null}const nv=he.forwardRef(({onEnter:e,onEntering:t,onEntered:n,onExit:r,onExiting:l,onExited:o,addEndListener:i,children:u,childRef:s,...a},h)=>{const p=v.useRef(null),d=go(p,s),w=E=>{d(tv(E))},y=E=>C=>{E&&p.current&&E(p.current,C)},x=v.useCallback(y(e),[e]),L=v.useCallback(y(t),[t]),m=v.useCallback(y(n),[n]),f=v.useCallback(y(r),[r]),g=v.useCallback(y(l),[l]),S=v.useCallback(y(o),[o]),N=v.useCallback(y(i),[i]);return c.jsx(Xh,{ref:h,...a,onEnter:x,onEntered:m,onEntering:L,onExit:f,onExited:S,onExiting:g,addEndListener:N,nodeRef:p,children:typeof u=="function"?(E,C)=>u(E,{...C,ref:w}):he.cloneElement(u,{ref:w})})}),rv=nv;function lv(e){const t=v.useRef(e);return v.useEffect(()=>{t.current=e},[e]),t}function ze(e){const t=lv(e);return v.useCallback(function(...n){return t.current&&t.current(...n)},[t])}const nd=e=>v.forwardRef((t,n)=>c.jsx("div",{...t,ref:n,className:M(t.className,e)})),rd=nd("h4");rd.displayName="DivStyledAsH4";const ld=v.forwardRef(({className:e,bsPrefix:t,as:n=rd,...r},l)=>(t=H(t,"alert-heading"),c.jsx(n,{ref:l,className:M(e,t),...r})));ld.displayName="AlertHeading";const ov=ld;function iv(){return v.useState(null)}function uv(){const e=v.useRef(!0),t=v.useRef(()=>e.current);return v.useEffect(()=>(e.current=!0,()=>{e.current=!1}),[]),t.current}function sv(e){const t=v.useRef(null);return v.useEffect(()=>{t.current=e}),t.current}const av=typeof global<"u"&&global.navigator&&global.navigator.product==="ReactNative",cv=typeof document<"u",ga=cv||av?v.useLayoutEffect:v.useEffect,fv=["as","disabled"];function dv(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 pv(e){return!e||e.trim()==="#"}function Gu({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 h=d=>{if((t||e==="a"&&pv(n))&&d.preventDefault(),t){d.stopPropagation();return}i==null||i(d)},p=d=>{d.key===" "&&(d.preventDefault(),h(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:h,onKeyDown:p},a]}const mv=v.forwardRef((e,t)=>{let{as:n,disabled:r}=e,l=dv(e,fv);const[o,{tagName:i}]=Gu(Object.assign({tagName:n,disabled:r},l));return c.jsx(i,Object.assign({},l,o,{ref:t}))});mv.displayName="Button";const hv=["onKeyDown"];function vv(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 gv(e){return!e||e.trim()==="#"}const od=v.forwardRef((e,t)=>{let{onKeyDown:n}=e,r=vv(e,hv);const[l]=Gu(Object.assign({tagName:"a"},r)),o=ze(i=>{l.onKeyDown(i),n==null||n(i)});return gv(r.href)||r.role==="button"?c.jsx("a",Object.assign({ref:t},r,l,{onKeyDown:o})):c.jsx("a",Object.assign({ref:t},r,{onKeyDown:n}))});od.displayName="Anchor";const yv=od,id=v.forwardRef(({className:e,bsPrefix:t,as:n=yv,...r},l)=>(t=H(t,"alert-link"),c.jsx(n,{ref:l,className:M(e,t),...r})));id.displayName="AlertLink";const wv=id,xv={[St]:"show",[Kt]:"show"},ud=v.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=v.useCallback((s,a)=>{bh(s),r==null||r(s,a)},[r]);return c.jsx(rv,{ref:o,addEndListener:qh,...i,onEnter:u,childRef:t.ref,children:(s,a)=>v.cloneElement(t,{...a,className:M("fade",e,t.props.className,xv[s],n[s])})})});ud.displayName="Fade";const Yl=ud,Sv={"aria-label":st.string,onClick:st.func,variant:st.oneOf(["white"])},Xu=v.forwardRef(({className:e,variant:t,"aria-label":n="Close",...r},l)=>c.jsx("button",{ref:l,type:"button",className:M("btn-close",t&&`btn-close-${t}`,e),"aria-label":n,...r}));Xu.displayName="CloseButton";Xu.propTypes=Sv;const sd=Xu,ad=v.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:h,transition:p=Yl,...d}=Oh(e,{show:"onClose"}),w=H(n,"alert"),y=ze(m=>{a&&a(!1,m)}),x=p===!0?Yl:p,L=c.jsxs("div",{role:"alert",...x?void 0:d,ref:t,className:M(i,w,s&&`${w}-${s}`,h&&`${w}-dismissible`),children:[h&&c.jsx(sd,{onClick:y,"aria-label":l,variant:o}),u]});return x?c.jsx(x,{unmountOnExit:!0,...d,ref:void 0,in:r,children:L}):r?L:null});ad.displayName="Alert";const ya=Object.assign(ad,{Link:wv,Heading:ov}),cd=v.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"),[h,{tagName:p}]=Gu({tagName:e,disabled:o,...u}),d=p;return c.jsx(d,{...h,...u,ref:s,disabled:o,className:M(i,a,l&&"active",n&&`${a}-${n}`,r&&`${a}-${r}`,u.href&&o&&"disabled")})});cd.displayName="Button";const $t=cd;function Ev(e){const t=v.useRef(e);return t.current=e,t}function fd(e){const t=Ev(e);v.useEffect(()=>()=>t.current(),[])}function kv(e,t){let n=0;return v.Children.map(e,r=>v.isValidElement(r)?t(r,n++):r)}function Cv(e,t){return v.Children.toArray(e).some(n=>v.isValidElement(n)&&n.type===t)}function Tv({as:e,bsPrefix:t,className:n,...r}){t=H(t,"col");const l=Xf(),o=Yf(),i=[],u=[];return l.forEach(s=>{const a=r[s];delete r[s];let h,p,d;typeof a=="object"&&a!=null?{span:h,offset:p,order:d}=a:h=a;const w=s!==o?`-${s}`:"";h&&i.push(h===!0?`${t}${w}`:`${t}${w}-${h}`),d!=null&&u.push(`order${w}-${d}`),p!=null&&u.push(`offset${w}-${p}`)}),[{...r,className:M(n,...i,...u)},{as:e,bsPrefix:t,spans:i}]}const dd=v.forwardRef((e,t)=>{const[{className:n,...r},{as:l="div",bsPrefix:o,spans:i}]=Tv(e);return c.jsx(l,{...r,ref:t,className:M(n,!i.length&&o)})});dd.displayName="Col";const Yu=dd,pd=v.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 c.jsx(n,{ref:o,...l,className:M(r,t?`${i}${u}`:i)})});pd.displayName="Container";const Nv=pd;var _v=Function.prototype.bind.call(Function.prototype.call,[].slice);function mn(e,t){return _v(e.querySelectorAll(t))}function wa(e,t){if(e.contains)return e.contains(t);if(e.compareDocumentPosition)return e===t||!!(e.compareDocumentPosition(t)&16)}const jv="data-rr-ui-";function Lv(e){return`${jv}${e}`}const md=v.createContext(Kn?window:void 0);md.Provider;function Zu(){return v.useContext(md)}const Ov={type:st.string,tooltip:st.bool,as:st.elementType},Ju=v.forwardRef(({as:e="div",className:t,type:n="valid",tooltip:r=!1,...l},o)=>c.jsx(e,{...l,ref:o,className:M(t,`${n}-${r?"tooltip":"feedback"}`)}));Ju.displayName="Feedback";Ju.propTypes=Ov;const hd=Ju,Rv=v.createContext({}),pt=Rv,vd=v.forwardRef(({id:e,bsPrefix:t,className:n,type:r="checkbox",isValid:l=!1,isInvalid:o=!1,as:i="input",...u},s)=>{const{controlId:a}=v.useContext(pt);return t=H(t,"form-check-input"),c.jsx(i,{...u,ref:s,type:r,id:e||a,className:M(n,t,l&&"is-valid",o&&"is-invalid")})});vd.displayName="FormCheckInput";const gd=vd,yd=v.forwardRef(({bsPrefix:e,className:t,htmlFor:n,...r},l)=>{const{controlId:o}=v.useContext(pt);return e=H(e,"form-check-label"),c.jsx("label",{...r,ref:l,htmlFor:n||o,className:M(t,e)})});yd.displayName="FormCheckLabel";const Ji=yd,wd=v.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:h,className:p,style:d,title:w="",type:y="checkbox",label:x,children:L,as:m="input",...f},g)=>{t=H(t,"form-check"),n=H(n,"form-switch");const{controlId:S}=v.useContext(pt),N=v.useMemo(()=>({controlId:e||S}),[S,e]),E=!L&&x!=null&&x!==!1||Cv(L,Ji),C=c.jsx(gd,{...f,type:y==="switch"?"checkbox":y,ref:g,isValid:i,isInvalid:u,disabled:o,as:m});return c.jsx(pt.Provider,{value:N,children:c.jsx("div",{style:d,className:M(p,E&&t,r&&`${t}-inline`,l&&`${t}-reverse`,y==="switch"&&n),children:L||c.jsxs(c.Fragment,{children:[C,E&&c.jsx(Ji,{title:w,children:x}),a&&c.jsx(hd,{type:h,tooltip:s,children:a})]})})})});wd.displayName="FormCheck";const Zl=Object.assign(wd,{Input:gd,Label:Ji}),xd=v.forwardRef(({bsPrefix:e,type:t,size:n,htmlSize:r,id:l,className:o,isValid:i=!1,isInvalid:u=!1,plaintext:s,readOnly:a,as:h="input",...p},d)=>{const{controlId:w}=v.useContext(pt);return e=H(e,"form-control"),c.jsx(h,{...p,type:t,size:r,ref:d,readOnly:a,id:l||w,className:M(o,s?`${e}-plaintext`:e,n&&`${e}-${n}`,t==="color"&&`${e}-color`,i&&"is-valid",u&&"is-invalid")})});xd.displayName="FormControl";const Pv=Object.assign(xd,{Feedback:hd}),Sd=v.forwardRef(({className:e,bsPrefix:t,as:n="div",...r},l)=>(t=H(t,"form-floating"),c.jsx(n,{ref:l,className:M(e,t),...r})));Sd.displayName="FormFloating";const Fv=Sd,Ed=v.forwardRef(({controlId:e,as:t="div",...n},r)=>{const l=v.useMemo(()=>({controlId:e}),[e]);return c.jsx(pt.Provider,{value:l,children:c.jsx(t,{...n,ref:r})})});Ed.displayName="FormGroup";const kd=Ed,Cd=v.forwardRef(({as:e="label",bsPrefix:t,column:n=!1,visuallyHidden:r=!1,className:l,htmlFor:o,...i},u)=>{const{controlId:s}=v.useContext(pt);t=H(t,"form-label");let a="col-form-label";typeof n=="string"&&(a=`${a} ${a}-${n}`);const h=M(l,t,r&&"visually-hidden",n&&a);return o=o||s,n?c.jsx(Yu,{ref:u,as:"label",className:h,htmlFor:o,...i}):c.jsx(e,{ref:u,className:h,htmlFor:o,...i})});Cd.displayName="FormLabel";const Mv=Cd,Td=v.forwardRef(({bsPrefix:e,className:t,id:n,...r},l)=>{const{controlId:o}=v.useContext(pt);return e=H(e,"form-range"),c.jsx("input",{...r,type:"range",ref:l,className:M(t,e),id:n||o})});Td.displayName="FormRange";const zv=Td,Nd=v.forwardRef(({bsPrefix:e,size:t,htmlSize:n,className:r,isValid:l=!1,isInvalid:o=!1,id:i,...u},s)=>{const{controlId:a}=v.useContext(pt);return e=H(e,"form-select"),c.jsx("select",{...u,size:n,ref:s,className:M(r,e,t&&`${e}-${t}`,l&&"is-valid",o&&"is-invalid"),id:i||a})});Nd.displayName="FormSelect";const Iv=Nd,_d=v.forwardRef(({bsPrefix:e,className:t,as:n="small",muted:r,...l},o)=>(e=H(e,"form-text"),c.jsx(n,{...l,ref:o,className:M(t,e,r&&"text-muted")})));_d.displayName="FormText";const $v=_d,jd=v.forwardRef((e,t)=>c.jsx(Zl,{...e,ref:t,type:"switch"}));jd.displayName="Switch";const Dv=Object.assign(jd,{Input:Zl.Input,Label:Zl.Label}),Ld=v.forwardRef(({bsPrefix:e,className:t,children:n,controlId:r,label:l,...o},i)=>(e=H(e,"form-floating"),c.jsxs(kd,{ref:i,className:M(t,e),controlId:r,...o,children:[n,c.jsx("label",{htmlFor:r,children:l})]})));Ld.displayName="FloatingLabel";const Av=Ld,Bv={_ref:st.any,validated:st.bool,as:st.elementType},qu=v.forwardRef(({className:e,validated:t,as:n="form",...r},l)=>c.jsx(n,{...r,ref:l,className:M(e,t&&"was-validated")}));qu.displayName="Form";qu.propTypes=Bv;const re=Object.assign(qu,{Group:kd,Control:Pv,Floating:Fv,Check:Zl,Switch:Dv,Label:Mv,Text:$v,Range:zv,Select:Iv,FloatingLabel:Av});var cl;function xa(e){if((!cl&&cl!==0||e)&&Kn){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),cl=t.offsetWidth-t.clientWidth,document.body.removeChild(t)}return cl}function Go(e){e===void 0&&(e=vo());try{var t=e.activeElement;return!t||!t.nodeName?null:t}catch{return e.body}}function Uv(e=document){const t=e.defaultView;return Math.abs(t.innerWidth-e.documentElement.clientWidth)}const Sa=Lv("modal-open");class Hv{constructor({ownerDocument:t,handleContainerOverflow:n=!0,isRTL:r=!1}={}){this.handleContainerOverflow=n,this.isRTL=r,this.modals=[],this.ownerDocument=t}getScrollbarWidth(){return Uv(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(qt(l,r)||"0",10)+t.scrollBarWidth}px`),l.setAttribute(Sa,""),qt(l,n)}reset(){[...this.modals].forEach(t=>this.remove(t))}removeContainerStyle(t){const n=this.getElement();n.removeAttribute(Sa),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 bu=Hv,Xo=(e,t)=>Kn?e==null?(t||vo()).body:(typeof e=="function"&&(e=e()),e&&"current"in e&&(e=e.current),e&&("nodeType"in e||e.getBoundingClientRect)?e:null):null;function Wv(e,t){const n=Zu(),[r,l]=v.useState(()=>Xo(e,n==null?void 0:n.document));if(!r){const o=Xo(e);o&&l(o)}return v.useEffect(()=>{t&&r&&t(r)},[t,r]),v.useEffect(()=>{const o=Xo(e);o!==r&&l(o)},[e,r]),r}function Vv({children:e,in:t,onExited:n,mountOnEnter:r,unmountOnExit:l}){const o=v.useRef(null),i=v.useRef(t),u=ze(n);v.useEffect(()=>{t?i.current=!0:u(o.current)},[t,u]);const s=go(o,e.ref),a=v.cloneElement(e,{ref:s});return t?a:l||!i.current&&r?null:a}function Qv({in:e,onTransition:t}){const n=v.useRef(null),r=v.useRef(!0),l=ze(t);return ga(()=>{if(!n.current)return;let o=!1;return l({in:e,element:n.current,initial:r.current,isStale:()=>o}),()=>{o=!0}},[e,l]),ga(()=>(r.current=!1,()=>{r.current=!0}),[]),n}function Kv({children:e,in:t,onExited:n,onEntered:r,transition:l}){const[o,i]=v.useState(!t);t&&o&&i(!1);const u=Qv({in:!!t,onTransition:a=>{const h=()=>{a.isStale()||(a.in?r==null||r(a.element,a.initial):(i(!0),n==null||n(a.element)))};Promise.resolve(l(a)).then(h,p=>{throw a.in||i(!0),p})}}),s=go(u,e.ref);return o&&!t?null:v.cloneElement(e,{ref:s})}function Ea(e,t,n){return e?c.jsx(e,Object.assign({},n)):t?c.jsx(Kv,Object.assign({},n,{transition:t})):c.jsx(Vv,Object.assign({},n))}function Gv(e){return e.code==="Escape"||e.keyCode===27}const Xv=["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 Yv(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 Yo;function Zv(e){return Yo||(Yo=new bu({ownerDocument:e==null?void 0:e.document})),Yo}function Jv(e){const t=Zu(),n=e||Zv(t),r=v.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:v.useCallback(l=>{r.current.dialog=l},[]),setBackdropRef:v.useCallback(l=>{r.current.backdrop=l},[])})}const Od=v.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:h,transition:p,runTransition:d,backdropTransition:w,runBackdropTransition:y,autoFocus:x=!0,enforceFocus:L=!0,restoreFocus:m=!0,restoreFocusOptions:f,renderDialog:g,renderBackdrop:S=K=>c.jsx("div",Object.assign({},K)),manager:N,container:E,onShow:C,onHide:_=()=>{},onExit:$,onExited:P,onExiting:se,onEnter:Ge,onEntering:Xe,onEntered:sn}=e,Gn=Yv(e,Xv);const Oe=Zu(),Ye=Wv(E),T=Jv(N),O=uv(),R=sv(n),[D,B]=v.useState(!n),pe=v.useRef(null);v.useImperativeHandle(t,()=>T,[T]),Kn&&!R&&n&&(pe.current=Go(Oe==null?void 0:Oe.document)),n&&D&&B(!1);const Re=ze(()=>{if(T.add(),cn.current=Xl(document,"keydown",wo),an.current=Xl(document,"focus",()=>setTimeout(Pe),!0),C&&C(),x){var K,Vr;const Zn=Go((K=(Vr=T.dialog)==null?void 0:Vr.ownerDocument)!=null?K:Oe==null?void 0:Oe.document);T.dialog&&Zn&&!wa(T.dialog,Zn)&&(pe.current=Zn,T.dialog.focus())}}),tt=ze(()=>{if(T.remove(),cn.current==null||cn.current(),an.current==null||an.current(),m){var K;(K=pe.current)==null||K.focus==null||K.focus(f),pe.current=null}});v.useEffect(()=>{!n||!Ye||Re()},[n,Ye,Re]),v.useEffect(()=>{D&&tt()},[D,tt]),fd(()=>{tt()});const Pe=ze(()=>{if(!L||!O()||!T.isTopModal())return;const K=Go(Oe==null?void 0:Oe.document);T.dialog&&K&&!wa(T.dialog,K)&&T.dialog.focus()}),vt=ze(K=>{K.target===K.currentTarget&&(a==null||a(K),u===!0&&_())}),wo=ze(K=>{s&&Gv(K)&&T.isTopModal()&&(h==null||h(K),K.defaultPrevented||_())}),an=v.useRef(),cn=v.useRef(),Xn=(...K)=>{B(!0),P==null||P(...K)};if(!Ye)return null;const Wr=Object.assign({role:r,ref:T.setDialogRef,"aria-modal":r==="dialog"?!0:void 0},Gn,{style:o,className:l,tabIndex:-1});let Yn=g?g(Wr):c.jsx("div",Object.assign({},Wr,{children:v.cloneElement(i,{role:"document"})}));Yn=Ea(p,d,{unmountOnExit:!0,mountOnEnter:!0,appear:!0,in:!!n,onExit:$,onExiting:se,onExited:Xn,onEnter:Ge,onEntering:Xe,onEntered:sn,children:Yn});let Ht=null;return u&&(Ht=S({ref:T.setBackdropRef,onClick:vt}),Ht=Ea(w,y,{in:!!n,appear:!0,mountOnEnter:!0,unmountOnExit:!0,children:Ht})),c.jsx(c.Fragment,{children:jn.createPortal(c.jsxs(c.Fragment,{children:[Ht,Yn]}),Ye)})});Od.displayName="Modal";const qv=Object.assign(Od,{Manager:bu});function bv(e,t){return e.classList?!!t&&e.classList.contains(t):(" "+(e.className.baseVal||e.className)+" ").indexOf(" "+t+" ")!==-1}function e0(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 ka(e,t){return e.replace(new RegExp("(^|\\s)"+t+"(?:\\s|$)","g"),"$1").replace(/\s+/g," ").replace(/^\s*|\s*$/g,"")}function t0(e,t){e.classList?e.classList.remove(t):typeof e.className=="string"?e.className=ka(e.className,t):e.setAttribute("class",ka(e.className&&e.className.baseVal||"",t))}const hn={FIXED_CONTENT:".fixed-top, .fixed-bottom, .is-fixed, .sticky-top",STICKY_CONTENT:".sticky-top",NAVBAR_TOGGLER:".navbar-toggler"};class n0 extends bu{adjustAndStore(t,n,r){const l=n.style[t];n.dataset[t]=l,qt(n,{[t]:`${parseFloat(qt(n,t))+r}px`})}restore(t,n){const r=n.dataset[t];r!==void 0&&(delete n.dataset[t],qt(n,{[t]:r}))}setContainerStyle(t){super.setContainerStyle(t);const n=this.getElement();if(e0(n,"modal-open"),!t.scrollBarWidth)return;const r=this.isRTL?"paddingLeft":"paddingRight",l=this.isRTL?"marginLeft":"marginRight";mn(n,hn.FIXED_CONTENT).forEach(o=>this.adjustAndStore(r,o,t.scrollBarWidth)),mn(n,hn.STICKY_CONTENT).forEach(o=>this.adjustAndStore(l,o,-t.scrollBarWidth)),mn(n,hn.NAVBAR_TOGGLER).forEach(o=>this.adjustAndStore(l,o,t.scrollBarWidth))}removeContainerStyle(t){super.removeContainerStyle(t);const n=this.getElement();t0(n,"modal-open");const r=this.isRTL?"paddingLeft":"paddingRight",l=this.isRTL?"marginLeft":"marginRight";mn(n,hn.FIXED_CONTENT).forEach(o=>this.restore(r,o)),mn(n,hn.STICKY_CONTENT).forEach(o=>this.restore(l,o)),mn(n,hn.NAVBAR_TOGGLER).forEach(o=>this.restore(l,o))}}let Zo;function r0(e){return Zo||(Zo=new n0(e)),Zo}const Rd=v.forwardRef(({className:e,bsPrefix:t,as:n="div",...r},l)=>(t=H(t,"modal-body"),c.jsx(n,{ref:l,className:M(e,t),...r})));Rd.displayName="ModalBody";const l0=Rd,o0=v.createContext({onHide(){}}),Pd=o0,Fd=v.forwardRef(({bsPrefix:e,className:t,contentClassName:n,centered:r,size:l,fullscreen:o,children:i,scrollable:u,...s},a)=>{e=H(e,"modal");const h=`${e}-dialog`,p=typeof o=="string"?`${e}-fullscreen-${o}`:`${e}-fullscreen`;return c.jsx("div",{...s,ref:a,className:M(h,t,l&&`${e}-${l}`,r&&`${h}-centered`,u&&`${h}-scrollable`,o&&p),children:c.jsx("div",{className:M(`${e}-content`,n),children:i})})});Fd.displayName="ModalDialog";const Md=Fd,zd=v.forwardRef(({className:e,bsPrefix:t,as:n="div",...r},l)=>(t=H(t,"modal-footer"),c.jsx(n,{ref:l,className:M(e,t),...r})));zd.displayName="ModalFooter";const i0=zd,u0=v.forwardRef(({closeLabel:e="Close",closeVariant:t,closeButton:n=!1,onHide:r,children:l,...o},i)=>{const u=v.useContext(Pd),s=ze(()=>{u==null||u.onHide(),r==null||r()});return c.jsxs("div",{ref:i,...o,children:[l,n&&c.jsx(sd,{"aria-label":e,variant:t,onClick:s})]})}),s0=u0,Id=v.forwardRef(({bsPrefix:e,className:t,closeLabel:n="Close",closeButton:r=!1,...l},o)=>(e=H(e,"modal-header"),c.jsx(s0,{ref:o,...l,className:M(t,e),closeLabel:n,closeButton:r})));Id.displayName="ModalHeader";const a0=Id,c0=nd("h4"),$d=v.forwardRef(({className:e,bsPrefix:t,as:n=c0,...r},l)=>(t=H(t,"modal-title"),c.jsx(n,{ref:l,className:M(e,t),...r})));$d.displayName="ModalTitle";const f0=$d;function d0(e){return c.jsx(Yl,{...e,timeout:null})}function p0(e){return c.jsx(Yl,{...e,timeout:null})}const Dd=v.forwardRef(({bsPrefix:e,className:t,style:n,dialogClassName:r,contentClassName:l,children:o,dialogAs:i=Md,"aria-labelledby":u,"aria-describedby":s,"aria-label":a,show:h=!1,animation:p=!0,backdrop:d=!0,keyboard:w=!0,onEscapeKeyDown:y,onShow:x,onHide:L,container:m,autoFocus:f=!0,enforceFocus:g=!0,restoreFocus:S=!0,restoreFocusOptions:N,onEntered:E,onExit:C,onExiting:_,onEnter:$,onEntering:P,onExited:se,backdropClassName:Ge,manager:Xe,...sn},Gn)=>{const[Oe,Ye]=v.useState({}),[T,O]=v.useState(!1),R=v.useRef(!1),D=v.useRef(!1),B=v.useRef(null),[pe,Re]=iv(),tt=go(Gn,Re),Pe=ze(L),vt=Mh();e=H(e,"modal");const wo=v.useMemo(()=>({onHide:Pe}),[Pe]);function an(){return Xe||r0({isRTL:vt})}function cn(I){if(!Kn)return;const fn=an().getScrollbarWidth()>0,rs=I.scrollHeight>vo(I).documentElement.clientHeight;Ye({paddingRight:fn&&!rs?xa():void 0,paddingLeft:!fn&&rs?xa():void 0})}const Xn=ze(()=>{pe&&cn(pe.dialog)});fd(()=>{Zi(window,"resize",Xn),B.current==null||B.current()});const Wr=()=>{R.current=!0},Yn=I=>{R.current&&pe&&I.target===pe.dialog&&(D.current=!0),R.current=!1},Ht=()=>{O(!0),B.current=td(pe.dialog,()=>{O(!1)})},K=I=>{I.target===I.currentTarget&&Ht()},Vr=I=>{if(d==="static"){K(I);return}if(D.current||I.target!==I.currentTarget){D.current=!1;return}L==null||L()},Zn=I=>{w?y==null||y(I):(I.preventDefault(),d==="static"&&Ht())},Zd=(I,fn)=>{I&&cn(I),$==null||$(I,fn)},Jd=I=>{B.current==null||B.current(),C==null||C(I)},qd=(I,fn)=>{P==null||P(I,fn),ed(window,"resize",Xn)},bd=I=>{I&&(I.style.display=""),se==null||se(I),Zi(window,"resize",Xn)},ep=v.useCallback(I=>c.jsx("div",{...I,className:M(`${e}-backdrop`,Ge,!p&&"show")}),[p,Ge,e]),ns={...n,...Oe};ns.display="block";const tp=I=>c.jsx("div",{role:"dialog",...I,style:ns,className:M(t,e,T&&`${e}-static`,!p&&"show"),onClick:d?Vr:void 0,onMouseUp:Yn,"aria-label":a,"aria-labelledby":u,"aria-describedby":s,children:c.jsx(i,{...sn,onMouseDown:Wr,className:r,contentClassName:l,children:o})});return c.jsx(Pd.Provider,{value:wo,children:c.jsx(qv,{show:h,ref:tt,backdrop:d,container:m,keyboard:!0,autoFocus:f,enforceFocus:g,restoreFocus:S,restoreFocusOptions:N,onEscapeKeyDown:Zn,onShow:x,onHide:L,onEnter:Zd,onEntering:qd,onEntered:E,onExit:Jd,onExiting:_,onExited:bd,manager:an(),transition:p?d0:void 0,backdropTransition:p?p0:void 0,renderBackdrop:ep,renderDialog:tp})})});Dd.displayName="Modal";const ee=Object.assign(Dd,{Body:l0,Header:a0,Title:f0,Footer:i0,Dialog:Md,TRANSITION_DURATION:300,BACKDROP_TRANSITION_DURATION:150}),Ca=1e3;function m0(e,t,n){const r=(e-t)/(n-t)*100;return Math.round(r*Ca)/Ca}function Ta({min:e,now:t,max:n,label:r,visuallyHidden:l,striped:o,animated:i,className:u,style:s,variant:a,bsPrefix:h,...p},d){return c.jsx("div",{ref:d,...p,role:"progressbar",className:M(u,`${h}-bar`,{[`bg-${a}`]:a,[`${h}-bar-animated`]:i,[`${h}-bar-striped`]:i||o}),style:{width:`${m0(t,e,n)}%`,...s},"aria-valuenow":t,"aria-valuemin":e,"aria-valuemax":n,children:l?c.jsx("span",{className:"visually-hidden",children:r}):r})}const Ad=v.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 Ta(r,n);const{min:l,now:o,max:i,label:u,visuallyHidden:s,striped:a,animated:h,bsPrefix:p,variant:d,className:w,children:y,...x}=r;return c.jsx("div",{ref:n,...x,className:M(w,p),children:y?kv(y,L=>v.cloneElement(L,{isChild:!0})):Ta({min:l,now:o,max:i,label:u,visuallyHidden:s,striped:a,animated:h,bsPrefix:p,variant:d},n)})});Ad.displayName="ProgressBar";const h0=Ad,Bd=v.forwardRef(({bsPrefix:e,className:t,as:n="div",...r},l)=>{const o=H(e,"row"),i=Xf(),u=Yf(),s=`${o}-cols`,a=[];return i.forEach(h=>{const p=r[h];delete r[h];let d;p!=null&&typeof p=="object"?{cols:d}=p:d=p;const w=h!==u?`-${h}`:"";d!=null&&a.push(`${s}${w}-${d}`)}),c.jsx(n,{ref:l,...r,className:M(t,o,...a)})});Bd.displayName="Row";const Ud=Bd,Hd=v.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 c.jsx(l,{ref:u,...i,className:M(o,s,r&&`${s}-${r}`,t&&`text-${t}`)})});Hd.displayName="Spinner";const Hn=Hd,Jl="initializing",Wd="paused",Vd="live",v0="error";function es(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 Qd(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 kl=e=>{const{onClick:t,disabled:n,color:r,children:l,className:o,...i}=e,u=a=>{a.stopPropagation(),!n&&t()},s=r?`text-${r}`:"";return c.jsx("a",{className:`p-1 ${s} ${o}`,onClick:u,href:"#",...i,children:l})},ln=e=>{var r,l,o;let{error:t,remove:n}=e;return t==null?null:c.jsxs(ya,{variant:"danger",onClose:n,dismissible:n!=null,children:[c.jsx(ya.Heading,{children:t.text}),((r=t.details)==null?void 0:r.statusText)&&c.jsx("p",{children:c.jsx("strong",{children:(l=t.details)==null?void 0:l.statusText})}),c.jsx("pre",{children:(o=t.details)==null?void 0:o.text})]})},g0=({id:e,show:t,onHide:n})=>{if(!t)return null;const[r,l]=v.useState(!1),[o,i]=v.useState(null),[u,s]=v.useState(!1),a=v.useContext(Hr),h=v.useContext(Ut),p=()=>{l(!1),i(null),s(!1),n()},d=()=>{s(!0),(r?h.delete:h.forget)(e).then(()=>{a.refreshTorrents(),p()}).catch(y=>{i({text:`Error deleting torrent id=${e}`,details:y}),s(!1)})};return c.jsxs(ee,{show:t,onHide:p,children:[c.jsx(ee.Header,{closeButton:!0,children:"Delete torrent"}),c.jsxs(ee.Body,{children:[c.jsx(re,{children:c.jsx(re.Group,{controlId:"delete-torrent",children:c.jsx(re.Check,{type:"checkbox",label:"Also delete files",checked:r,onChange:()=>l(!r)})})}),o&&c.jsx(ln,{error:o})]}),c.jsxs(ee.Footer,{children:[u&&c.jsx(Hn,{}),c.jsx($t,{variant:"primary",onClick:d,disabled:u,children:"OK"}),c.jsx($t,{variant:"secondary",onClick:p,children:"Cancel"})]})]})};var Kd={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},Na=he.createContext&&he.createContext(Kd),Mt=globalThis&&globalThis.__assign||function(){return Mt=Object.assign||function(e){for(var t,n=1,r=arguments.length;n{let n=t.state,[r,l]=v.useState(!1),[o,i]=v.useState(!1),u=v.useContext(Qf);const s=n=="live",a=n=="paused"||n=="error",h=v.useContext(Hr),p=v.useContext(Ut),d=()=>{l(!0),p.start(e).then(()=>{u.refresh()},L=>{h.setCloseableError({text:`Error starting torrent id=${e}`,details:L})}).finally(()=>l(!1))},w=()=>{l(!0),p.pause(e).then(()=>{u.refresh()},L=>{h.setCloseableError({text:`Error pausing torrent id=${e}`,details:L})}).finally(()=>l(!1))},y=()=>{l(!0),i(!0)},x=()=>{l(!1),i(!1)};return c.jsx(Ud,{children:c.jsxs(Yu,{children:[a&&c.jsx(kl,{onClick:d,disabled:r,color:"success",children:c.jsx(E0,{})}),s&&c.jsx(kl,{onClick:w,disabled:r,children:c.jsx(S0,{})}),c.jsx(kl,{onClick:y,disabled:r,color:"danger",children:c.jsx(k0,{})}),c.jsx(g0,{id:e,show:o,onHide:x})]})})};function ts(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 T0=({statsResponse:e})=>{var t,n;switch(e.state){case Wd:return"Paused";case Jl:return"Checking files";case v0:return"Error"}return e.state!="live"||e.live===null?e.state:c.jsxs(c.Fragment,{children:[!e.finished&&c.jsxs("div",{className:"download-speed",children:["↓ ",(t=e.live.download_speed)==null?void 0:t.human_readable]}),c.jsxs("div",{className:"upload-speed",children:["↑ ",(n=e.live.upload_speed)==null?void 0:n.human_readable,e.live.snapshot.uploaded_bytes>0&&c.jsxs("span",{children:[" ","(",ts(e.live.snapshot.uploaded_bytes),")"]})]})]})},yt=({size:e,label:t,children:n})=>c.jsxs(Yu,{md:e||1,className:"py-3",children:[c.jsx("div",{className:"fw-bold",children:t}),n]});function N0(e){return e.files.filter(n=>n.included).reduce((n,r)=>n.length>r.length?n:r).name}function _0(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 j0(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":_0(t)}const L0=({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==Jl||r==Vd)&&!u,h=l?"Error":`${s.toFixed(2)}%`,p=l?"danger":u?"success":r==Jl?"warning":"primary",d=()=>{var x;let y=(x=n==null?void 0:n.live)==null?void 0:x.snapshot.peer_stats;return y?`${y.live} / ${y.seen}`:""};let w=[];return l?w.push("bg-warning"):e%2==0&&w.push("bg-light"),c.jsxs(Ud,{className:w.join(" "),children:[c.jsx(yt,{size:3,label:"Name",children:t?c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"text-truncate",children:N0(t)}),l&&c.jsxs("p",{className:"text-danger",children:[c.jsx("strong",{children:"Error:"})," ",l]})]}):c.jsx(Hn,{})}),n?c.jsxs(c.Fragment,{children:[c.jsx(yt,{label:"Size",children:`${ts(o)} `}),c.jsx(yt,{size:2,label:(r==Wd,"Progress"),children:c.jsx(h0,{now:s,label:h,animated:a,variant:p})}),c.jsx(yt,{size:2,label:"Speed",children:c.jsx(T0,{statsResponse:n})}),c.jsx(yt,{label:"ETA",children:j0(n)}),c.jsx(yt,{size:2,label:"Live / Seen",children:d()}),c.jsx(yt,{label:"Actions",children:c.jsx(C0,{id:e,statsResponse:n})})]}):c.jsx(yt,{label:"Loading stats",size:8,children:c.jsx(Hn,{})})]})},O0=({id:e,torrent:t})=>{const[n,r]=v.useState(null),[l,o]=v.useState(null),[i,u]=v.useState(0),s=v.useContext(Ut),a=()=>{u(i+1)};return v.useEffect(()=>{if(n===null)return Qd(async()=>{await s.getTorrentDetails(t.id).then(r)},1e3)},[n]),v.useEffect(()=>es(async()=>s.getTorrentStats(t.id).then(w=>(o(w),w)).then(w=>w.state==Jl||w.state==Vd?1e3:1e4,()=>1e4),0),[i]),c.jsx(Qf.Provider,{value:{refresh:a},children:c.jsx(L0,{id:e,detailsResponse:n,statsResponse:l})})},R0=e=>{if(e.torrents===null&&e.loading)return c.jsx(Hn,{});if(e.torrents!==null)return e.torrents.length===0?c.jsx("div",{className:"text-center",children:c.jsx("p",{children:"No existing torrents found. Add them through buttons below."})}):c.jsx("div",{style:{fontSize:"smaller"},children:e.torrents.map(t=>c.jsx(O0,{id:t.id,torrent:t},t.id))})},P0=e=>{let{onHide:t,listTorrentResponse:n,listTorrentError:r,listTorrentLoading:l,data:o}=e;const[i,u]=v.useState([]),[s,a]=v.useState(!1),[h,p]=v.useState(null),[d,w]=v.useState(!1),[y,x]=v.useState(""),L=v.useContext(Hr),m=v.useContext(Ut);v.useEffect(()=>{console.log(n),u(n?n.details.files.map((E,C)=>C):[]),x((n==null?void 0:n.output_folder)||"")},[n]);const f=()=>{t(),u([]),p(null),a(!1)},g=E=>{i.includes(E)?u(i.filter(C=>C!==E)):u([...i,E])},S=async()=>{if(!n)return;a(!0);let E=n.seen_peers?n.seen_peers.slice(0,32):null,C={overwrite:!0,only_files:i,initial_peers:E,output_folder:y};d&&(C.peer_opts={connect_timeout:20,read_write_timeout:60}),m.uploadTorrent(o,C).then(()=>{t(),L.refreshTorrents()},_=>{p({text:"Error starting torrent",details:_})}).finally(()=>a(!1))},N=()=>{if(l)return c.jsx(Hn,{});if(r)return c.jsx(ln,{error:r});if(n)return c.jsxs(re,{children:[c.jsxs("fieldset",{className:"mb-4",children:[c.jsx("legend",{children:"Pick the files to download"}),n.details.files.map((E,C)=>c.jsx(re.Group,{controlId:`check-${C}`,children:c.jsx(re.Check,{type:"checkbox",label:`${E.name} (${ts(E.length)})`,checked:i.includes(C),onChange:()=>g(C)})},C))]}),c.jsxs("fieldset",{children:[c.jsx("legend",{children:"Options"}),c.jsxs(re.Group,{controlId:"output-folder",className:"mb-3",children:[c.jsx(re.Label,{children:"Output folder"}),c.jsx(re.Control,{type:"text",value:y,onChange:E=>x(E.target.value)})]}),c.jsxs(re.Group,{controlId:"unpopular-torrent",className:"mb-3",children:[c.jsx(re.Check,{type:"checkbox",label:"Increase timeouts",checked:d,onChange:()=>w(!d)}),c.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 c.jsxs(ee,{show:!0,onHide:f,size:"lg",children:[c.jsx(ee.Header,{closeButton:!0,children:c.jsx(ee.Title,{children:"Add torrent"})}),c.jsxs(ee.Body,{children:[N(),c.jsx(ln,{error:h})]}),c.jsxs(ee.Footer,{children:[s&&c.jsx(Hn,{}),c.jsx($t,{variant:"primary",onClick:S,disabled:l||s||i.length==0,children:"OK"}),c.jsx($t,{variant:"secondary",onClick:f,children:"Cancel"})]})]})},Xd=({buttonText:e,onClick:t,data:n,resetData:r,variant:l})=>{const[o,i]=v.useState(!1),[u,s]=v.useState(null),[a,h]=v.useState(null),p=v.useContext(Ut);v.useEffect(()=>{if(n===null)return;let w=setTimeout(async()=>{i(!0);try{const y=await p.uploadTorrent(n,{list_only:!0});s(y)}catch(y){h({text:"Error listing torrent files",details:y})}finally{i(!1)}},0);return()=>clearTimeout(w)},[n]);const d=()=>{r(),h(null),s(null),i(!1)};return c.jsxs(c.Fragment,{children:[c.jsx($t,{variant:l,onClick:t,className:"m-1",children:e}),n&&c.jsx(P0,{onHide:d,listTorrentError:a,listTorrentResponse:u,data:n,listTorrentLoading:o})]})},F0=({show:e,setUrl:t,cancel:n})=>{let[r,l]=v.useState("");return c.jsxs(ee,{show:e,onHide:n,size:"lg",children:[c.jsx(ee.Header,{closeButton:!0,children:c.jsx(ee.Title,{children:"Add torrent"})}),c.jsx(ee.Body,{children:c.jsx(re,{children:c.jsxs(re.Group,{className:"mb-3",controlId:"url",children:[c.jsx(re.Label,{children:"Enter magnet or HTTP(S) URL to the .torrent"}),c.jsx(re.Control,{value:r,placeholder:"magnet:?xt=urn:btih:...",onChange:o=>{l(o.target.value)}})]})})}),c.jsxs(ee.Footer,{children:[c.jsx($t,{variant:"primary",onClick:()=>{t(r),l("")},disabled:r.length==0,children:"OK"}),c.jsx($t,{variant:"secondary",onClick:n,children:"Cancel"})]})]})},M0=()=>{let[e,t]=v.useState(null),[n,r]=v.useState(!1);return c.jsxs(c.Fragment,{children:[c.jsx(Xd,{variant:"primary",buttonText:"Add Torrent from Magnet / URL",onClick:()=>{r(!0)},data:e,resetData:()=>t(null)}),c.jsx(F0,{show:n,setUrl:l=>{r(!1),t(l)},cancel:()=>{r(!1),t(null)}})]})},z0=()=>{const e=v.useRef(),[t,n]=v.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 c.jsxs(c.Fragment,{children:[c.jsx("input",{type:"file",ref:e,accept:".torrent",onChange:r,className:"d-none"}),c.jsx(Xd,{variant:"secondary",buttonText:"Upload .torrent File",onClick:o,data:t,resetData:l})]})},I0=()=>c.jsxs("div",{id:"buttons-container",className:"mt-3",children:[c.jsx(M0,{}),c.jsx(z0,{})]}),$0=e=>{let t=v.useContext(Hr);return c.jsxs(Nv,{children:[c.jsx(ln,{error:e.closeableError,remove:()=>t.setCloseableError(null)}),c.jsx(ln,{error:e.otherError}),c.jsx(R0,{torrents:e.torrents,loading:e.torrentsLoading}),c.jsx(I0,{})]})};var D0="Expected a function",_a=0/0,A0="[object Symbol]",B0=/^\s+|\s+$/g,U0=/^[-+]0x[0-9a-f]+$/i,H0=/^0b[01]+$/i,W0=/^0o[0-7]+$/i,V0=parseInt,Q0=typeof Qr=="object"&&Qr&&Qr.Object===Object&&Qr,K0=typeof self=="object"&&self&&self.Object===Object&&self,G0=Q0||K0||Function("return this")(),X0=Object.prototype,Y0=X0.toString,Z0=Math.max,J0=Math.min,Jo=function(){return G0.Date.now()};function q0(e,t,n){var r,l,o,i,u,s,a=0,h=!1,p=!1,d=!0;if(typeof e!="function")throw new TypeError(D0);t=ja(t)||0,qi(n)&&(h=!!n.leading,p="maxWait"in n,o=p?Z0(ja(n.maxWait)||0,t):o,d="trailing"in n?!!n.trailing:d);function w(E){var C=r,_=l;return r=l=void 0,a=E,i=e.apply(_,C),i}function y(E){return a=E,u=setTimeout(m,t),h?w(E):i}function x(E){var C=E-s,_=E-a,$=t-C;return p?J0($,o-_):$}function L(E){var C=E-s,_=E-a;return s===void 0||C>=t||C<0||p&&_>=o}function m(){var E=Jo();if(L(E))return f(E);u=setTimeout(m,x(E))}function f(E){return u=void 0,d&&r?w(E):(r=l=void 0,i)}function g(){u!==void 0&&clearTimeout(u),a=0,r=s=l=u=void 0}function S(){return u===void 0?i:f(Jo())}function N(){var E=Jo(),C=L(E);if(r=arguments,l=this,s=E,C){if(u===void 0)return y(s);if(p)return u=setTimeout(m,t),w(s)}return u===void 0&&(u=setTimeout(m,t)),i}return N.cancel=g,N.flush=S,N}function qi(e){var t=typeof e;return!!e&&(t=="object"||t=="function")}function b0(e){return!!e&&typeof e=="object"}function eg(e){return typeof e=="symbol"||b0(e)&&Y0.call(e)==A0}function ja(e){if(typeof e=="number")return e;if(eg(e))return _a;if(qi(e)){var t=typeof e.valueOf=="function"?e.valueOf():e;e=qi(t)?t+"":t}if(typeof e!="string")return e===0?e:+e;e=e.replace(B0,"");var n=H0.test(e);return n||W0.test(e)?V0(e.slice(2),n?2:8):U0.test(e)?_a:+e}var tg=q0;const ng=Ir(tg),rg=({span:e})=>{let t=Object.entries(e).filter(([n,r])=>n!="name");return t.length==0?null:c.jsxs(c.Fragment,{children:["{",t.map(([n,r])=>c.jsxs("span",{children:[n," = ",r]},n)).reduce((n,r)=>c.jsxs(c.Fragment,{children:[n,", ",r]})),"}"]})},lg=({span:e})=>c.jsxs(c.Fragment,{children:[c.jsx("span",{className:"fw-bold",children:e.name}),c.jsx(rg,{span:e})]}),og=({fields:e})=>c.jsxs("span",{className:`m-1 ${e.message.match(/error|fail/g)?"text-danger":"text-muted"}`,children:[e.message,Object.entries(e).filter(([t,n])=>t!="message").map(([t,n])=>c.jsxs("span",{className:"m-1",children:[c.jsx("span",{className:"fst-italic fw-bold",children:t}),"=",n]},t))]}),ig=he.memo(({line:e})=>{var r;const t=e,n=l=>{switch(l){case"DEBUG":return"text-primary";case"INFO":return"text-success";case"WARN":return"text-warning";case"ERROR":return"text-danger";default:return"text-muted"}};return c.jsxs("p",{className:"font-monospace m-0 text-break",style:{fontSize:"10px"},children:[c.jsx("span",{className:"m-1",children:t.timestamp}),c.jsx("span",{className:`m-1 ${n(t.level)}`,children:t.level}),c.jsx("span",{className:"m-1",children:(r=t.spans)==null?void 0:r.map((l,o)=>c.jsx(lg,{span:l},o))}),c.jsx("span",{className:"m-1 text-muted",children:t.target}),c.jsx(og,{fields:t.fields})]})}),ug=(e,t)=>{if(e.length===0)return t;if(t.length===0)return e;const n=new Uint8Array(e.length+t.length);return n.set(e),n.set(t,e.length),n},sg=(e,t,n)=>{const r=new AbortController,l=r.signal;let o=!1;const i=()=>{console.log("cancelling fetch"),o=!0,r.abort()},u=async()=>{let a=await fetch(e,{signal:l});if(!a.ok){let d=await a.text();throw n({text:"error fetching logs",details:{statusText:a.statusText,text:d}}),null}if(!a.body){n({text:"error fetching logs: ReadableStream not supported."});return}n(null);const h=a.body.getReader();let p=new Uint8Array;for(;;){const{done:d,value:w}=await h.read();if(d)throw n({text:"log stream terminated"}),null;p=ug(p,w);for(let y;(y=p.indexOf(10))!==-1;){let x=p.slice(0,y),L=new TextDecoder().decode(x);t(L),p=p.slice(y+1)}}};let s=Qd(()=>u().then(()=>{},a=>{if(!o&&a!==null)throw n({text:"error streaming logs",details:{text:a.toString()}}),a}),1e3);return()=>{i(),s()}},ag=({url:e,maxLines:t})=>{const[n,r]=v.useState([]),[l,o]=v.useState(null),[i,u]=v.useState(""),s=v.useRef(null),a=t??1e3,h=v.useCallback(y=>{r(x=>[{id:x.length==0?0:x[0].id+1,content:y,parsed:JSON.parse(y),show:s.current?!!y.match(s.current):!0},...x.slice(0,a-1)])},[s.current,t]),p=v.useRef(h);p.current=h;const d=ng(y=>{let x=null;try{x=new RegExp(y)}catch{return}s.current=x,r(L=>{let m=[...L];for(let f of m)f.show=!!f.content.match(x);return m})},200),w=y=>{u(y),d(y)};return v.useEffect(()=>d.cancel,[]),v.useEffect(()=>sg(e,y=>p.current(y),o),[e]),c.jsxs("div",{children:[c.jsx(ln,{error:l}),c.jsxs("div",{className:"mb-3",children:["Showing last ",a," logs since this window was opened"]}),c.jsx(re,{children:c.jsx(re.Group,{className:"mb-3",children:c.jsx(re.Control,{type:"text",value:i,name:"filter",placeholder:"Enter filter (regex)",onChange:y=>w(y.target.value)})})}),n.map(y=>c.jsx("div",{hidden:!y.show,children:c.jsx(ig,{line:y.parsed},y.id)}))]})},cg=({show:e,onClose:t})=>{let r=v.useContext(Ut).getStreamLogsUrl();return c.jsxs(ee,{size:"xl",show:e,onHide:t,children:[c.jsx(ee.Header,{closeButton:!0,children:c.jsx(ee.Title,{children:"rqbit server logs"})}),c.jsx(ee.Body,{children:r?c.jsx(ag,{url:r}):c.jsx(ln,{error:{text:"HTTP API not available to stream logs"}})}),c.jsx(ee.Footer,{children:c.jsx($t,{variant:"primary",onClick:t,children:"Close"})})]})},fg=e=>{const[t,n]=v.useState(null),[r,l]=v.useState(null),[o,i]=v.useState(null),[u,s]=v.useState(!1);let[a,h]=v.useState(!1);const p=v.useContext(Ut),d=async()=>{s(!0);let y=await p.listTorrents().finally(()=>s(!1));i(y.torrents)};v.useEffect(()=>es(async()=>d().then(()=>(l(null),5e3),y=>(l({text:"Error refreshing torrents",details:y}),console.error(y),5e3)),0),[]);const w={setCloseableError:n,refreshTorrents:d};return c.jsxs(Hr.Provider,{value:w,children:[c.jsxs("div",{className:"text-center",children:[c.jsx("h1",{className:"mt-3 mb-4",children:e.title}),c.jsx($0,{closeableError:t,otherError:r,torrents:o,torrentsLoading:u})]}),c.jsxs("div",{className:"position-absolute top-0 start-0 p-1",children:[e.menuButtons&&e.menuButtons.map((y,x)=>c.jsx("span",{children:y},x)),c.jsx(kl,{onClick:()=>h(!0),children:c.jsx(x0,{})})]}),c.jsx(cg,{show:a,onClose:()=>h(!1)})]})},Yd=window.origin==="null"||window.origin==="http://localhost:3031"?"http://localhost:3030":"",nt=async(e,t,n)=>{console.log(e,t);const r=Yd+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()},La={getStreamLogsUrl:()=>Yd+"/stream_logs",listTorrents:()=>nt("GET","/torrents"),getTorrentDetails:e=>nt("GET",`/torrents/${e}`),getTorrentStats:e=>nt("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"),nt("POST",n,e)},pause:e=>nt("POST",`/torrents/${e}/pause`),start:e=>nt("POST",`/torrents/${e}/start`),forget:e=>nt("POST",`/torrents/${e}/forget`),delete:e=>nt("POST",`/torrents/${e}/delete`),getVersion:async()=>(await nt("GET","/")).version},dg=()=>{let[e,t]=v.useState("rqbit web UI");return v.useEffect(()=>es(()=>La.getVersion().then(r=>{const l=`rqbit web UI - v${r}`;return t(l),document.title=l,1e4},r=>1e3),0),[]),c.jsx(v.StrictMode,{children:c.jsx(Ut.Provider,{value:La,children:c.jsx(fg,{title:e})})})};qo.createRoot(document.getElementById("app")).render(c.jsx(dg,{})); diff --git a/crates/librqbit/webui/dist/manifest.json b/crates/librqbit/webui/dist/manifest.json index 7156632..e787636 100644 --- a/crates/librqbit/webui/dist/manifest.json +++ b/crates/librqbit/webui/dist/manifest.json @@ -4,7 +4,7 @@ "src": "assets/logo.svg" }, "index.html": { - "file": "assets/index-b804d1c8.js", + "file": "assets/index-af1222d3.js", "isEntry": true, "src": "index.html" } diff --git a/crates/librqbit/webui/src/components/LogStream.tsx b/crates/librqbit/webui/src/components/LogStream.tsx index d0f7cce..ba021f7 100644 --- a/crates/librqbit/webui/src/components/LogStream.tsx +++ b/crates/librqbit/webui/src/components/LogStream.tsx @@ -66,7 +66,7 @@ const streamLogs = ( text, }, }); - throw new Error("retry"); + throw null; } if (!response.body) { @@ -88,7 +88,7 @@ const streamLogs = ( setError({ text: "log stream terminated", }); - throw new Error("retry"); + throw null; } buffer = mergeBuffers(buffer, value); @@ -110,6 +110,10 @@ const streamLogs = ( if (canceled) { return; } + if (e === null) { + // We already set the error. + return; + } setError({ text: "error streaming logs", details: {