diff --git a/Cargo.lock b/Cargo.lock index f0b3c3b..8ef2a12 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1253,7 +1253,7 @@ dependencies = [ [[package]] name = "librqbit" -version = "5.4.0" +version = "5.4.1" dependencies = [ "anyhow", "axum 0.7.2", @@ -1326,7 +1326,7 @@ version = "2.2.1" [[package]] name = "librqbit-core" -version = "3.4.0" +version = "3.5.0" dependencies = [ "anyhow", "directories", diff --git a/crates/librqbit/Cargo.toml b/crates/librqbit/Cargo.toml index e16f504..a40a3c7 100644 --- a/crates/librqbit/Cargo.toml +++ b/crates/librqbit/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "librqbit" -version = "5.4.0" +version = "5.4.1" authors = ["Igor Katson "] edition = "2021" description = "The main library used by rqbit torrent client. The binary is just a small wrapper on top of it." @@ -24,7 +24,7 @@ rust-tls = ["reqwest/rustls-tls"] [dependencies] bencode = {path = "../bencode", default-features=false, package="librqbit-bencode", version="2.2.1"} buffers = {path = "../buffers", package="librqbit-buffers", version = "2.2.1"} -librqbit-core = {path = "../librqbit_core", version = "3.4.0"} +librqbit-core = {path = "../librqbit_core", version = "3.5.0"} clone_to_owned = {path = "../clone_to_owned", package="librqbit-clone-to-owned", version = "2.2.1"} peer_binary_protocol = {path = "../peer_binary_protocol", package="librqbit-peer-protocol", version = "3.4.0"} sha1w = {path = "../sha1w", default-features=false, package="librqbit-sha1-wrapper", version="2.2.1"} diff --git a/crates/librqbit/webui/dist/assets/index.js b/crates/librqbit/webui/dist/assets/index.js index 6c6e981..22e4648 100644 --- a/crates/librqbit/webui/dist/assets/index.js +++ b/crates/librqbit/webui/dist/assets/index.js @@ -53,4 +53,4 @@ Error generating stack: `+o.message+` * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - */var Wl=x,rp=np;function lp(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var op=typeof Object.is=="function"?Object.is:lp,ip=rp.useSyncExternalStore,up=Wl.useRef,sp=Wl.useEffect,ap=Wl.useMemo,cp=Wl.useDebugValue;kd.useSyncExternalStoreWithSelector=function(e,t,n,r,l){var o=up(null);if(o.current===null){var i={hasValue:!1,value:null};o.current=i}else i=o.current;o=ap(function(){function s(g){if(!a){if(a=!0,v=g,g=r(g),l!==void 0&&i.hasValue){var y=i.value;if(l(y,g))return h=y}return h=g}if(y=h,op(v,g))return y;var S=r(g);return l!==void 0&&l(y,S)?y:(v=g,h=S)}var a=!1,v,h,f=n===void 0?null:n;return[function(){return s(t())},f===null?void 0:function(){return s(f())}]},[t,n,r,l]);var u=ip(e,o[0],o[1]);return sp(function(){i.hasValue=!0,i.value=u},[u]),cp(u),u};wd.exports=kd;var dp=wd.exports;const fp=El(dp),{useDebugValue:pp}=Je,{useSyncExternalStoreWithSelector:hp}=fp;function mp(e,t=e.getState,n){const r=hp(e.subscribe,e.getState,e.getServerState||e.getState,t,n);return pp(r),r}const Qs=e=>{const t=typeof e=="function"?Z1(e):e,n=(r,l)=>mp(t,r,l);return Object.assign(n,t),n},Cd=e=>e?Qs(e):Qs,vp=(e,t)=>e.id==t.id&&e.info_hash==t.info_hash,gp=(e,t)=>e===null&&t===null?!0:e===null||t===null?!1:e.length===t.length&&e.every((n,r)=>vp(n,t[r])),At=Cd(e=>({torrents:null,torrentsLoading:!1,torrentsInitiallyLoading:!1,setTorrentsLoading:t=>e(n=>n.torrents==null?{torrentsInitiallyLoading:t,torrentsLoading:t}:{torrentsInitiallyLoading:!1,torrentsLoading:t}),setTorrents:t=>e(n=>gp(n.torrents,t)?{}:{torrents:t}),refreshTorrents:()=>{},setRefreshTorrents:t=>e({refreshTorrents:t})})),yp=({id:e,show:t,onHide:n})=>{if(!t)return null;const[r,l]=x.useState(!1),[o,i]=x.useState(null),[u,s]=x.useState(!1),a=x.useContext(Nt),v=At(g=>g.refreshTorrents),h=()=>{l(!1),i(null),s(!1),n()},f=()=>{s(!0),(r?a.delete:a.forget)(e).then(()=>{v(),h()}).catch(y=>{i({text:`Error deleting torrent id=${e}`,details:y}),s(!1)})};return c.jsxs(Bl,{isOpen:t,onClose:n,title:"Delete torrent",children:[c.jsxs(Vl,{children:[c.jsx("p",{className:"text-gray-700 dark:text-slate-300",children:"Are you sure you want to delete the torrent?"}),c.jsxs("div",{className:"mt-4 flex items-center",children:[c.jsx("input",{type:"checkbox",id:"deleteFiles",className:"form-checkbox h-4 w-4 text-blue-500",onChange:()=>l(!r),checked:r,placeholder:"Also delete files"}),c.jsx("label",{htmlFor:"deleteFiles",className:"ml-2 text-gray-700 dark:text-slate-300",children:"Also delete files"})]}),o&&c.jsx(Qt,{error:o})]}),c.jsxs(Hl,{children:[u&&c.jsx(Sl,{}),c.jsx(Et,{variant:"cancel",onClick:h,children:"Cancel"}),c.jsx(Et,{variant:"danger",onClick:f,disabled:u,children:"Delete Torrent"})]})]})};function xp(e){return ee({tag:"svg",attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M144 479H48c-26.5 0-48-21.5-48-48V79c0-26.5 21.5-48 48-48h96c26.5 0 48 21.5 48 48v352c0 26.5-21.5 48-48 48zm304-48V79c0-26.5-21.5-48-48-48h-96c-26.5 0-48 21.5-48 48v352c0 26.5 21.5 48 48 48h96c26.5 0 48-21.5 48-48z"}}]})(e)}function wp(e){return ee({tag:"svg",attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M424.4 214.7L72.4 6.6C43.8-10.3 0 6.1 0 47.9V464c0 37.5 40.7 60.1 72.4 41.3l352-208c31.4-18.5 31.5-64.1 0-82.6z"}}]})(e)}function kp(e){return ee({tag:"svg",attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M432 32H312l-9.4-18.7A24 24 0 0 0 281.1 0H166.8a23.72 23.72 0 0 0-21.4 13.3L136 32H16A16 16 0 0 0 0 48v32a16 16 0 0 0 16 16h416a16 16 0 0 0 16-16V48a16 16 0 0 0-16-16zM53.2 467a48 48 0 0 0 47.9 45h245.8a48 48 0 0 0 47.9-45L416 128H32z"}}]})(e)}const gn=Cd(e=>({closeableError:null,setCloseableError:t=>e(()=>({closeableError:t})),otherError:null,setOtherError:t=>e(()=>({otherError:t}))})),Sp=({id:e,statsResponse:t})=>{let n=t.state,[r,l]=x.useState(!1),[o,i]=x.useState(!1),u=x.useContext(dd);const s=n=="live",a=n=="paused"||n=="error",v=gn(L=>L.setCloseableError),h=x.useContext(Nt),f=()=>{l(!0),h.start(e).then(()=>{u.refresh()},L=>{v({text:`Error starting torrent id=${e}`,details:L})}).finally(()=>l(!1))},g=()=>{l(!0),h.pause(e).then(()=>{u.refresh()},L=>{v({text:`Error pausing torrent id=${e}`,details:L})}).finally(()=>l(!1))},y=()=>{l(!0),i(!0)},S=()=>{l(!1),i(!1)};return c.jsxs("div",{className:"flex w-full justify-center gap-2 dark:text-slate-300",children:[a&&c.jsx(vn,{onClick:f,disabled:r,children:c.jsx(wp,{className:"hover:text-green-600"})}),s&&c.jsx(vn,{onClick:g,disabled:r,children:c.jsx(xp,{className:"hover:text-amber-500"})}),c.jsx(vn,{onClick:y,disabled:r,children:c.jsx(kp,{className:"hover:text-red-500"})}),c.jsx(yp,{id:e,show:o,onHide:S})]})},Zs={warn:"bg-amber-500 text-white",info:"bg-blue-500 text-white",success:"bg-green-700 text-white",error:"bg-red-500 text-white"},Ep=({now:e,variant:t,label:n})=>{const r=n??`${e.toFixed(2)}%`,l=Zs[t??"info"]??Zs.info;return c.jsx("div",{className:"w-full bg-gray-200 rounded-full dark:bg-gray-500",children:c.jsx("div",{className:`text-xs font-medium transition-all text-center p-0.5 leading-none rounded-full ${l}`,style:{width:`${e}%`},children:r})})};function pr(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 Cp=({statsResponse:e})=>{var t,n;switch(e.state){case r1:return"Paused";case wu:return"Checking files";case o1: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:["(",pr(e.live.snapshot.uploaded_bytes),")"]})]})]})};function _p(e){return e.files.filter(n=>n.included).reduce((n,r)=>n.length>r.length?n:r).name}function jp(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 Np(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":jp(t)}function Tp(e){return ee({tag:"svg",attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"}},{tag:"path",attr:{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z"}}]})(e)}function Lp(e){return ee({tag:"svg",attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"}},{tag:"path",attr:{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z"}}]})(e)}function Pp(e){return ee({tag:"svg",attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"}},{tag:"path",attr:{d:"M5 20h14v-2H5v2zM19 9h-4V3H9v6H5l7 7 7-7z"}}]})(e)}function zp(e){return ee({tag:"svg",attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0V0z"}},{tag:"path",attr:{d:"M9 16h6v-6h4l-7-7-7 7h4v6zm3-10.17L14.17 8H13v6h-2V8H9.83L12 5.83zM5 18h14v2H5z"}}]})(e)}function Mp(e){return ee({tag:"svg",attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"}},{tag:"path",attr:{d:"M22 12c0 5.52-4.48 10-10 10S2 17.52 2 12c0-1.19.22-2.32.6-3.38l1.88.68C4.17 10.14 4 11.05 4 12c0 4.41 3.59 8 8 8s8-3.59 8-8-3.59-8-8-8c-.95 0-1.85.17-2.69.48l-.68-1.89C9.69 2.22 10.82 2 12 2c5.52 0 10 4.48 10 10zM5.5 4C4.67 4 4 4.67 4 5.5S4.67 7 5.5 7 7 6.33 7 5.5 6.33 4 5.5 4zM11 16V8H9v8h2zm4 0V8h-2v8h2z"}}]})(e)}const Op=({className:e,finished:t,live:n,error:r})=>{const l=t&&n;return r?c.jsx(Lp,{className:e,color:"red"}):l?c.jsx(zp,{className:e,color:"green"}):t?c.jsx(Tp,{className:e,color:"green"}):n?c.jsx(Pp,{className:`text-blue-500 ${e}`}):c.jsx(Mp,{className:e})},Ip=({id:e,detailsResponse:t,statsResponse:n})=>{const r=(n==null?void 0:n.state)??"",l=(n==null?void 0:n.error)??null,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=()=>{var f;let h=(f=n==null?void 0:n.live)==null?void 0:f.snapshot.peer_stats;return h?`${h.live} / ${h.seen}`:""},v=h=>c.jsx(Op,{className:h,error:!!l,live:!!(n!=null&&n.live),finished:u});return c.jsxs("section",{className:"flex flex-col sm:flex-row items-center gap-2 border p-2 border-gray-200 rounded-xl shadow-xs hover:drop-shadow-sm dark:bg-slate-800 dark:border-slate-900",children:[c.jsx("div",{className:"hidden md:block",children:v("w-10 h-10")}),c.jsxs("div",{className:"w-full flex flex-col gap-2",children:[t&&c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("div",{className:"md:hidden",children:v("w-5 h-5")}),c.jsx("div",{className:"text-left text-lg text-gray-900 text-ellipsis break-all dark:text-slate-200",children:_p(t)})]}),l?c.jsxs("p",{className:"text-red-500 text-sm",children:[c.jsx("strong",{children:"Error:"})," ",l]}):c.jsxs(c.Fragment,{children:[c.jsx("div",{children:c.jsx(Ep,{now:s,label:l,variant:r==wu?"warn":u?"success":"info"})}),c.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-2 sm:flex-wrap items-center text-sm text-nowrap font-medium text-gray-500",children:[c.jsxs("div",{className:"flex gap-2 items-center",children:[c.jsx(c1,{})," ",a().toString()]}),c.jsxs("div",{className:"flex gap-2 items-center",children:[c.jsx(a1,{}),c.jsxs("div",{children:[pr(i),"/",pr(o)]})]}),n&&c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"flex gap-2 items-center",children:[c.jsx(s1,{}),Np(n)]}),c.jsx("div",{className:"flex gap-2 items-center",children:c.jsx(Cp,{statsResponse:n})})]})]})]})]}),n&&c.jsx("div",{className:"",children:c.jsx(Sp,{id:e,statsResponse:n})})]})},Fp=({id:e,torrent:t})=>{const[n,r]=x.useState(null),[l,o]=x.useState(null),[i,u]=x.useState(0),s=x.useContext(Nt),a=()=>{u(i+1)};return x.useEffect(()=>{if(n===null)return fd(async()=>{await s.getTorrentDetails(t.id).then(r)},1e3)},[n]),x.useEffect(()=>ku(async()=>s.getTorrentStats(t.id).then(g=>(o(g),g)).then(g=>g.state==wu||g.state==l1?1e3:1e4,()=>1e4),0),[i]),c.jsx(dd.Provider,{value:{refresh:a},children:c.jsx(Ip,{id:e,detailsResponse:n,statsResponse:l})})},Dp=e=>c.jsx("div",{className:"flex flex-col gap-2 mx-2 pb-3 sm:px-7",children:e.torrents===null?e.loading?c.jsx(Sl,{className:"justify-center m-5",label:"Loading torrent list"}):null:e.torrents.length===0?c.jsx("p",{className:"text-center",children:"No existing torrents found."}):e.torrents.map(t=>c.jsx(Fp,{id:t.id,torrent:t},t.id))}),Rp=e=>{let t=gn(i=>i.closeableError),n=gn(i=>i.setCloseableError),r=gn(i=>i.otherError),l=At(i=>i.torrents),o=At(i=>i.torrentsInitiallyLoading);return c.jsxs("div",{className:"container mx-auto",children:[c.jsx(Qt,{error:t,remove:()=>n(null)}),c.jsx(Qt,{error:r}),c.jsx(Dp,{torrents:l,loading:o})]})};var $p="Expected a function",Ks=0/0,Ap="[object Symbol]",Up=/^\s+|\s+$/g,Bp=/^[-+]0x[0-9a-f]+$/i,Vp=/^0b[01]+$/i,Hp=/^0o[0-7]+$/i,Wp=parseInt,Qp=typeof kr=="object"&&kr&&kr.Object===Object&&kr,Zp=typeof self=="object"&&self&&self.Object===Object&&self,Kp=Qp||Zp||Function("return this")(),Gp=Object.prototype,Yp=Gp.toString,Xp=Math.max,Jp=Math.min,Lo=function(){return Kp.Date.now()};function qp(e,t,n){var r,l,o,i,u,s,a=0,v=!1,h=!1,f=!0;if(typeof e!="function")throw new TypeError($p);t=Gs(t)||0,_i(n)&&(v=!!n.leading,h="maxWait"in n,o=h?Xp(Gs(n.maxWait)||0,t):o,f="trailing"in n?!!n.trailing:f);function g(E){var j=r,T=l;return r=l=void 0,a=E,i=e.apply(T,j),i}function y(E){return a=E,u=setTimeout(p,t),v?g(E):i}function S(E){var j=E-s,T=E-a,D=t-j;return h?Jp(D,o-T):D}function L(E){var j=E-s,T=E-a;return s===void 0||j>=t||j<0||h&&T>=o}function p(){var E=Lo();if(L(E))return d(E);u=setTimeout(p,S(E))}function d(E){return u=void 0,f&&r?g(E):(r=l=void 0,i)}function m(){u!==void 0&&clearTimeout(u),a=0,r=s=l=u=void 0}function w(){return u===void 0?i:d(Lo())}function _(){var E=Lo(),j=L(E);if(r=arguments,l=this,s=E,j){if(u===void 0)return y(s);if(h)return u=setTimeout(p,t),g(s)}return u===void 0&&(u=setTimeout(p,t)),i}return _.cancel=m,_.flush=w,_}function _i(e){var t=typeof e;return!!e&&(t=="object"||t=="function")}function bp(e){return!!e&&typeof e=="object"}function eh(e){return typeof e=="symbol"||bp(e)&&Yp.call(e)==Ap}function Gs(e){if(typeof e=="number")return e;if(eh(e))return Ks;if(_i(e)){var t=typeof e.valueOf=="function"?e.valueOf():e;e=_i(t)?t+"":t}if(typeof e!="string")return e===0?e:+e;e=e.replace(Up,"");var n=Vp.test(e);return n||Hp.test(e)?Wp(e.slice(2),n?2:8):Bp.test(e)?Ks:+e}var th=qp;const nh=El(th),rh=({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]})),"}"]})},lh=({span:e})=>c.jsxs(c.Fragment,{children:[c.jsx("span",{className:"font-bold",children:e.name}),c.jsx(rh,{span:e}),c.jsx("span",{className:"font-bold",children:":"})]}),oh=({fields:e})=>c.jsxs("span",{className:`m-1 ${e.message.match(/error|fail/g)?"text-red-500":"text-slate-500 dark:text-slate-200"}`,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:"italic font-bold",children:t}),"=",n]},t))]}),ih=Je.memo(({line:e})=>{var r;const t=e,n=l=>{switch(l){case"DEBUG":return"text-blue-500";case"INFO":return"text-green-500";case"WARN":return"text-amber-500";case"ERROR":return"text-red-500";default:return"text-slate-500"}};return c.jsxs("p",{className:"font-mono m-0 text-break text-[10px]",children:[c.jsx("span",{className:"m-1 text-slate-500 dark:text-slate-400",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(lh,{span:l},o))}),c.jsx("span",{className:"m-1 text-slate-500 dark:text-slate-400",children:t.target}),c.jsx(oh,{fields:t.fields})]})}),_d=({children:e})=>c.jsx("form",{children:e}),Cu=({autoFocus:e,value:t,name:n,disabled:r,onChange:l,onKeyDown:o,label:i,help:u,inputType:s,placeholder:a})=>c.jsxs("div",{className:"flex flex-col gap-2 text-sm mb-2",children:[c.jsx("label",{htmlFor:n,className:"dark:text-white",children:i}),c.jsx("input",{autoFocus:e,type:s,className:"block border rounded bg-transparent py-1.5 pl-2 text-gray-800 focus:ring-0 sm:text-sm sm:leading-6 dark:text-slate-300",id:n,name:n,disabled:r,placeholder:a,value:t,onKeyDown:o,onChange:l}),u&&c.jsx("div",{className:"text-xs text-slate-500 dark:text-slate-300",children:u})]}),uh=(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},sh=(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 f=await a.text();throw n({text:"error fetching logs",details:{statusText:a.statusText,text:f}}),null}if(!a.body){n({text:"error fetching logs: ReadableStream not supported."});return}n(null);const v=a.body.getReader();let h=new Uint8Array;for(;;){const{done:f,value:g}=await v.read();if(f)throw n({text:"log stream terminated"}),null;h=uh(h,g);for(let y;(y=h.indexOf(10))!==-1;){let S=h.slice(0,y),L=new TextDecoder().decode(S);t(L),h=h.slice(y+1)}}};let s=fd(()=>u().then(()=>{},a=>{if(!o&&a!==null)throw n({text:"error streaming logs",details:{text:a.toString()}}),a}),1e3);return()=>{i(),s()}},ah=({url:e,maxLines:t})=>{const[n,r]=x.useState([]),[l,o]=x.useState(null),[i,u]=x.useState(""),s=x.useRef(null),a=t??1e3,v=x.useCallback(y=>{r(S=>[{id:S.length==0?0:S[0].id+1,content:y,parsed:JSON.parse(y),show:s.current?!!y.match(s.current):!0},...S.slice(0,a-1)])},[s.current,t]),h=x.useRef(v);h.current=v;const f=nh(y=>{let S=null;try{S=new RegExp(y)}catch{return}s.current=S,r(L=>{let p=[...L];for(let d of p)d.show=!!d.content.match(S);return p})},200),g=y=>{u(y),f(y)};return x.useEffect(()=>f.cancel,[]),x.useEffect(()=>sh(e,y=>h.current(y),o),[e]),c.jsxs("div",{children:[c.jsx(Qt,{error:l}),c.jsxs("div",{className:"mb-3",children:["Showing last ",a," logs since this window was opened"]}),c.jsx(_d,{children:c.jsx(Cu,{value:i,name:"filter",placeholder:"Enter filter (regex)",onChange:y=>g(y.target.value)})}),n.map(y=>c.jsx("div",{hidden:!y.show,children:c.jsx(ih,{line:y.parsed})},y.id))]})},ch=({show:e,onClose:t})=>{let r=x.useContext(Nt).getStreamLogsUrl();return c.jsxs(Bl,{isOpen:e,onClose:t,title:"rqbit server logs",className:"max-w-7xl",children:[c.jsx(Vl,{children:r?c.jsx(ah,{url:r}):c.jsx(Qt,{error:{text:"HTTP API not available to stream logs"}})}),c.jsx(Hl,{children:c.jsx(Et,{variant:"primary",onClick:t,children:"Close"})})]})},dh=({children:e,label:t,help:n,className:r})=>c.jsxs("fieldset",{className:`mb-4 ${r}`,children:[t&&c.jsx("label",{className:"text-md font-md mb-3 block pb-1 border-b",children:t}),e]}),Ys=({checked:e,name:t,disabled:n,onChange:r,label:l,help:o,inputType:i})=>c.jsxs("div",{className:"flex gap-3 items-start",children:[c.jsx("div",{className:"flex",children:c.jsx("input",{type:i||"checkbox",className:"block mt-1",id:t,name:t,disabled:n,checked:e,onChange:r})}),c.jsxs("div",{className:"text-sm flex flex-col gap-1",children:[c.jsx("label",{htmlFor:t,children:l}),o&&c.jsx("div",{className:"text-xs text-slate-500 dark:text-slate-300 mb-3",children:o})]})]});function fh(e){return ee({tag:"svg",attr:{viewBox:"0 0 24 24"},child:[{tag:"g",attr:{id:"Square_Minus"},child:[{tag:"g",attr:{},child:[{tag:"path",attr:{d:"M18.438,20.938H5.564a2.5,2.5,0,0,1-2.5-2.5V5.564a2.5,2.5,0,0,1,2.5-2.5H18.438a2.5,2.5,0,0,1,2.5,2.5V18.438A2.5,2.5,0,0,1,18.438,20.938ZM5.564,4.064a1.5,1.5,0,0,0-1.5,1.5V18.438a1.5,1.5,0,0,0,1.5,1.5H18.438a1.5,1.5,0,0,0,1.5-1.5V5.564a1.5,1.5,0,0,0-1.5-1.5Z"}},{tag:"path",attr:{d:"M9,12.5a.5.5,0,0,1,0-1h6a.5.5,0,0,1,0,1Z"}}]}]}]})(e)}function ph(e){return ee({tag:"svg",attr:{viewBox:"0 0 24 24"},child:[{tag:"g",attr:{id:"Square_Plus"},child:[{tag:"g",attr:{},child:[{tag:"path",attr:{d:"M18.438,20.938H5.563a2.5,2.5,0,0,1-2.5-2.5V5.564a2.5,2.5,0,0,1,2.5-2.5H18.438a2.5,2.5,0,0,1,2.5,2.5V18.438A2.5,2.5,0,0,1,18.438,20.938ZM5.563,4.064a1.5,1.5,0,0,0-1.5,1.5V18.438a1.5,1.5,0,0,0,1.5,1.5H18.438a1.5,1.5,0,0,0,1.5-1.5V5.564a1.5,1.5,0,0,0-1.5-1.5Z"}},{tag:"path",attr:{d:"M15,12.5H12.5V15a.5.5,0,0,1-1,0V12.5H9a.5.5,0,0,1,0-1h2.5V9a.5.5,0,0,1,1,0v2.5H15A.5.5,0,0,1,15,12.5Z"}}]}]}]})(e)}const hh=(e,t)=>e.indexOf(t)===-1?[e,void 0]:[e.slice(0,e.indexOf(t)),e.slice(e.indexOf(t)+1)],mh=e=>{const t="/",n=(r,l,o)=>{let i=[],u=[],s={};const a=h=>(s[h]=s[h]||[],s[h]);o.forEach(h=>{let[f,g]=hh(h.name,t);if(g===void 0){i.push(h);return}a(f).push({id:h.id,name:g,length:h.length})});let v=0;for(const[h,f]of Object.entries(s))u.push(n(h,l+"."+v,f)),v+=1;return{name:r,id:l,dirs:u,files:i}};return n("","filetree-root",e.details.files.map((r,l)=>({id:l,name:r.name,length:r.length})))},jd=({tree:e,selectedFiles:t,setSelectedFiles:n,initialExpanded:r,listTorrentResponse:l})=>{let[o,i]=x.useState(r),u=x.useMemo(()=>{let f=g=>{let y=g.dirs.flatMap(f);return y.push(...g.files.map(S=>S.id)),y};return f(e)},[e]);const s=f=>{if(f.target.checked){let g=new Set(t);u.forEach(y=>g.add(y)),n(g)}else{let g=new Set(t);u.forEach(y=>g.delete(y)),n(g)}},a=f=>{if(t.has(f)){let g=new Set(t);g.delete(f),n(g)}else{let g=new Set(t);g.add(f),n(g)}},v=()=>u.filter(f=>t.has(f)).length,h=()=>u.filter(f=>t.has(f)).map(f=>l.details.files[f].length).reduce((f,g)=>f+g,0);return c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"flex items-center",children:[c.jsx(vn,{onClick:()=>i(!o),children:o?c.jsx(fh,{}):c.jsx(ph,{})}),c.jsx(Ys,{checked:u.every(f=>t.has(f)),label:`${e.name?e.name+", ":""} ${v()} files, ${pr(h())}`,name:e.id,onChange:s})]}),c.jsxs("div",{className:"pl-5",hidden:!o,children:[e.dirs.map(f=>c.jsx(jd,{listTorrentResponse:l,tree:f,selectedFiles:t,setSelectedFiles:n,initialExpanded:!1},f.name)),c.jsx("div",{className:"pl-1",children:e.files.map(f=>c.jsx(Ys,{checked:t.has(f.id),label:`${f.name} (${pr(f.length)})`,name:`file-${f.id}`,onChange:()=>a(f.id)},f.id))})]})]})},vh=({listTorrentResponse:e,selectedFiles:t,setSelectedFiles:n})=>{let r=x.useMemo(()=>mh(e),[e]);return c.jsx(c.Fragment,{children:c.jsx(jd,{listTorrentResponse:e,tree:r,selectedFiles:t,setSelectedFiles:n,initialExpanded:!0})})},gh=e=>{let{onHide:t,listTorrentResponse:n,listTorrentError:r,listTorrentLoading:l,data:o}=e;const[i,u]=x.useState(new Set),[s,a]=x.useState(!1),[v,h]=x.useState(null),[f,g]=x.useState(!1),[y,S]=x.useState(""),L=At(_=>_.refreshTorrents),p=x.useContext(Nt);x.useEffect(()=>{u(new Set(n==null?void 0:n.details.files.map((_,E)=>E))),S((n==null?void 0:n.output_folder)||"")},[n]);const d=()=>{t(),u(new Set),h(null),a(!1)},m=async()=>{if(!n)return;a(!0);let _=n.seen_peers?n.seen_peers.slice(0,32):null,E={overwrite:!0,only_files:Array.from(i),initial_peers:_,output_folder:y};f&&(E.peer_opts={connect_timeout:20,read_write_timeout:60}),p.uploadTorrent(o,E).then(()=>{t(),L()},j=>{h({text:"Error starting torrent",details:j})}).finally(()=>a(!1))},w=()=>{if(l)return c.jsx(Sl,{label:"Loading torrent contents"});if(r)return c.jsx(Qt,{error:r});if(n)return c.jsxs(_d,{children:[c.jsx(Cu,{label:"Output folder",name:"output_folder",inputType:"text",value:y,onChange:_=>S(_.target.value)}),c.jsx(dh,{children:c.jsx(vh,{selectedFiles:i,setSelectedFiles:u,listTorrentResponse:n})})]})};return c.jsxs(Bl,{isOpen:!0,onClose:d,title:"Add Torrent",children:[c.jsxs(Vl,{children:[w(),c.jsx(Qt,{error:v})]}),c.jsxs(Hl,{children:[s&&c.jsx(Sl,{}),c.jsx(Et,{onClick:d,variant:"cancel",children:"Cancel"}),c.jsx(Et,{onClick:m,variant:"primary",disabled:l||s||i.size==0,children:"OK"})]})]})},Nd=({onClick:e,data:t,resetData:n,children:r,className:l})=>{const[o,i]=x.useState(!1),[u,s]=x.useState(null),[a,v]=x.useState(null),h=x.useContext(Nt);x.useEffect(()=>{if(t===null)return;let g=setTimeout(async()=>{i(!0);try{const y=await h.uploadTorrent(t,{list_only:!0});s(y)}catch(y){v({text:"Error listing torrent files",details:y})}finally{i(!1)}},0);return()=>clearTimeout(g)},[t]);const f=()=>{n(),v(null),s(null),i(!1)};return c.jsxs(c.Fragment,{children:[c.jsx(Et,{onClick:e,className:l,children:r}),t&&c.jsx(gh,{onHide:f,listTorrentError:a,listTorrentResponse:u,data:t,listTorrentLoading:o})]})};function yh(e){return ee({tag:"svg",attr:{viewBox:"0 0 24 24",fill:"none"},child:[{tag:"path",attr:{d:"M10 18V16H8V14H10V12H12V14H14V16H12V18H10Z",fill:"currentColor"}},{tag:"path",attr:{fillRule:"evenodd",clipRule:"evenodd",d:"M6 2C4.34315 2 3 3.34315 3 5V19C3 20.6569 4.34315 22 6 22H18C19.6569 22 21 20.6569 21 19V9C21 5.13401 17.866 2 14 2H6ZM6 4H13V9H19V19C19 19.5523 18.5523 20 18 20H6C5.44772 20 5 19.5523 5 19V5C5 4.44772 5.44772 4 6 4ZM15 4.10002C16.6113 4.4271 17.9413 5.52906 18.584 7H15V4.10002Z",fill:"currentColor"}}]})(e)}function xh(e){return ee({tag:"svg",attr:{viewBox:"0 0 24 24",fill:"none"},child:[{tag:"path",attr:{d:"M14.8284 12L16.2426 13.4142L19.071 10.5858C20.6331 9.02365 20.6331 6.49099 19.071 4.9289C17.509 3.3668 14.9763 3.3668 13.4142 4.9289L10.5858 7.75732L12 9.17154L14.8284 6.34311C15.6095 5.56206 16.8758 5.56206 17.6568 6.34311C18.4379 7.12416 18.4379 8.39049 17.6568 9.17154L14.8284 12Z",fill:"currentColor"}},{tag:"path",attr:{d:"M12 14.8285L13.4142 16.2427L10.5858 19.0711C9.02372 20.6332 6.49106 20.6332 4.92896 19.0711C3.36686 17.509 3.36686 14.9764 4.92896 13.4143L7.75739 10.5858L9.1716 12L6.34317 14.8285C5.56212 15.6095 5.56212 16.8758 6.34317 17.6569C7.12422 18.4379 8.39055 18.4379 9.1716 17.6569L12 14.8285Z",fill:"currentColor"}},{tag:"path",attr:{d:"M14.8285 10.5857C15.219 10.1952 15.219 9.56199 14.8285 9.17147C14.4379 8.78094 13.8048 8.78094 13.4142 9.17147L9.1716 13.4141C8.78107 13.8046 8.78107 14.4378 9.1716 14.8283C9.56212 15.2188 10.1953 15.2188 10.5858 14.8283L14.8285 10.5857Z",fill:"currentColor"}}]})(e)}const wh=({className:e})=>{const t=x.useRef(),[n,r]=x.useState(null),l=async()=>{var s;if(!((s=t==null?void 0:t.current)!=null&&s.files))return;const u=t.current.files[0];r(u)},o=()=>{t!=null&&t.current&&(t.current.value="",r(null))},i=()=>{t!=null&&t.current&&t.current.click()};return c.jsxs(c.Fragment,{children:[c.jsx("input",{type:"file",ref:t,accept:".torrent",onChange:l,hidden:!0}),c.jsxs(Nd,{onClick:i,data:n,resetData:o,className:`group ${e}`,children:[c.jsx(yh,{className:"text-blue-500 group-hover:text-white dark:text-white"}),c.jsx("div",{children:"Upload .torrent File"})]})]})},kh=({className:e})=>{const[t,n]=x.useState(null),[r,l]=x.useState(""),[o,i]=x.useState(!1),u=()=>{n(r),l(""),i(!1)},s=()=>{i(!1),n(null)};return c.jsxs(c.Fragment,{children:[c.jsxs(Nd,{onClick:()=>{i(!0)},data:t,className:`group ${e}`,resetData:()=>n(null),children:[c.jsx(xh,{className:"text-blue-500 group-hover:text-white dark:text-white"}),c.jsx("div",{children:"Add Torrent from Magnet / URL"})]}),c.jsxs(Bl,{isOpen:o,onClose:s,title:"Add torrent",children:[c.jsx(Vl,{children:c.jsx(Cu,{autoFocus:!0,value:r,name:"magnet",onChange:a=>l(a.target.value),onKeyDown:a=>{a.key==="Enter"&&r&&u()},placeholder:"magnet:?xt=urn:btih:...",help:"Enter magnet or HTTP(S) URL to the .torrent"})}),c.jsxs(Hl,{children:[c.jsx(Et,{variant:"cancel",onClick:s,children:"Cancel"}),c.jsx(Et,{disabled:!r,variant:"primary",onClick:u,children:"Add"})]})]})]})},Sh=e=>x.createElement("svg",{width:"64mm",height:"64mm",viewBox:"0 0 64 64",id:"svg1",xmlSpace:"preserve","inkscape:version":"1.3.1 (91b66b0, 2023-11-16)","sodipodi:docname":"logo.svg","xmlns:inkscape":"http://www.inkscape.org/namespaces/inkscape","xmlns:sodipodi":"http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd",xmlns:"http://www.w3.org/2000/svg","xmlns:svg":"http://www.w3.org/2000/svg",...e},x.createElement("sodipodi:namedview",{id:"namedview1",pagecolor:"#ffffff",bordercolor:"#000000",borderopacity:.25,"inkscape:showpageshadow":2,"inkscape:pageopacity":0,"inkscape:pagecheckerboard":0,"inkscape:deskcolor":"#d1d1d1","inkscape:document-units":"mm","inkscape:zoom":1.4936372,"inkscape:cx":134.90559,"inkscape:cy":139.92689,"inkscape:window-width":1440,"inkscape:window-height":847,"inkscape:window-x":0,"inkscape:window-y":25,"inkscape:window-maximized":0,"inkscape:current-layer":"layer1"}),x.createElement("defs",{id:"defs1"},x.createElement("inkscape:perspective",{"sodipodi:type":"inkscape:persp3d","inkscape:vp_x":"3.1042448 : 18.147022 : 1","inkscape:vp_y":"0 : 999.99994 : 0","inkscape:vp_z":"303.94612 : 54.05812 : 1","inkscape:persp3d-origin":"105 : -134 : 1",id:"perspective4"})),x.createElement("g",{"inkscape:label":"Layer 1","inkscape:groupmode":"layer",id:"layer1",transform:"translate(-56.674541,-85.911432)"},x.createElement("path",{style:{fill:"#0d6efd",fillOpacity:1,strokeWidth:.610041},d:"m 81.603814,145.5382 -7.433116,-4.36986 -6.018097,-3.54529 -6.018099,-3.54529 -0.09405,-0.35761 -0.09406,-0.3576 v -15.31979 -15.31979 l 0.09451,-0.35939 0.09451,-0.35938 6.017643,-3.544433 6.017641,-3.544428 7.432805,-4.369167 7.432803,-4.369166 0.240089,0.09331 0.240083,0.09331 13.292394,7.826122 13.29241,7.826122 0.093,0.35355 0.093,0.35355 v 15.31979 15.31979 l -0.0928,0.35267 -0.0928,0.35266 -13.29682,7.82802 -13.296819,7.82803 -0.235583,0.0921 -0.235588,0.0921 z m 19.758596,-5.88315 12.13185,-7.15306 v -14.45996 -14.45994 l -5.11526,-3.01603 -5.11526,-3.016035 -7.017048,-4.136312 -7.017053,-4.13631 h -0.112738 -0.11273 l -7.097035,4.182089 -7.09703,4.18209 -5.035336,2.971548 -5.035335,2.97155 v 14.45761 14.45762 l 5.275113,3.11051 5.275113,3.11051 6.793709,4.02813 6.793702,4.02812 0.176743,0.0155 0.176742,0.0155 z",id:"path15","sodipodi:nodetypes":"cccccccccccccccccccccccccccccccccccccccccccccccccccc"}),x.createElement("path",{style:{fill:"#000000"},id:"path1",d:""}),x.createElement("path",{d:"m 84.161856,133.76725 -4.567369,-2.5483 -0.700367,0.28585 -0.700376,0.28584 -0.495731,0.11427 -0.495731,0.11426 -3.168791,-1.75603 -3.168782,-1.75603 -0.515321,-0.57002 -0.515323,-0.57002 0.0161,-3.59449 0.0161,-3.59448 0.164041,-0.41611 0.164042,-0.41611 1.480342,-0.85565 1.480346,-0.85565 0.06276,-3.67919 0.06276,-3.67921 0.39653,-0.35884 0.396521,-0.35886 3.663275,-2.04111 3.663267,-2.04112 0.114523,-1.62785 0.114506,-1.62786 0.229029,-0.21764 0.229038,-0.21765 3.341459,-1.854383 3.341467,-1.854382 h 0.301682 0.301682 l 2.476951,1.380374 2.476959,1.380381 1.151673,0.57845 1.151674,0.57845 0.02969,0.27424 0.02969,0.27423 0.02753,1.46272 0.02753,1.46273 3.663258,2.04521 3.66327,2.04521 0.40205,0.36386 0.40206,0.36385 v 3.60098 3.60097 l 0.28629,0.23408 0.28628,0.23408 1.43146,0.72479 1.43145,0.72479 v 3.9806 3.98059 l -0.51533,0.56995 -0.51532,0.56994 -3.19072,1.75191 -3.19072,1.75191 -0.47379,-0.11007 -0.473797,-0.11007 -0.699654,-0.28558 -0.699656,-0.28558 -4.589745,2.5527 -4.589746,2.55269 -0.321886,-0.004 -0.321886,-0.004 z m 8.681258,-1.65766 3.426793,-1.91645 0.06536,-0.19784 0.06535,-0.19785 -1.315884,-0.68709 -1.315885,-0.6871 -0.401264,-0.40081 -0.401265,-0.4008 v -3.79409 -3.79409 l 0.221568,-0.41401 0.221567,-0.414 3.411065,-1.86126 3.411061,-1.86126 h 0.38456 0.38455 l 0.91435,0.46646 0.91435,0.46646 -0.0646,-2.66249 -0.0646,-2.66248 -2.829977,-1.58148 -2.829984,-1.58149 -0.204696,0.12651 -0.204688,0.12651 v 1.11999 1.11999 l -0.744359,0.54975 -0.744358,0.54977 -2.773906,1.52318 -2.773906,1.52319 h -0.526565 -0.526565 l -3.34145,-1.85945 -3.341467,-1.85945 -0.168271,-0.2591 -0.16827,-0.25909 -0.0035,-1.07439 -0.0035,-1.07439 -0.204688,-0.12651 -0.204697,-0.12651 -2.82999,1.58149 -2.829982,1.58148 -0.06458,2.66248 -0.06458,2.66249 0.914351,-0.46646 0.914343,-0.46646 h 0.378551 0.37855 l 3.638639,1.97495 3.63864,1.97495 v 4.0944 4.09441 l -0.401265,0.4008 -0.401264,0.40081 -1.315885,0.6871 -1.315884,0.68709 0.06535,0.19785 0.06536,0.19784 3.426792,1.91645 3.426785,1.91644 h 0.343552 0.343544 z m -16.416873,-5.4431 -0.06475,-2.55838 -2.046125,-1.10985 -2.046124,-1.10984 -0.195677,0.19567 -0.195685,0.19568 0.06596,2.2656 0.06596,2.2656 2.06129,1.18713 2.06129,1.18713 0.179282,0.0198 0.179273,0.0198 z m 4.515881,1.34369 2.061291,-1.19456 0.06527,-2.48747 0.06527,-2.48748 -0.408821,0.15589 -0.408848,0.15589 -1.889514,1.02885 -1.889514,1.02885 v 2.50736 2.50736 l 0.171777,-0.01 0.171767,-0.01 z m 18.666131,-1.29267 v -2.50736 l -1.889509,-1.02885 -1.889522,-1.02885 -0.40883,-0.15589 -0.408839,-0.15589 0.06527,2.48748 0.06527,2.48747 2.061291,1.19456 2.061288,1.19456 0.171777,0.01 0.171774,0.01 z m 4.466127,1.28059 2.06129,-1.18713 0.0661,-2.2656 0.066,-2.2656 -0.19568,-0.19568 -0.19568,-0.19567 -2.04613,1.10984 -2.04612,1.10985 -0.0647,2.55838 -0.0648,2.55838 0.17927,-0.0198 0.17927,-0.0198 z m -24.281888,-6.71835 1.960418,-1.07415 -0.07566,-0.22693 -0.07566,-0.22691 -2.049423,-1.09443 -2.049431,-1.09442 -2.116604,1.14523 -2.116613,1.14523 v 0.17781 0.17782 l 2.004029,1.06709 2.004037,1.06711 0.277236,0.005 0.277237,0.005 z m 23.056528,4.3e-4 2.03643,-1.07372 -0.0708,-0.21245 -0.0708,-0.21244 -2.09332,-1.13015 -2.09332,-1.13016 -2.077692,1.17124 -2.077685,1.17123 v 0.17384 0.17386 l 1.889522,1.0551 1.889505,1.0551 0.31588,0.0161 0.31587,0.0161 z m -14.742004,-11.90808 0.06492,-2.2946 -0.293917,-0.23052 -0.293926,-0.2305 -2.011741,-1.08631 -2.01175,-1.08629 0.06501,2.57478 0.06501,2.57476 1.946776,1.09773 1.946767,1.09773 0.229038,-0.0611 0.229029,-0.0611 z m 4.401245,1.31989 1.946767,-1.09857 0.06501,-2.57476 0.06501,-2.57478 -2.01175,1.08629 -2.011741,1.08631 -0.286291,0.22417 -0.286291,0.22418 v 2.22411 2.2241 l 0.152689,0.15269 0.152689,0.15269 0.133602,-0.0139 0.133602,-0.0139 z m -1.021015,-6.79999 1.952048,-1.05546 -0.224347,-0.26147 -0.224337,-0.26149 -1.958921,-1.03065 -1.958911,-1.03064 -1.958912,1.03064 -1.958912,1.03065 -0.224303,0.26142 -0.224277,0.26141 1.896915,1.04261 1.896906,1.04261 0.517494,0.0129 0.517501,0.0129 z",style:{fill:"#0d6efd",fillOpacity:1,strokeWidth:.865634},id:"path1-8"}))),Eh=({title:e})=>{const[t,n]=e.split("-");return c.jsxs("header",{className:"bg-slate-50 drop-shadow-lg flex flex-wrap justify-center lg:justify-between items-center dark:bg-slate-800 mb-3",children:[c.jsxs("div",{className:"flex flex-nowrap items-center justify-between m-2",children:[c.jsx(Sh,{className:"w-10 h-10 p-1",alt:"logo"}),c.jsxs("h1",{className:"flex items-center dark:text-white",children:[c.jsx("div",{className:"text-3xl",children:t}),c.jsx("div",{className:"bg-blue-100 text-blue-800 text-xl font-semibold me-2 px-2.5 py-0.5 rounded ms-2 dark:bg-blue-900 dark:text-white",children:n})]})]}),c.jsxs("div",{className:"flex flex-wrap gap-1 m-2",children:[c.jsx(kh,{className:"flex-grow justify-center dark:text-white"}),c.jsx(wh,{className:"flex-grow justify-center dark:text-white"})]})]})};let Xt=window.matchMedia("(prefers-color-scheme: dark)").matches;window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",e=>{Ql.setDark(e.matches)});const Ql={isDark:()=>Xt,setDark:e=>(Xt=e,document.body.classList.toggle("dark",Xt),Xt),toggle:()=>{Ql.setDark(!Xt)}};Ql.setDark(Xt);const Ch=e=>{let[t,n]=x.useState(!1);gn(a=>a.setCloseableError);const r=gn(a=>a.setOtherError),l=x.useContext(Nt),o=At(a=>a.setTorrents),i=At(a=>a.setTorrentsLoading),u=At(a=>a.setRefreshTorrents),s=async()=>{i(!0);let a=await l.listTorrents().finally(()=>i(!1));o(a.torrents)};return u(s),x.useEffect(()=>ku(async()=>s().then(()=>(r(null),5e3),a=>(r({text:"Error refreshing torrents",details:a}),console.error(a),5e3)),0),[]),c.jsxs("div",{className:"dark:bg-gray-900 dark:text-gray-200 min-h-screen",children:[c.jsx(Eh,{title:e.title}),c.jsxs("div",{className:"relative",children:[c.jsxs("div",{className:"absolute top-0 start-0 pl-2 z-10",children:[e.menuButtons&&e.menuButtons.map((a,v)=>c.jsx("span",{children:a},v)),c.jsx(vn,{onClick:()=>n(!0),children:c.jsx(d1,{})}),c.jsx(vn,{onClick:Ql.toggle,children:c.jsx(f1,{})})]}),c.jsx(Rp,{})]}),c.jsx(ch,{show:t,onClose:()=>n(!1)})]})},Td=window.origin==="null"||window.origin==="http://localhost:3031"?"http://localhost:3030":"",Ze=async(e,t,n)=>{console.log(e,t);const r=Td+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()},Xs={getStreamLogsUrl:()=>Td+"/stream_logs",listTorrents:()=>Ze("GET","/torrents"),getTorrentDetails:e=>Ze("GET",`/torrents/${e}`),getTorrentStats:e=>Ze("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"),Ze("POST",n,e)},pause:e=>Ze("POST",`/torrents/${e}/pause`),start:e=>Ze("POST",`/torrents/${e}/start`),forget:e=>Ze("POST",`/torrents/${e}/forget`),delete:e=>Ze("POST",`/torrents/${e}/delete`),getVersion:async()=>(await Ze("GET","/")).version},_h=()=>{let[e,t]=x.useState("rqbit web UI");return x.useEffect(()=>ku(()=>Xs.getVersion().then(r=>{const l=`rqbit web UI - v${r}`;return t(l),document.title=l,1e4},r=>1e3),0),[]),c.jsx(Nt.Provider,{value:Xs,children:c.jsx(Ch,{title:e})})};Po.createRoot(document.getElementById("app")).render(c.jsx(x.StrictMode,{children:c.jsx(_h,{})})); + */var Wl=x,rp=np;function lp(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var op=typeof Object.is=="function"?Object.is:lp,ip=rp.useSyncExternalStore,up=Wl.useRef,sp=Wl.useEffect,ap=Wl.useMemo,cp=Wl.useDebugValue;kd.useSyncExternalStoreWithSelector=function(e,t,n,r,l){var o=up(null);if(o.current===null){var i={hasValue:!1,value:null};o.current=i}else i=o.current;o=ap(function(){function s(g){if(!a){if(a=!0,v=g,g=r(g),l!==void 0&&i.hasValue){var y=i.value;if(l(y,g))return h=y}return h=g}if(y=h,op(v,g))return y;var S=r(g);return l!==void 0&&l(y,S)?y:(v=g,h=S)}var a=!1,v,h,f=n===void 0?null:n;return[function(){return s(t())},f===null?void 0:function(){return s(f())}]},[t,n,r,l]);var u=ip(e,o[0],o[1]);return sp(function(){i.hasValue=!0,i.value=u},[u]),cp(u),u};wd.exports=kd;var dp=wd.exports;const fp=El(dp),{useDebugValue:pp}=Je,{useSyncExternalStoreWithSelector:hp}=fp;function mp(e,t=e.getState,n){const r=hp(e.subscribe,e.getState,e.getServerState||e.getState,t,n);return pp(r),r}const Qs=e=>{const t=typeof e=="function"?Z1(e):e,n=(r,l)=>mp(t,r,l);return Object.assign(n,t),n},Cd=e=>e?Qs(e):Qs,vp=(e,t)=>e.id==t.id&&e.info_hash==t.info_hash,gp=(e,t)=>e===null&&t===null?!0:e===null||t===null?!1:e.length===t.length&&e.every((n,r)=>vp(n,t[r])),At=Cd(e=>({torrents:null,torrentsLoading:!1,torrentsInitiallyLoading:!1,setTorrentsLoading:t=>e(n=>n.torrents==null?{torrentsInitiallyLoading:t,torrentsLoading:t}:{torrentsInitiallyLoading:!1,torrentsLoading:t}),setTorrents:t=>e(n=>gp(n.torrents,t)?{}:{torrents:t}),refreshTorrents:()=>{},setRefreshTorrents:t=>e({refreshTorrents:t})})),yp=({id:e,show:t,onHide:n})=>{if(!t)return null;const[r,l]=x.useState(!1),[o,i]=x.useState(null),[u,s]=x.useState(!1),a=x.useContext(Nt),v=At(g=>g.refreshTorrents),h=()=>{l(!1),i(null),s(!1),n()},f=()=>{s(!0),(r?a.delete:a.forget)(e).then(()=>{v(),h()}).catch(y=>{i({text:`Error deleting torrent id=${e}`,details:y}),s(!1)})};return c.jsxs(Bl,{isOpen:t,onClose:n,title:"Delete torrent",children:[c.jsxs(Vl,{children:[c.jsx("p",{className:"text-gray-700 dark:text-slate-300",children:"Are you sure you want to delete the torrent?"}),c.jsxs("div",{className:"mt-4 flex items-center",children:[c.jsx("input",{type:"checkbox",id:"deleteFiles",className:"form-checkbox h-4 w-4 text-blue-500",onChange:()=>l(!r),checked:r,placeholder:"Also delete files"}),c.jsx("label",{htmlFor:"deleteFiles",className:"ml-2 text-gray-700 dark:text-slate-300",children:"Also delete files"})]}),o&&c.jsx(Qt,{error:o})]}),c.jsxs(Hl,{children:[u&&c.jsx(Sl,{}),c.jsx(Et,{variant:"cancel",onClick:h,children:"Cancel"}),c.jsx(Et,{variant:"danger",onClick:f,disabled:u,children:"Delete Torrent"})]})]})};function xp(e){return ee({tag:"svg",attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M144 479H48c-26.5 0-48-21.5-48-48V79c0-26.5 21.5-48 48-48h96c26.5 0 48 21.5 48 48v352c0 26.5-21.5 48-48 48zm304-48V79c0-26.5-21.5-48-48-48h-96c-26.5 0-48 21.5-48 48v352c0 26.5 21.5 48 48 48h96c26.5 0 48-21.5 48-48z"}}]})(e)}function wp(e){return ee({tag:"svg",attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M424.4 214.7L72.4 6.6C43.8-10.3 0 6.1 0 47.9V464c0 37.5 40.7 60.1 72.4 41.3l352-208c31.4-18.5 31.5-64.1 0-82.6z"}}]})(e)}function kp(e){return ee({tag:"svg",attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M432 32H312l-9.4-18.7A24 24 0 0 0 281.1 0H166.8a23.72 23.72 0 0 0-21.4 13.3L136 32H16A16 16 0 0 0 0 48v32a16 16 0 0 0 16 16h416a16 16 0 0 0 16-16V48a16 16 0 0 0-16-16zM53.2 467a48 48 0 0 0 47.9 45h245.8a48 48 0 0 0 47.9-45L416 128H32z"}}]})(e)}const gn=Cd(e=>({closeableError:null,setCloseableError:t=>e(()=>({closeableError:t})),otherError:null,setOtherError:t=>e(()=>({otherError:t}))})),Sp=({id:e,statsResponse:t})=>{let n=t.state,[r,l]=x.useState(!1),[o,i]=x.useState(!1),u=x.useContext(dd);const s=n=="live",a=n=="paused"||n=="error",v=gn(L=>L.setCloseableError),h=x.useContext(Nt),f=()=>{l(!0),h.start(e).then(()=>{u.refresh()},L=>{v({text:`Error starting torrent id=${e}`,details:L})}).finally(()=>l(!1))},g=()=>{l(!0),h.pause(e).then(()=>{u.refresh()},L=>{v({text:`Error pausing torrent id=${e}`,details:L})}).finally(()=>l(!1))},y=()=>{l(!0),i(!0)},S=()=>{l(!1),i(!1)};return c.jsxs("div",{className:"flex w-full justify-center gap-2 dark:text-slate-300",children:[a&&c.jsx(vn,{onClick:f,disabled:r,children:c.jsx(wp,{className:"hover:text-green-600"})}),s&&c.jsx(vn,{onClick:g,disabled:r,children:c.jsx(xp,{className:"hover:text-amber-500"})}),c.jsx(vn,{onClick:y,disabled:r,children:c.jsx(kp,{className:"hover:text-red-500"})}),c.jsx(yp,{id:e,show:o,onHide:S})]})},Zs={warn:"bg-amber-500 text-white",info:"bg-blue-500 text-white",success:"bg-green-700 text-white",error:"bg-red-500 text-white"},Ep=({now:e,variant:t,label:n})=>{const r=n??`${e.toFixed(2)}%`,l=Zs[t??"info"]??Zs.info;return c.jsx("div",{className:"w-full bg-gray-200 rounded-full dark:bg-gray-500",children:c.jsx("div",{className:`text-xs font-medium transition-all text-center p-0.5 leading-none rounded-full ${l}`,style:{width:`${e}%`},children:r})})};function pr(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 Cp=({statsResponse:e})=>{var t,n;switch(e.state){case r1:return"Paused";case wu:return"Checking files";case o1: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:["(",pr(e.live.snapshot.uploaded_bytes),")"]})]})]})};function _p(e){return e.files.filter(n=>n.included).reduce((n,r)=>n.length>r.length?n:r).name}function jp(e){return e.name??_p(e)}function Np(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 Tp(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":Np(t)}function Lp(e){return ee({tag:"svg",attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"}},{tag:"path",attr:{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z"}}]})(e)}function Pp(e){return ee({tag:"svg",attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"}},{tag:"path",attr:{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z"}}]})(e)}function zp(e){return ee({tag:"svg",attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"}},{tag:"path",attr:{d:"M5 20h14v-2H5v2zM19 9h-4V3H9v6H5l7 7 7-7z"}}]})(e)}function Mp(e){return ee({tag:"svg",attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0V0z"}},{tag:"path",attr:{d:"M9 16h6v-6h4l-7-7-7 7h4v6zm3-10.17L14.17 8H13v6h-2V8H9.83L12 5.83zM5 18h14v2H5z"}}]})(e)}function Op(e){return ee({tag:"svg",attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"}},{tag:"path",attr:{d:"M22 12c0 5.52-4.48 10-10 10S2 17.52 2 12c0-1.19.22-2.32.6-3.38l1.88.68C4.17 10.14 4 11.05 4 12c0 4.41 3.59 8 8 8s8-3.59 8-8-3.59-8-8-8c-.95 0-1.85.17-2.69.48l-.68-1.89C9.69 2.22 10.82 2 12 2c5.52 0 10 4.48 10 10zM5.5 4C4.67 4 4 4.67 4 5.5S4.67 7 5.5 7 7 6.33 7 5.5 6.33 4 5.5 4zM11 16V8H9v8h2zm4 0V8h-2v8h2z"}}]})(e)}const Ip=({className:e,finished:t,live:n,error:r})=>{const l=t&&n;return r?c.jsx(Pp,{className:e,color:"red"}):l?c.jsx(Mp,{className:e,color:"green"}):t?c.jsx(Lp,{className:e,color:"green"}):n?c.jsx(zp,{className:`text-blue-500 ${e}`}):c.jsx(Op,{className:e})},Fp=({id:e,detailsResponse:t,statsResponse:n})=>{const r=(n==null?void 0:n.state)??"",l=(n==null?void 0:n.error)??null,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=()=>{var f;let h=(f=n==null?void 0:n.live)==null?void 0:f.snapshot.peer_stats;return h?`${h.live} / ${h.seen}`:""},v=h=>c.jsx(Ip,{className:h,error:!!l,live:!!(n!=null&&n.live),finished:u});return c.jsxs("section",{className:"flex flex-col sm:flex-row items-center gap-2 border p-2 border-gray-200 rounded-xl shadow-xs hover:drop-shadow-sm dark:bg-slate-800 dark:border-slate-900",children:[c.jsx("div",{className:"hidden md:block",children:v("w-10 h-10")}),c.jsxs("div",{className:"w-full flex flex-col gap-2",children:[t&&c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("div",{className:"md:hidden",children:v("w-5 h-5")}),c.jsx("div",{className:"text-left text-lg text-gray-900 text-ellipsis break-all dark:text-slate-200",children:jp(t)})]}),l?c.jsxs("p",{className:"text-red-500 text-sm",children:[c.jsx("strong",{children:"Error:"})," ",l]}):c.jsxs(c.Fragment,{children:[c.jsx("div",{children:c.jsx(Ep,{now:s,label:l,variant:r==wu?"warn":u?"success":"info"})}),c.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-2 sm:flex-wrap items-center text-sm text-nowrap font-medium text-gray-500",children:[c.jsxs("div",{className:"flex gap-2 items-center",children:[c.jsx(c1,{})," ",a().toString()]}),c.jsxs("div",{className:"flex gap-2 items-center",children:[c.jsx(a1,{}),c.jsxs("div",{children:[pr(i),"/",pr(o)]})]}),n&&c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"flex gap-2 items-center",children:[c.jsx(s1,{}),Tp(n)]}),c.jsx("div",{className:"flex gap-2 items-center",children:c.jsx(Cp,{statsResponse:n})})]})]})]})]}),n&&c.jsx("div",{className:"",children:c.jsx(Sp,{id:e,statsResponse:n})})]})},Dp=({id:e,torrent:t})=>{const[n,r]=x.useState(null),[l,o]=x.useState(null),[i,u]=x.useState(0),s=x.useContext(Nt),a=()=>{u(i+1)};return x.useEffect(()=>{if(n===null)return fd(async()=>{await s.getTorrentDetails(t.id).then(r)},1e3)},[n]),x.useEffect(()=>ku(async()=>s.getTorrentStats(t.id).then(g=>(o(g),g)).then(g=>g.state==wu||g.state==l1?1e3:1e4,()=>1e4),0),[i]),c.jsx(dd.Provider,{value:{refresh:a},children:c.jsx(Fp,{id:e,detailsResponse:n,statsResponse:l})})},Rp=e=>c.jsx("div",{className:"flex flex-col gap-2 mx-2 pb-3 sm:px-7",children:e.torrents===null?e.loading?c.jsx(Sl,{className:"justify-center m-5",label:"Loading torrent list"}):null:e.torrents.length===0?c.jsx("p",{className:"text-center",children:"No existing torrents found."}):e.torrents.map(t=>c.jsx(Dp,{id:t.id,torrent:t},t.id))}),$p=e=>{let t=gn(i=>i.closeableError),n=gn(i=>i.setCloseableError),r=gn(i=>i.otherError),l=At(i=>i.torrents),o=At(i=>i.torrentsInitiallyLoading);return c.jsxs("div",{className:"container mx-auto",children:[c.jsx(Qt,{error:t,remove:()=>n(null)}),c.jsx(Qt,{error:r}),c.jsx(Rp,{torrents:l,loading:o})]})};var Ap="Expected a function",Ks=0/0,Up="[object Symbol]",Bp=/^\s+|\s+$/g,Vp=/^[-+]0x[0-9a-f]+$/i,Hp=/^0b[01]+$/i,Wp=/^0o[0-7]+$/i,Qp=parseInt,Zp=typeof kr=="object"&&kr&&kr.Object===Object&&kr,Kp=typeof self=="object"&&self&&self.Object===Object&&self,Gp=Zp||Kp||Function("return this")(),Yp=Object.prototype,Xp=Yp.toString,Jp=Math.max,qp=Math.min,Lo=function(){return Gp.Date.now()};function bp(e,t,n){var r,l,o,i,u,s,a=0,v=!1,h=!1,f=!0;if(typeof e!="function")throw new TypeError(Ap);t=Gs(t)||0,_i(n)&&(v=!!n.leading,h="maxWait"in n,o=h?Jp(Gs(n.maxWait)||0,t):o,f="trailing"in n?!!n.trailing:f);function g(E){var j=r,T=l;return r=l=void 0,a=E,i=e.apply(T,j),i}function y(E){return a=E,u=setTimeout(p,t),v?g(E):i}function S(E){var j=E-s,T=E-a,D=t-j;return h?qp(D,o-T):D}function L(E){var j=E-s,T=E-a;return s===void 0||j>=t||j<0||h&&T>=o}function p(){var E=Lo();if(L(E))return d(E);u=setTimeout(p,S(E))}function d(E){return u=void 0,f&&r?g(E):(r=l=void 0,i)}function m(){u!==void 0&&clearTimeout(u),a=0,r=s=l=u=void 0}function w(){return u===void 0?i:d(Lo())}function _(){var E=Lo(),j=L(E);if(r=arguments,l=this,s=E,j){if(u===void 0)return y(s);if(h)return u=setTimeout(p,t),g(s)}return u===void 0&&(u=setTimeout(p,t)),i}return _.cancel=m,_.flush=w,_}function _i(e){var t=typeof e;return!!e&&(t=="object"||t=="function")}function eh(e){return!!e&&typeof e=="object"}function th(e){return typeof e=="symbol"||eh(e)&&Xp.call(e)==Up}function Gs(e){if(typeof e=="number")return e;if(th(e))return Ks;if(_i(e)){var t=typeof e.valueOf=="function"?e.valueOf():e;e=_i(t)?t+"":t}if(typeof e!="string")return e===0?e:+e;e=e.replace(Bp,"");var n=Hp.test(e);return n||Wp.test(e)?Qp(e.slice(2),n?2:8):Vp.test(e)?Ks:+e}var nh=bp;const rh=El(nh),lh=({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]})),"}"]})},oh=({span:e})=>c.jsxs(c.Fragment,{children:[c.jsx("span",{className:"font-bold",children:e.name}),c.jsx(lh,{span:e}),c.jsx("span",{className:"font-bold",children:":"})]}),ih=({fields:e})=>c.jsxs("span",{className:`m-1 ${e.message.match(/error|fail/g)?"text-red-500":"text-slate-500 dark:text-slate-200"}`,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:"italic font-bold",children:t}),"=",n]},t))]}),uh=Je.memo(({line:e})=>{var r;const t=e,n=l=>{switch(l){case"DEBUG":return"text-blue-500";case"INFO":return"text-green-500";case"WARN":return"text-amber-500";case"ERROR":return"text-red-500";default:return"text-slate-500"}};return c.jsxs("p",{className:"font-mono m-0 text-break text-[10px]",children:[c.jsx("span",{className:"m-1 text-slate-500 dark:text-slate-400",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(oh,{span:l},o))}),c.jsx("span",{className:"m-1 text-slate-500 dark:text-slate-400",children:t.target}),c.jsx(ih,{fields:t.fields})]})}),_d=({children:e})=>c.jsx("form",{children:e}),Cu=({autoFocus:e,value:t,name:n,disabled:r,onChange:l,onKeyDown:o,label:i,help:u,inputType:s,placeholder:a})=>c.jsxs("div",{className:"flex flex-col gap-2 text-sm mb-2",children:[c.jsx("label",{htmlFor:n,className:"dark:text-white",children:i}),c.jsx("input",{autoFocus:e,type:s,className:"block border rounded bg-transparent py-1.5 pl-2 text-gray-800 focus:ring-0 sm:text-sm sm:leading-6 dark:text-slate-300",id:n,name:n,disabled:r,placeholder:a,value:t,onKeyDown:o,onChange:l}),u&&c.jsx("div",{className:"text-xs text-slate-500 dark:text-slate-300",children:u})]}),sh=(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},ah=(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 f=await a.text();throw n({text:"error fetching logs",details:{statusText:a.statusText,text:f}}),null}if(!a.body){n({text:"error fetching logs: ReadableStream not supported."});return}n(null);const v=a.body.getReader();let h=new Uint8Array;for(;;){const{done:f,value:g}=await v.read();if(f)throw n({text:"log stream terminated"}),null;h=sh(h,g);for(let y;(y=h.indexOf(10))!==-1;){let S=h.slice(0,y),L=new TextDecoder().decode(S);t(L),h=h.slice(y+1)}}};let s=fd(()=>u().then(()=>{},a=>{if(!o&&a!==null)throw n({text:"error streaming logs",details:{text:a.toString()}}),a}),1e3);return()=>{i(),s()}},ch=({url:e,maxLines:t})=>{const[n,r]=x.useState([]),[l,o]=x.useState(null),[i,u]=x.useState(""),s=x.useRef(null),a=t??1e3,v=x.useCallback(y=>{r(S=>[{id:S.length==0?0:S[0].id+1,content:y,parsed:JSON.parse(y),show:s.current?!!y.match(s.current):!0},...S.slice(0,a-1)])},[s.current,t]),h=x.useRef(v);h.current=v;const f=rh(y=>{let S=null;try{S=new RegExp(y)}catch{return}s.current=S,r(L=>{let p=[...L];for(let d of p)d.show=!!d.content.match(S);return p})},200),g=y=>{u(y),f(y)};return x.useEffect(()=>f.cancel,[]),x.useEffect(()=>ah(e,y=>h.current(y),o),[e]),c.jsxs("div",{children:[c.jsx(Qt,{error:l}),c.jsxs("div",{className:"mb-3",children:["Showing last ",a," logs since this window was opened"]}),c.jsx(_d,{children:c.jsx(Cu,{value:i,name:"filter",placeholder:"Enter filter (regex)",onChange:y=>g(y.target.value)})}),n.map(y=>c.jsx("div",{hidden:!y.show,children:c.jsx(uh,{line:y.parsed})},y.id))]})},dh=({show:e,onClose:t})=>{let r=x.useContext(Nt).getStreamLogsUrl();return c.jsxs(Bl,{isOpen:e,onClose:t,title:"rqbit server logs",className:"max-w-7xl",children:[c.jsx(Vl,{children:r?c.jsx(ch,{url:r}):c.jsx(Qt,{error:{text:"HTTP API not available to stream logs"}})}),c.jsx(Hl,{children:c.jsx(Et,{variant:"primary",onClick:t,children:"Close"})})]})},fh=({children:e,label:t,help:n,className:r})=>c.jsxs("fieldset",{className:`mb-4 ${r}`,children:[t&&c.jsx("label",{className:"text-md font-md mb-3 block pb-1 border-b",children:t}),e]}),Ys=({checked:e,name:t,disabled:n,onChange:r,label:l,help:o,inputType:i})=>c.jsxs("div",{className:"flex gap-3 items-start",children:[c.jsx("div",{className:"flex",children:c.jsx("input",{type:i||"checkbox",className:"block mt-1",id:t,name:t,disabled:n,checked:e,onChange:r})}),c.jsxs("div",{className:"text-sm flex flex-col gap-1",children:[c.jsx("label",{htmlFor:t,children:l}),o&&c.jsx("div",{className:"text-xs text-slate-500 dark:text-slate-300 mb-3",children:o})]})]});function ph(e){return ee({tag:"svg",attr:{viewBox:"0 0 24 24"},child:[{tag:"g",attr:{id:"Square_Minus"},child:[{tag:"g",attr:{},child:[{tag:"path",attr:{d:"M18.438,20.938H5.564a2.5,2.5,0,0,1-2.5-2.5V5.564a2.5,2.5,0,0,1,2.5-2.5H18.438a2.5,2.5,0,0,1,2.5,2.5V18.438A2.5,2.5,0,0,1,18.438,20.938ZM5.564,4.064a1.5,1.5,0,0,0-1.5,1.5V18.438a1.5,1.5,0,0,0,1.5,1.5H18.438a1.5,1.5,0,0,0,1.5-1.5V5.564a1.5,1.5,0,0,0-1.5-1.5Z"}},{tag:"path",attr:{d:"M9,12.5a.5.5,0,0,1,0-1h6a.5.5,0,0,1,0,1Z"}}]}]}]})(e)}function hh(e){return ee({tag:"svg",attr:{viewBox:"0 0 24 24"},child:[{tag:"g",attr:{id:"Square_Plus"},child:[{tag:"g",attr:{},child:[{tag:"path",attr:{d:"M18.438,20.938H5.563a2.5,2.5,0,0,1-2.5-2.5V5.564a2.5,2.5,0,0,1,2.5-2.5H18.438a2.5,2.5,0,0,1,2.5,2.5V18.438A2.5,2.5,0,0,1,18.438,20.938ZM5.563,4.064a1.5,1.5,0,0,0-1.5,1.5V18.438a1.5,1.5,0,0,0,1.5,1.5H18.438a1.5,1.5,0,0,0,1.5-1.5V5.564a1.5,1.5,0,0,0-1.5-1.5Z"}},{tag:"path",attr:{d:"M15,12.5H12.5V15a.5.5,0,0,1-1,0V12.5H9a.5.5,0,0,1,0-1h2.5V9a.5.5,0,0,1,1,0v2.5H15A.5.5,0,0,1,15,12.5Z"}}]}]}]})(e)}const mh=e=>{const t=(n,r,l,o)=>{let i=[],u=[],s={};const a=h=>(s[h]=s[h]||[],s[h]);l.forEach(h=>{if(o==h.pathComponents.length-1){i.push(h);return}a(h.pathComponents[0]).push(h)});let v=0;for(const[h,f]of Object.entries(s))u.push(t(h,r+"."+v,f,o+1)),v+=1;return{name:n,id:r,dirs:u,files:i}};return t("","filetree-root",e.details.files.map((n,r)=>({id:r,filename:n.components[n.components.length-1],pathComponents:n.components,length:n.length})),0)},jd=({tree:e,selectedFiles:t,setSelectedFiles:n,initialExpanded:r,listTorrentResponse:l})=>{let[o,i]=x.useState(r),u=x.useMemo(()=>{let f=g=>{let y=g.dirs.flatMap(f);return y.push(...g.files.map(S=>S.id)),y};return f(e)},[e]);const s=f=>{if(f.target.checked){let g=new Set(t);u.forEach(y=>g.add(y)),n(g)}else{let g=new Set(t);u.forEach(y=>g.delete(y)),n(g)}},a=f=>{if(t.has(f)){let g=new Set(t);g.delete(f),n(g)}else{let g=new Set(t);g.add(f),n(g)}},v=()=>u.filter(f=>t.has(f)).length,h=()=>u.filter(f=>t.has(f)).map(f=>l.details.files[f].length).reduce((f,g)=>f+g,0);return c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"flex items-center",children:[c.jsx(vn,{onClick:()=>i(!o),children:o?c.jsx(ph,{}):c.jsx(hh,{})}),c.jsx(Ys,{checked:u.every(f=>t.has(f)),label:`${e.name?e.name+", ":""} ${v()} files, ${pr(h())}`,name:e.id,onChange:s})]}),c.jsxs("div",{className:"pl-5",hidden:!o,children:[e.dirs.map(f=>c.jsx(jd,{listTorrentResponse:l,tree:f,selectedFiles:t,setSelectedFiles:n,initialExpanded:!1},f.name)),c.jsx("div",{className:"pl-1",children:e.files.map(f=>c.jsx(Ys,{checked:t.has(f.id),label:`${f.filename} (${pr(f.length)})`,name:`file-${f.id}`,onChange:()=>a(f.id)},f.id))})]})]})},vh=({listTorrentResponse:e,selectedFiles:t,setSelectedFiles:n})=>{let r=x.useMemo(()=>mh(e),[e]);return c.jsx(c.Fragment,{children:c.jsx(jd,{listTorrentResponse:e,tree:r,selectedFiles:t,setSelectedFiles:n,initialExpanded:!0})})},gh=e=>{let{onHide:t,listTorrentResponse:n,listTorrentError:r,listTorrentLoading:l,data:o}=e;const[i,u]=x.useState(new Set),[s,a]=x.useState(!1),[v,h]=x.useState(null),[f,g]=x.useState(!1),[y,S]=x.useState(""),L=At(_=>_.refreshTorrents),p=x.useContext(Nt);x.useEffect(()=>{u(new Set(n==null?void 0:n.details.files.map((_,E)=>E))),S((n==null?void 0:n.output_folder)||"")},[n]);const d=()=>{t(),u(new Set),h(null),a(!1)},m=async()=>{if(!n)return;a(!0);let _=n.seen_peers?n.seen_peers.slice(0,32):null,E={overwrite:!0,only_files:Array.from(i),initial_peers:_,output_folder:y};f&&(E.peer_opts={connect_timeout:20,read_write_timeout:60}),p.uploadTorrent(o,E).then(()=>{t(),L()},j=>{h({text:"Error starting torrent",details:j})}).finally(()=>a(!1))},w=()=>{if(l)return c.jsx(Sl,{label:"Loading torrent contents"});if(r)return c.jsx(Qt,{error:r});if(n)return c.jsxs(_d,{children:[c.jsx(Cu,{label:"Output folder",name:"output_folder",inputType:"text",value:y,onChange:_=>S(_.target.value)}),c.jsx(fh,{children:c.jsx(vh,{selectedFiles:i,setSelectedFiles:u,listTorrentResponse:n})})]})};return c.jsxs(Bl,{isOpen:!0,onClose:d,title:"Add Torrent",children:[c.jsxs(Vl,{children:[w(),c.jsx(Qt,{error:v})]}),c.jsxs(Hl,{children:[s&&c.jsx(Sl,{}),c.jsx(Et,{onClick:d,variant:"cancel",children:"Cancel"}),c.jsx(Et,{onClick:m,variant:"primary",disabled:l||s||i.size==0,children:"OK"})]})]})},Nd=({onClick:e,data:t,resetData:n,children:r,className:l})=>{const[o,i]=x.useState(!1),[u,s]=x.useState(null),[a,v]=x.useState(null),h=x.useContext(Nt);x.useEffect(()=>{if(t===null)return;let g=setTimeout(async()=>{i(!0);try{const y=await h.uploadTorrent(t,{list_only:!0});s(y)}catch(y){v({text:"Error listing torrent files",details:y})}finally{i(!1)}},0);return()=>clearTimeout(g)},[t]);const f=()=>{n(),v(null),s(null),i(!1)};return c.jsxs(c.Fragment,{children:[c.jsx(Et,{onClick:e,className:l,children:r}),t&&c.jsx(gh,{onHide:f,listTorrentError:a,listTorrentResponse:u,data:t,listTorrentLoading:o})]})};function yh(e){return ee({tag:"svg",attr:{viewBox:"0 0 24 24",fill:"none"},child:[{tag:"path",attr:{d:"M10 18V16H8V14H10V12H12V14H14V16H12V18H10Z",fill:"currentColor"}},{tag:"path",attr:{fillRule:"evenodd",clipRule:"evenodd",d:"M6 2C4.34315 2 3 3.34315 3 5V19C3 20.6569 4.34315 22 6 22H18C19.6569 22 21 20.6569 21 19V9C21 5.13401 17.866 2 14 2H6ZM6 4H13V9H19V19C19 19.5523 18.5523 20 18 20H6C5.44772 20 5 19.5523 5 19V5C5 4.44772 5.44772 4 6 4ZM15 4.10002C16.6113 4.4271 17.9413 5.52906 18.584 7H15V4.10002Z",fill:"currentColor"}}]})(e)}function xh(e){return ee({tag:"svg",attr:{viewBox:"0 0 24 24",fill:"none"},child:[{tag:"path",attr:{d:"M14.8284 12L16.2426 13.4142L19.071 10.5858C20.6331 9.02365 20.6331 6.49099 19.071 4.9289C17.509 3.3668 14.9763 3.3668 13.4142 4.9289L10.5858 7.75732L12 9.17154L14.8284 6.34311C15.6095 5.56206 16.8758 5.56206 17.6568 6.34311C18.4379 7.12416 18.4379 8.39049 17.6568 9.17154L14.8284 12Z",fill:"currentColor"}},{tag:"path",attr:{d:"M12 14.8285L13.4142 16.2427L10.5858 19.0711C9.02372 20.6332 6.49106 20.6332 4.92896 19.0711C3.36686 17.509 3.36686 14.9764 4.92896 13.4143L7.75739 10.5858L9.1716 12L6.34317 14.8285C5.56212 15.6095 5.56212 16.8758 6.34317 17.6569C7.12422 18.4379 8.39055 18.4379 9.1716 17.6569L12 14.8285Z",fill:"currentColor"}},{tag:"path",attr:{d:"M14.8285 10.5857C15.219 10.1952 15.219 9.56199 14.8285 9.17147C14.4379 8.78094 13.8048 8.78094 13.4142 9.17147L9.1716 13.4141C8.78107 13.8046 8.78107 14.4378 9.1716 14.8283C9.56212 15.2188 10.1953 15.2188 10.5858 14.8283L14.8285 10.5857Z",fill:"currentColor"}}]})(e)}const wh=({className:e})=>{const t=x.useRef(),[n,r]=x.useState(null),l=async()=>{var s;if(!((s=t==null?void 0:t.current)!=null&&s.files))return;const u=t.current.files[0];r(u)},o=()=>{t!=null&&t.current&&(t.current.value="",r(null))},i=()=>{t!=null&&t.current&&t.current.click()};return c.jsxs(c.Fragment,{children:[c.jsx("input",{type:"file",ref:t,accept:".torrent",onChange:l,hidden:!0}),c.jsxs(Nd,{onClick:i,data:n,resetData:o,className:`group ${e}`,children:[c.jsx(yh,{className:"text-blue-500 group-hover:text-white dark:text-white"}),c.jsx("div",{children:"Upload .torrent File"})]})]})},kh=({className:e})=>{const[t,n]=x.useState(null),[r,l]=x.useState(""),[o,i]=x.useState(!1),u=()=>{n(r),l(""),i(!1)},s=()=>{i(!1),n(null)};return c.jsxs(c.Fragment,{children:[c.jsxs(Nd,{onClick:()=>{i(!0)},data:t,className:`group ${e}`,resetData:()=>n(null),children:[c.jsx(xh,{className:"text-blue-500 group-hover:text-white dark:text-white"}),c.jsx("div",{children:"Add Torrent from Magnet / URL"})]}),c.jsxs(Bl,{isOpen:o,onClose:s,title:"Add torrent",children:[c.jsx(Vl,{children:c.jsx(Cu,{autoFocus:!0,value:r,name:"magnet",onChange:a=>l(a.target.value),onKeyDown:a=>{a.key==="Enter"&&r&&u()},placeholder:"magnet:?xt=urn:btih:...",help:"Enter magnet or HTTP(S) URL to the .torrent"})}),c.jsxs(Hl,{children:[c.jsx(Et,{variant:"cancel",onClick:s,children:"Cancel"}),c.jsx(Et,{disabled:!r,variant:"primary",onClick:u,children:"Add"})]})]})]})},Sh=e=>x.createElement("svg",{width:"64mm",height:"64mm",viewBox:"0 0 64 64",id:"svg1",xmlSpace:"preserve","inkscape:version":"1.3.1 (91b66b0, 2023-11-16)","sodipodi:docname":"logo.svg","xmlns:inkscape":"http://www.inkscape.org/namespaces/inkscape","xmlns:sodipodi":"http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd",xmlns:"http://www.w3.org/2000/svg","xmlns:svg":"http://www.w3.org/2000/svg",...e},x.createElement("sodipodi:namedview",{id:"namedview1",pagecolor:"#ffffff",bordercolor:"#000000",borderopacity:.25,"inkscape:showpageshadow":2,"inkscape:pageopacity":0,"inkscape:pagecheckerboard":0,"inkscape:deskcolor":"#d1d1d1","inkscape:document-units":"mm","inkscape:zoom":1.4936372,"inkscape:cx":134.90559,"inkscape:cy":139.92689,"inkscape:window-width":1440,"inkscape:window-height":847,"inkscape:window-x":0,"inkscape:window-y":25,"inkscape:window-maximized":0,"inkscape:current-layer":"layer1"}),x.createElement("defs",{id:"defs1"},x.createElement("inkscape:perspective",{"sodipodi:type":"inkscape:persp3d","inkscape:vp_x":"3.1042448 : 18.147022 : 1","inkscape:vp_y":"0 : 999.99994 : 0","inkscape:vp_z":"303.94612 : 54.05812 : 1","inkscape:persp3d-origin":"105 : -134 : 1",id:"perspective4"})),x.createElement("g",{"inkscape:label":"Layer 1","inkscape:groupmode":"layer",id:"layer1",transform:"translate(-56.674541,-85.911432)"},x.createElement("path",{style:{fill:"#0d6efd",fillOpacity:1,strokeWidth:.610041},d:"m 81.603814,145.5382 -7.433116,-4.36986 -6.018097,-3.54529 -6.018099,-3.54529 -0.09405,-0.35761 -0.09406,-0.3576 v -15.31979 -15.31979 l 0.09451,-0.35939 0.09451,-0.35938 6.017643,-3.544433 6.017641,-3.544428 7.432805,-4.369167 7.432803,-4.369166 0.240089,0.09331 0.240083,0.09331 13.292394,7.826122 13.29241,7.826122 0.093,0.35355 0.093,0.35355 v 15.31979 15.31979 l -0.0928,0.35267 -0.0928,0.35266 -13.29682,7.82802 -13.296819,7.82803 -0.235583,0.0921 -0.235588,0.0921 z m 19.758596,-5.88315 12.13185,-7.15306 v -14.45996 -14.45994 l -5.11526,-3.01603 -5.11526,-3.016035 -7.017048,-4.136312 -7.017053,-4.13631 h -0.112738 -0.11273 l -7.097035,4.182089 -7.09703,4.18209 -5.035336,2.971548 -5.035335,2.97155 v 14.45761 14.45762 l 5.275113,3.11051 5.275113,3.11051 6.793709,4.02813 6.793702,4.02812 0.176743,0.0155 0.176742,0.0155 z",id:"path15","sodipodi:nodetypes":"cccccccccccccccccccccccccccccccccccccccccccccccccccc"}),x.createElement("path",{style:{fill:"#000000"},id:"path1",d:""}),x.createElement("path",{d:"m 84.161856,133.76725 -4.567369,-2.5483 -0.700367,0.28585 -0.700376,0.28584 -0.495731,0.11427 -0.495731,0.11426 -3.168791,-1.75603 -3.168782,-1.75603 -0.515321,-0.57002 -0.515323,-0.57002 0.0161,-3.59449 0.0161,-3.59448 0.164041,-0.41611 0.164042,-0.41611 1.480342,-0.85565 1.480346,-0.85565 0.06276,-3.67919 0.06276,-3.67921 0.39653,-0.35884 0.396521,-0.35886 3.663275,-2.04111 3.663267,-2.04112 0.114523,-1.62785 0.114506,-1.62786 0.229029,-0.21764 0.229038,-0.21765 3.341459,-1.854383 3.341467,-1.854382 h 0.301682 0.301682 l 2.476951,1.380374 2.476959,1.380381 1.151673,0.57845 1.151674,0.57845 0.02969,0.27424 0.02969,0.27423 0.02753,1.46272 0.02753,1.46273 3.663258,2.04521 3.66327,2.04521 0.40205,0.36386 0.40206,0.36385 v 3.60098 3.60097 l 0.28629,0.23408 0.28628,0.23408 1.43146,0.72479 1.43145,0.72479 v 3.9806 3.98059 l -0.51533,0.56995 -0.51532,0.56994 -3.19072,1.75191 -3.19072,1.75191 -0.47379,-0.11007 -0.473797,-0.11007 -0.699654,-0.28558 -0.699656,-0.28558 -4.589745,2.5527 -4.589746,2.55269 -0.321886,-0.004 -0.321886,-0.004 z m 8.681258,-1.65766 3.426793,-1.91645 0.06536,-0.19784 0.06535,-0.19785 -1.315884,-0.68709 -1.315885,-0.6871 -0.401264,-0.40081 -0.401265,-0.4008 v -3.79409 -3.79409 l 0.221568,-0.41401 0.221567,-0.414 3.411065,-1.86126 3.411061,-1.86126 h 0.38456 0.38455 l 0.91435,0.46646 0.91435,0.46646 -0.0646,-2.66249 -0.0646,-2.66248 -2.829977,-1.58148 -2.829984,-1.58149 -0.204696,0.12651 -0.204688,0.12651 v 1.11999 1.11999 l -0.744359,0.54975 -0.744358,0.54977 -2.773906,1.52318 -2.773906,1.52319 h -0.526565 -0.526565 l -3.34145,-1.85945 -3.341467,-1.85945 -0.168271,-0.2591 -0.16827,-0.25909 -0.0035,-1.07439 -0.0035,-1.07439 -0.204688,-0.12651 -0.204697,-0.12651 -2.82999,1.58149 -2.829982,1.58148 -0.06458,2.66248 -0.06458,2.66249 0.914351,-0.46646 0.914343,-0.46646 h 0.378551 0.37855 l 3.638639,1.97495 3.63864,1.97495 v 4.0944 4.09441 l -0.401265,0.4008 -0.401264,0.40081 -1.315885,0.6871 -1.315884,0.68709 0.06535,0.19785 0.06536,0.19784 3.426792,1.91645 3.426785,1.91644 h 0.343552 0.343544 z m -16.416873,-5.4431 -0.06475,-2.55838 -2.046125,-1.10985 -2.046124,-1.10984 -0.195677,0.19567 -0.195685,0.19568 0.06596,2.2656 0.06596,2.2656 2.06129,1.18713 2.06129,1.18713 0.179282,0.0198 0.179273,0.0198 z m 4.515881,1.34369 2.061291,-1.19456 0.06527,-2.48747 0.06527,-2.48748 -0.408821,0.15589 -0.408848,0.15589 -1.889514,1.02885 -1.889514,1.02885 v 2.50736 2.50736 l 0.171777,-0.01 0.171767,-0.01 z m 18.666131,-1.29267 v -2.50736 l -1.889509,-1.02885 -1.889522,-1.02885 -0.40883,-0.15589 -0.408839,-0.15589 0.06527,2.48748 0.06527,2.48747 2.061291,1.19456 2.061288,1.19456 0.171777,0.01 0.171774,0.01 z m 4.466127,1.28059 2.06129,-1.18713 0.0661,-2.2656 0.066,-2.2656 -0.19568,-0.19568 -0.19568,-0.19567 -2.04613,1.10984 -2.04612,1.10985 -0.0647,2.55838 -0.0648,2.55838 0.17927,-0.0198 0.17927,-0.0198 z m -24.281888,-6.71835 1.960418,-1.07415 -0.07566,-0.22693 -0.07566,-0.22691 -2.049423,-1.09443 -2.049431,-1.09442 -2.116604,1.14523 -2.116613,1.14523 v 0.17781 0.17782 l 2.004029,1.06709 2.004037,1.06711 0.277236,0.005 0.277237,0.005 z m 23.056528,4.3e-4 2.03643,-1.07372 -0.0708,-0.21245 -0.0708,-0.21244 -2.09332,-1.13015 -2.09332,-1.13016 -2.077692,1.17124 -2.077685,1.17123 v 0.17384 0.17386 l 1.889522,1.0551 1.889505,1.0551 0.31588,0.0161 0.31587,0.0161 z m -14.742004,-11.90808 0.06492,-2.2946 -0.293917,-0.23052 -0.293926,-0.2305 -2.011741,-1.08631 -2.01175,-1.08629 0.06501,2.57478 0.06501,2.57476 1.946776,1.09773 1.946767,1.09773 0.229038,-0.0611 0.229029,-0.0611 z m 4.401245,1.31989 1.946767,-1.09857 0.06501,-2.57476 0.06501,-2.57478 -2.01175,1.08629 -2.011741,1.08631 -0.286291,0.22417 -0.286291,0.22418 v 2.22411 2.2241 l 0.152689,0.15269 0.152689,0.15269 0.133602,-0.0139 0.133602,-0.0139 z m -1.021015,-6.79999 1.952048,-1.05546 -0.224347,-0.26147 -0.224337,-0.26149 -1.958921,-1.03065 -1.958911,-1.03064 -1.958912,1.03064 -1.958912,1.03065 -0.224303,0.26142 -0.224277,0.26141 1.896915,1.04261 1.896906,1.04261 0.517494,0.0129 0.517501,0.0129 z",style:{fill:"#0d6efd",fillOpacity:1,strokeWidth:.865634},id:"path1-8"}))),Eh=({title:e})=>{const[t,n]=e.split("-");return c.jsxs("header",{className:"bg-slate-50 drop-shadow-lg flex flex-wrap justify-center lg:justify-between items-center dark:bg-slate-800 mb-3",children:[c.jsxs("div",{className:"flex flex-nowrap items-center justify-between m-2",children:[c.jsx(Sh,{className:"w-10 h-10 p-1",alt:"logo"}),c.jsxs("h1",{className:"flex items-center dark:text-white",children:[c.jsx("div",{className:"text-3xl",children:t}),c.jsx("div",{className:"bg-blue-100 text-blue-800 text-xl font-semibold me-2 px-2.5 py-0.5 rounded ms-2 dark:bg-blue-900 dark:text-white",children:n})]})]}),c.jsxs("div",{className:"flex flex-wrap gap-1 m-2",children:[c.jsx(kh,{className:"flex-grow justify-center dark:text-white"}),c.jsx(wh,{className:"flex-grow justify-center dark:text-white"})]})]})};let Xt=window.matchMedia("(prefers-color-scheme: dark)").matches;window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",e=>{Ql.setDark(e.matches)});const Ql={isDark:()=>Xt,setDark:e=>(Xt=e,document.body.classList.toggle("dark",Xt),Xt),toggle:()=>{Ql.setDark(!Xt)}};Ql.setDark(Xt);const Ch=e=>{let[t,n]=x.useState(!1);gn(a=>a.setCloseableError);const r=gn(a=>a.setOtherError),l=x.useContext(Nt),o=At(a=>a.setTorrents),i=At(a=>a.setTorrentsLoading),u=At(a=>a.setRefreshTorrents),s=async()=>{i(!0);let a=await l.listTorrents().finally(()=>i(!1));o(a.torrents)};return u(s),x.useEffect(()=>ku(async()=>s().then(()=>(r(null),5e3),a=>(r({text:"Error refreshing torrents",details:a}),console.error(a),5e3)),0),[]),c.jsxs("div",{className:"dark:bg-gray-900 dark:text-gray-200 min-h-screen",children:[c.jsx(Eh,{title:e.title}),c.jsxs("div",{className:"relative",children:[c.jsxs("div",{className:"absolute top-0 start-0 pl-2 z-10",children:[e.menuButtons&&e.menuButtons.map((a,v)=>c.jsx("span",{children:a},v)),c.jsx(vn,{onClick:()=>n(!0),children:c.jsx(d1,{})}),c.jsx(vn,{onClick:Ql.toggle,children:c.jsx(f1,{})})]}),c.jsx($p,{})]}),c.jsx(dh,{show:t,onClose:()=>n(!1)})]})},Td=window.origin==="null"||window.origin==="http://localhost:3031"?"http://localhost:3030":"",Ze=async(e,t,n)=>{console.log(e,t);const r=Td+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()},Xs={getStreamLogsUrl:()=>Td+"/stream_logs",listTorrents:()=>Ze("GET","/torrents"),getTorrentDetails:e=>Ze("GET",`/torrents/${e}`),getTorrentStats:e=>Ze("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"),Ze("POST",n,e)},pause:e=>Ze("POST",`/torrents/${e}/pause`),start:e=>Ze("POST",`/torrents/${e}/start`),forget:e=>Ze("POST",`/torrents/${e}/forget`),delete:e=>Ze("POST",`/torrents/${e}/delete`),getVersion:async()=>(await Ze("GET","/")).version},_h=()=>{let[e,t]=x.useState("rqbit web UI");return x.useEffect(()=>ku(()=>Xs.getVersion().then(r=>{const l=`rqbit web UI - v${r}`;return t(l),document.title=l,1e4},r=>1e3),0),[]),c.jsx(Nt.Provider,{value:Xs,children:c.jsx(Ch,{title:e})})};Po.createRoot(document.getElementById("app")).render(c.jsx(x.StrictMode,{children:c.jsx(_h,{})})); diff --git a/crates/librqbit/webui/dist/manifest.json b/crates/librqbit/webui/dist/manifest.json index 3be229f..059ecb3 100644 --- a/crates/librqbit/webui/dist/manifest.json +++ b/crates/librqbit/webui/dist/manifest.json @@ -11,7 +11,7 @@ "css": [ "assets/index-d46108e9.css" ], - "file": "assets/index-b218d1f9.js", + "file": "assets/index-1ee4d2cc.js", "isEntry": true, "src": "index.html" } diff --git a/crates/librqbit/webui/tsconfig.json b/crates/librqbit/webui/tsconfig.json index ec0c6a1..4e07e2c 100644 --- a/crates/librqbit/webui/tsconfig.json +++ b/crates/librqbit/webui/tsconfig.json @@ -1,17 +1,14 @@ { - "compilerOptions": { - "target": "ES2020", - "module": "ESNext", - "moduleResolution": "bundler", - "noEmit": true, - "allowJs": true, - "checkJs": true, - "jsx": "react-jsx", - "skipLibCheck": true, - "strict": true, - }, - "include": [ - "node_modules/vite/client.d.ts", - "**/*" - ] -} \ No newline at end of file + "compilerOptions": { + "target": "ES2020", + "module": "ESNext", + "moduleResolution": "bundler", + "noEmit": true, + "allowJs": true, + "checkJs": true, + "jsx": "react-jsx", + "skipLibCheck": true, + "strict": true + }, + "include": ["node_modules/vite/client.d.ts", "**/*"] +} diff --git a/crates/librqbit_core/Cargo.toml b/crates/librqbit_core/Cargo.toml index 664010c..223f889 100644 --- a/crates/librqbit_core/Cargo.toml +++ b/crates/librqbit_core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "librqbit-core" -version = "3.4.0" +version = "3.5.0" edition = "2021" description = "Important utilities used throughout librqbit useful for working with torrents." license = "Apache-2.0" diff --git a/crates/rqbit/Cargo.toml b/crates/rqbit/Cargo.toml index c33dc20..5745fac 100644 --- a/crates/rqbit/Cargo.toml +++ b/crates/rqbit/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rqbit" -version = "5.4.0" +version = "5.4.1" authors = ["Igor Katson "] edition = "2021" description = "A bittorrent command line client and server." @@ -24,7 +24,7 @@ default-tls = ["librqbit/default-tls"] rust-tls = ["librqbit/rust-tls"] [dependencies] -librqbit = {path="../librqbit", default-features=false, version = "5.0.0"} +librqbit = {path="../librqbit", default-features=false, version = "5.4.1"} tokio = {version = "1", features = ["macros", "rt-multi-thread"]} console-subscriber = {version = "0.2", optional = true} anyhow = "1" diff --git a/desktop/src-tauri/Cargo.toml b/desktop/src-tauri/Cargo.toml index 0928638..8f64fdf 100644 --- a/desktop/src-tauri/Cargo.toml +++ b/desktop/src-tauri/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rqbit-desktop" -version = "5.4.0" +version = "5.4.1" description = "rqbit torrent client" authors = ["you"] license = ""