@jesec/flood
Version:
A modern Web UI for various torrent clients with multi-user and multi-client support
1 lines • 87 kB
JavaScript
"use strict";(globalThis.webpackChunk_jesec_flood=globalThis.webpackChunk_jesec_flood||[]).push([[179],{179:(e,t,s)=>{s.r(t),s.d(t,{default:()=>Bt});var i=s(6488),l=s(2618),n=s(6540),r=s(3443),a=s(9679),d=s(9161),o=s(6565),c=s(9075),h=s(2412);const u=({start:e,destination:t,tags:s,tab:i})=>{const l={};null!=e&&(l.startTorrentsOnLoad=e),null!=t&&""!==t&&(null==l.torrentDestinations&&(l.torrentDestinations=h.A.floodSettings.torrentDestinations||{}),"string"==typeof s?.[0]?l.torrentDestinations[s[0]]=t:l.torrentDestinations[""]=t),null!=i&&(l.UITorrentsAddTab=i),c.A.saveSettings(l)};var x=s(3537),_=s(4930),m=s(4848);const j=e=>{const{actions:t}=e,s=t.map((e,t)=>{let s=()=>{};return e.triggerDismiss&&(s=()=>{_.A.setActiveModal(null)}),"checkbox"===e.type?(0,m.jsx)(o.Sc,{defaultChecked:e.checked,id:e.id,onClick:t=>{null!=e.clickHandler&&e.clickHandler(t),s()},children:e.content},t):(0,m.jsx)(o.$n,{isLoading:e.isLoading,onClick:t=>{null!=e.clickHandler&&e.clickHandler(t),s()},priority:e.type,type:e.submit?"submit":"button",children:e.content},t)}),i=(0,m.jsx)("div",{className:"modal__button-group",children:s});return(0,m.jsx)("div",{className:"modal__actions",children:i})},g=({isAddingTorrents:e,onAddTorrentsClick:t})=>{const{i18n:s}=(0,d.uB)();return(0,m.jsx)(j,{actions:[{checked:Boolean(h.A.floodSettings.startTorrentsOnLoad),clickHandler:null,content:s._("torrents.add.start.label"),id:"start",triggerDismiss:!1,type:"checkbox"},{clickHandler:null,content:s._("button.cancel"),triggerDismiss:!0,type:"tertiary"},{clickHandler:t,content:s._("torrents.add.button.add"),isLoading:e,submit:!0,triggerDismiss:!1,type:"primary"}]})};var f=s(8221),p=s.n(f),b=s(5162),v=s(942),y=s(9475),k=s(9844),N=s(2114),A=s(8851),S=s(2592);const w=y.AH.raw({padding:"3px 9px"}),C=y.AH.raw({borderBottom:"1px solid #dde2e8",marginBottom:"3px",paddingBottom:"3px",opacity:.75,_last:{marginBottom:0}}),T=y.AH.raw({transition:"color 0.25s",whiteSpace:"nowrap","& button":{width:"100%",height:"100%",textAlign:"left",_disabled:{pointerEvents:"none"},...w}}),R=(0,y.AH)({opacity:.5,...T}),D=y.AH.raw({color:"#374c66",background:"rgba(94, 114, 140, 0.1)","& button:focus":{outline:"none",WebkitTapHighlightColor:"transparent"}}),M=(0,y.AH)({opacity:1,cursor:"pointer",transition:"background 0.25s, color 0.25s",userSelect:"none",_hover:D,_focusWithin:D,...T}),P={EACCES:"filesystem.error.eacces",ENOENT:"filesystem.error.enoent"},I=(0,n.memo)(({directory:e,selectable:t,onItemSelection:s,onYieldFocus:i})=>{const[l,r]=(0,n.useState)(null),[a,o]=(0,n.useState)(null),[c,h]=(0,n.useState)(e.includes("/")?"/":"\\"),[u,x]=(0,n.useState)(null),[_,j]=(0,n.useState)(null),g=(0,n.useRef)(null),f=e.lastIndexOf(c)+1,p=f>0?e.substr(0,f):e,b=e.substr(f);(0,n.useEffect)(()=>{p&&(r(null),x(null),j(null),A.A.fetchDirectoryList(p).then(({files:e,directories:t,separator:s})=>{x(t),j(e),h(s),o(null)}).catch(({response:e})=>{o(e)}))},[p]),(0,n.useEffect)(()=>{if(null!=g.current&&null!=l){const e=g.current.children[l]?.children[0];0===e?.tabIndex?e.focus():r(Array.from(g.current.children).findIndex(e=>0===e.children[0].tabIndex))}},[l]),(0,N.A)("ArrowUp",e=>{e.preventDefault(),r(e=>null==e||e-1<0?(i?.(),null):e-1)}),(0,N.A)("ArrowDown",e=>{e.preventDefault(),r(e=>null!=e?e+1:0)});let T=null,D=[];if((null==u&&"directories"===t||null==_&&"files"===t)&&(T="filesystem.fetching"),a&&a.data&&a.data.code&&(T=P[a.data.code]||"filesystem.error.unknown"),e){const e=`${p.split(c).slice(0,-2).join(c)}${c}`,i=(0,m.jsx)("li",{className:`${M} ${(0,y.AH)({"@media (max-width: 720px)":C})}`,children:(0,m.jsxs)("button",{type:"button",onClick:()=>s?.(e,!0),children:[(0,m.jsx)(v.i3,{className:(0,y.AH)({transform:"scale(0.75) rotate(180deg)"})}),".."]})},e),l="files"!==t,n=b?(0,S.A)(u,e=>e,b):[],r=n.includes(b)||"directories"!==t||!b||T?[]:(()=>{const e=`${p}${b}${c}`;return[(0,m.jsx)("li",{className:`${M} ${(0,y.AH)({"@media (max-width: 720px)":{display:"none"}})}`,style:{fontWeight:"bold"},children:(0,m.jsxs)("button",{type:"button",onClick:()=>s?.(e,!1),children:[(0,m.jsx)(v.N7,{}),(0,m.jsx)("span",{style:{whiteSpace:"pre-wrap"},children:b}),(0,m.jsxs)("em",{style:{fontWeight:"lighter"},children:[" - ",(0,m.jsx)(d.x6,{id:"filesystem.error.enoent"})]})]})},e)]})(),a=u?.length&&(0,k.di)(u.slice()).desc(e=>n.includes(e)).map(e=>{const t=`${p}${e}${c}`;return(0,m.jsx)("li",{className:l?M:R,style:n.includes(e)?{fontWeight:"bold"}:void 0,children:(0,m.jsxs)("button",{type:"button",disabled:!l,tabIndex:l?0:-1,onClick:l?()=>s?.(t,!0):void 0,children:[(0,m.jsx)(v.Ah,{}),e]})},t)})||[],o="directories"!==t,h=b?(0,S.A)(_,e=>e,b):[],x=_?.length&&(0,k.di)(_.slice()).desc(e=>h.includes(e)).map(e=>{const t=`${p}${e}`;return(0,m.jsx)("li",{className:o?M:R,style:h.includes(e)?{fontWeight:"bold"}:void 0,children:(0,m.jsxs)("button",{type:"button",disabled:!o,tabIndex:o?0:-1,onClick:o?()=>s?.(t,!1):void 0,children:[(0,m.jsx)(v.ZH,{}),e]})},t)})||[];0!==a.length||0!==x.length||T||(T="filesystem.empty.directory"),D=[i,...r,...a,...x]}else T="filesystem.error.no.input";return(0,m.jsxs)("div",{className:(0,y.AH)({color:"#5E728C",listStyle:"none",padding:"3px 0px","& .icon":{fill:"currentColor",height:"14px",width:"14px",marginRight:"5px",marginTop:"-3px",verticalAlign:"middle"}}),children:[p&&(0,m.jsxs)("li",{className:`${R} ${(0,y.AH)(C,w,{whiteSpace:"pre-wrap",wordBreak:"break-all","& .icon":{transform:"scale(0.9)",marginTop:"-2px !important"},"@media (max-width: 720px)":{display:"none"}})}`,children:[(0,m.jsx)(v.gx,{}),p]}),(0,m.jsx)("ul",{ref:g,children:D}),T&&(0,m.jsx)("div",{className:`${R} ${(0,y.AH)(w)}`,style:{opacity:1},children:(0,m.jsx)("em",{children:(0,m.jsx)(d.x6,{id:T})})})]})}),$=(0,n.forwardRef)(({id:e,label:t,selectable:s,suggested:i,showBasePathToggle:l=!1,showCompletedToggle:r=!1,showSequentialToggle:a=!1,onChange:c},u)=>{const[x,_]=(0,n.useState)(i||h.A.floodSettings.torrentDestinations?.[""]||h.A.clientSettings?.directoryDefault||""),[j,g]=(0,n.useState)(!1),f=(0,n.useRef)(null),y=(0,b.A)(u),{i18n:k}=(0,d.uB)();(0,n.useEffect)(()=>{const e=()=>{g(!1)},t=t=>{f.current?.contains(t.target)||e()};return document.addEventListener("click",t),window.addEventListener("resize",e),()=>{document.removeEventListener("click",t),window.removeEventListener("resize",e)}},[]);const N=[];return l&&N.push((0,m.jsx)(o.Sc,{grow:!1,id:"isBasePath",children:(0,m.jsx)(d.x6,{id:"torrents.destination.base_path"})},"isBasePath")),r&&N.push((0,m.jsx)(o.Sc,{grow:!1,id:"isCompleted",children:(0,m.jsx)(d.x6,{id:"torrents.destination.completed"})},"isCompleted")),a&&N.push((0,m.jsx)(o.Sc,{grow:!1,id:"isSequential",children:(0,m.jsx)(d.x6,{id:"torrents.destination.sequential"})},"isSequential")),(0,m.jsxs)(o.eW,{ref:f,children:[(0,m.jsx)(o.fh,{children:(0,m.jsxs)(o.Rj,{autoComplete:j?"off":void 0,addonPlacement:"after",defaultValue:x,id:e,label:t,onChange:p()(()=>{if(null==y.current)return;const e=y.current.value;c&&c(e),_(e)},100,{leading:!0}),onClick:e=>e.nativeEvent.stopImmediatePropagation(),placeholder:k._("torrents.add.destination.placeholder"),ref:y,children:[(0,m.jsx)(o.t0,{onClick:()=>{null!=y.current&&_(y.current.value),g(!j)},children:(0,m.jsx)(v.vj,{})}),(0,m.jsx)(o.ZL,{children:(0,m.jsx)(o.tz,{isIn:j,onClick:e=>e.nativeEvent.stopImmediatePropagation(),overlayProps:{isInteractive:!1},padding:!1,triggerRef:y,children:(0,m.jsx)(I,{directory:x,selectable:s,onItemSelection:(e,t=!0)=>{null!=y.current&&(y.current.value=e),g(t),_(e)},onYieldFocus:()=>{y.current?.focus()}})})})]})}),N.length>0?(0,m.jsx)(o.fh,{children:N}):null]})});var V=s(6942),L=s.n(V),H=s(9399);const F=({defaultValue:e,placeholder:t,id:s="tags",label:i,onTagSelected:l})=>{const[r,c]=(0,n.useState)(!1),[u,x]=(0,n.useState)(e??[]),_=(0,n.useRef)(null),j=(0,n.useRef)(null),g=(0,n.useRef)(null),f=L()("select form__element",{"select--is-open":r});return(0,a.A)("Escape",e=>{e.preventDefault(),c(!1)}),(0,n.useEffect)(()=>{const e=e=>{_.current?.contains(e.target)||c(!1)};return document.addEventListener("click",e),()=>{document.removeEventListener("click",e)}},[]),(0,n.useEffect)(()=>{null!=g.current&&(g.current.value=u.join()),l&&l(u)},[u,l]),(0,m.jsx)(o.ci,{ref:_,children:(0,m.jsx)("div",{className:f,children:(0,m.jsxs)(o.Rj,{autoComplete:r?"off":void 0,id:s||"tags",addonPlacement:"after",defaultValue:e,label:i,onChange:()=>{if(null!=g.current){let e=g.current.value.split(",").map(e=>e.trim()).filter(e=>e.length>0);g.current.value.trimEnd().endsWith(",")&&(e.push(""),e=[...new Set(e)]),x(e)}},placeholder:t,ref:g,children:[(0,m.jsx)(o.t0,{onClick:()=>{c(!r)},className:"select__indicator",children:(0,m.jsx)(v.cL,{})}),(0,m.jsx)(o.ZL,{children:(0,m.jsx)(o.tz,{isIn:r,onClick:e=>{"single"!==h.A.floodSettings.UITagSelectorMode&&e.nativeEvent.stopImmediatePropagation()},overlayProps:{isInteractive:!1},ref:j,triggerRef:g,children:[...new Set(["untagged",...(0,k.di)(Object.keys(H.A.taxonomy.tagCounts)).asc(),...u])].reduce((e,t)=>(""===t||e.push((0,m.jsx)(o.eb,{id:t,isSelected:u.includes(t),onClick:()=>{"untagged"===t?x([]):u.includes(t)?x(u.filter(e=>e!==t&&""!==e)):x([...u.filter(e=>""!==e),t])},children:"untagged"===t?(0,m.jsx)(d.x6,{id:"filter.untagged"}):t},t)),e),[])})})]})})})},E=(e,t)=>Object.keys(e).reduce((s,i)=>{if(i.startsWith(t)){const t=e[i];null!=t&&s.push(t)}return s},[]),B=({defaultValues:e,id:t,label:s,placeholder:i})=>{const l=(0,n.useRef)(0),[r,a]=(0,n.useState)(e??[{id:0,value:""}]);return(0,m.jsx)(o.eW,{children:r.map((e,n)=>{let d=null;return n>0&&(d=(0,m.jsx)(o.t0,{onClick:()=>{const e=r.slice();e.splice(n,1),a(e)},children:(0,m.jsx)(v._B,{})})),(0,m.jsx)(o.fh,{children:(0,m.jsxs)(o.Rj,{addonPlacement:"after",id:`${t}-${e.id}`,defaultValue:e.value,label:0===n&&s,placeholder:i,wrapperClassName:"textbox-repeater",children:[(0,m.jsx)(o.t0,{onClick:()=>{l.current+=1;const e=r.slice();e.splice(n+1,0,{id:l.current,value:""}),a(e)},children:(0,m.jsx)(v.Fx,{})}),d]})},e.id)})})},O=()=>{const e=(0,n.useRef)(null),{i18n:t}=(0,d.uB)(),[s,i]=(0,n.useState)(!1);return(0,m.jsxs)(o.lV,{className:"inverse",ref:e,children:[(0,m.jsx)($,{id:"sourcePath",label:t._("torrents.create.source.path.label")}),(0,m.jsx)(B,{id:"trackers",label:t._("torrents.create.trackers.label"),placeholder:t._("torrents.create.tracker.input.placeholder"),defaultValues:[{id:0,value:""}]}),(0,m.jsx)(o.fh,{children:(0,m.jsx)(o.Rj,{id:"name",label:t._("torrents.create.base.name.label"),placeholder:t._("torrents.create.base.name.input.placeholder")})}),(0,m.jsx)(o.fh,{children:(0,m.jsx)(o.Rj,{id:"comment",label:t._("torrents.create.comment.label"),placeholder:t._("torrents.create.comment.input.placeholder")})}),(0,m.jsx)(o.fh,{children:(0,m.jsx)(o.Rj,{id:"infoSource",label:t._("torrents.create.info.source.label"),placeholder:t._("torrents.create.info.source.input.placeholder")})}),(0,m.jsx)(o.fh,{children:(0,m.jsx)(o.Sc,{grow:!1,id:"isPrivate",children:t._("torrents.create.is.private.label")})}),(0,m.jsx)(o.fh,{children:(0,m.jsx)(F,{id:"tags",label:t._("torrents.add.tags"),placeholder:t._("torrents.create.tags.input.placeholder")})}),(0,m.jsx)(g,{onAddTorrentsClick:()=>{if(null==e.current)return;const t=e.current.getFormData();i(!0),null!=t.sourcePath&&(x.A.createTorrent({name:t.name,sourcePath:t.sourcePath,trackers:E(t,"trackers"),comment:t.comment,infoSource:t.infoSource,isPrivate:t.isPrivate||!1,start:t.start||!1,tags:null!=t.tags?t.tags.split(","):void 0}).then(()=>{_.A.setActiveModal(null)}),u({start:t.start,destination:t.sourcePath,tab:"by-creation"}))},isAddingTorrents:s})]})};var U=s(6386);const z=({initialFiles:e,onFilesChanged:t})=>{const[s,i]=(0,n.useState)(e??[]);return(0,n.useEffect)(()=>{t(s)},[s,t]),(0,m.jsxs)(o.ci,{children:[(0,m.jsx)("span",{className:"form__element__label",children:(0,m.jsx)(d.x6,{id:"torrents.add.torrents.label"})}),s.length>0?(0,m.jsx)("div",{onClick:e=>{e.stopPropagation()},role:"none",children:(0,m.jsx)("ul",{className:"dropzone__selected-files interactive-list",children:s.map((e,t)=>(0,m.jsxs)("li",{className:"dropzone__selected-files__file interactive-list__item",title:e.name,children:[(0,m.jsx)("span",{className:"interactive-list__icon",children:(0,m.jsx)(v.ZH,{})}),(0,m.jsx)("span",{className:"interactive-list__label",children:e.name}),(0,m.jsx)("button",{className:"interactive-list__icon interactive-list__icon--action interactive-list__icon--action--warning",type:"button",onClick:()=>{const e=s.slice();e.splice(t,1),i(e)},children:(0,m.jsx)(v.bm,{})})]},e.name))})}):null,(0,m.jsx)(U.Ay,{onDrop:e=>{const t=[];e.forEach(l=>{const n=new FileReader;n.onload=n=>{null!=n.target?.result&&"string"==typeof n.target.result&&t.push({name:l.name,data:n.target.result.split("base64,")[1]}),t.length===e.length&&i(s.concat(t))},n.readAsDataURL(l)})},children:({getRootProps:e,getInputProps:t,isDragActive:s})=>(0,m.jsxs)("div",{...e(),className:"form__dropzone dropzone interactive-list "+(s?"dropzone--is-dragging":""),children:[(0,m.jsx)("input",{...t()}),(0,m.jsxs)("div",{className:"dropzone__copy",children:[(0,m.jsx)("div",{className:"dropzone__icon",children:(0,m.jsx)(v.sv,{})}),(0,m.jsx)(d.x6,{id:"torrents.add.tab.file.drop"})," ",(0,m.jsx)("span",{className:"dropzone__browse-button",children:(0,m.jsx)(d.x6,{id:"torrents.add.tab.file.browse"})}),"."]})]})})]})},W=()=>{const e=(0,n.useRef)([]),t=(0,n.useRef)(null),s=(0,n.useRef)(null),[i,l]=(0,n.useState)(!1),{i18n:r}=(0,d.uB)();return(0,m.jsxs)(o.lV,{className:"inverse",ref:t,children:[(0,m.jsx)(o.fh,{children:(0,m.jsx)(z,{initialFiles:"add-torrents"===_.A.activeModal?.id&&"by-file"===_.A.activeModal?.tab&&_.A.activeModal?.files||[],onFilesChanged:t=>{e.current=t}})}),(0,m.jsx)(o.fh,{children:(0,m.jsx)(F,{label:r._("torrents.add.tags"),id:"tags",onTagSelected:e=>{if(null!=s.current){const t=h.A.floodSettings.torrentDestinations?.[e[0]];"string"==typeof t&&null!=s.current&&(s.current.value=t,s.current.dispatchEvent(new Event("input",{bubbles:!0})))}}})}),(0,m.jsx)($,{id:"destination",label:r._("torrents.add.destination.label"),ref:s,selectable:"directories",showBasePathToggle:!0,showCompletedToggle:!0,showSequentialToggle:!0}),(0,m.jsx)(g,{onAddTorrentsClick:()=>{if(null==t.current)return;const s=t.current?.getFormData();l(!0);const{destination:i,start:n,tags:r,isBasePath:a,isCompleted:d,isSequential:o}=s,c=[];if(e.current.forEach(e=>{c.push(e.data)}),0===c.length||null==i)return void l(!1);const h=null!=r?r.split(",").filter(e=>e.length>0):void 0;x.A.addTorrentsByFiles({files:c,destination:i,tags:h,isBasePath:a,isCompleted:d,isSequential:o,start:n}).then(()=>{_.A.setActiveModal(null)}),u({start:n,destination:i,tags:h,tab:"by-file"})},isAddingTorrents:i})]})};var q=s(9550);const G=()=>{const e=(0,n.useRef)(null),t=(0,n.useRef)(null),[s,i]=(0,n.useState)(!1),{i18n:l}=(0,d.uB)();return(0,m.jsxs)(o.lV,{className:"inverse",ref:e,children:[(0,m.jsx)(B,{id:"urls",label:(0,m.jsxs)("div",{children:[l._("torrents.add.torrents.label"),"function"==typeof navigator.registerProtocolHandler&&(0,m.jsx)("button",{className:(0,y.AH)({float:"right",_focus:{outline:"none",WebkitTapHighlightColor:"transparent"},_focusVisible:{outline:"dashed"}}),type:"button",onClick:()=>{"function"==typeof navigator.registerProtocolHandler&&navigator.registerProtocolHandler("magnet",`${q.A.baseURI}?action=add-urls&url=%s`)},children:(0,m.jsx)("em",{className:(0,y.AH)({fontSize:"0.8em"}),children:l._("torrents.add.tab.url.register.magnet.handler")})})]}),placeholder:l._("torrents.add.tab.url.input.placeholder"),defaultValues:"add-torrents"===_.A.activeModal?.id&&"by-url"===_.A.activeModal?.tab&&_.A.activeModal?.urls||[{id:0,value:""}]}),(0,m.jsx)(B,{id:"cookies",label:l._("torrents.add.cookies.label"),placeholder:l._("torrents.add.cookies.input.placeholder")}),(0,m.jsx)(o.fh,{children:(0,m.jsx)(F,{id:"tags",label:l._("torrents.add.tags"),onTagSelected:e=>{if(null!=t.current){const s=h.A.floodSettings.torrentDestinations?.[e[0]];"string"==typeof s&&null!=t.current&&(t.current.value=s,t.current.dispatchEvent(new Event("input",{bubbles:!0})))}}})}),(0,m.jsx)($,{id:"destination",label:l._("torrents.add.destination.label"),ref:t,selectable:"directories",showBasePathToggle:!0,showCompletedToggle:!0,showSequentialToggle:!0}),(0,m.jsx)(g,{onAddTorrentsClick:()=>{if(null==e.current)return;const t=e.current.getFormData();i(!0);const s=E(t,"urls").filter(e=>""!==e);if(0===s.length||null==t.destination)return void i(!1);const l=E(t,"cookies"),n=s[0].startsWith("http")&&s[0].split("/")[2],r=n?{[n]:l}:void 0,a=null!=t.tags?t.tags.split(",").filter(e=>e.length>0):void 0;x.A.addTorrentsByUrls({urls:s,cookies:r,destination:t.destination,isBasePath:t.isBasePath,isCompleted:t.isCompleted,isSequential:t.isSequential,start:t.start,tags:a}).then(()=>{_.A.setActiveModal(null)}),u({start:t.start,destination:t.destination,tags:a,tab:"by-url"})},isAddingTorrents:s})]})},Z=({activeTabId:e,tabs:t={},onTabChange:s})=>(0,m.jsx)("ul",{className:"modal__tabs",children:Object.keys(t).map(i=>{const l=t[i];l.id=i;const n=L()("modal__tab",{"is-active":i===e});return(0,m.jsx)("li",{className:n,children:(0,m.jsx)("button",{className:(0,y.AH)({_focus:{outline:"none",WebkitTapHighlightColor:"transparent"},_focusVisible:{outline:"dashed"}}),type:"button",onClick:()=>{s&&s(l)},children:l.label})},i)})}),Q=({alignment:e="left",size:t="medium",orientation:s="horizontal",tabsInBody:i=!1,inverse:l=!0,initialTabId:r,className:a=null,content:d,heading:o,tabs:c,actions:h})=>{const u=L()("modal__content__wrapper",`modal--align-${e}`,`modal--size-${t}`,{"modal--horizontal":"horizontal"===s,"modal--vertical":"vertical"===s,"modal--tabs-in-header":!i,"modal--tabs-in-body":i,inverse:l},a);let x=d;const _=o,g=L()("modal__header",{"has-tabs":c});let f,p,b;const[v,y]=(0,n.useState)(r??Object.keys(c||{})[0]);if(c){const e=c[v],t=L()("modal__content",e.modalContentClasses),s=e.content,l=e.props,n=(0,m.jsx)(Z,{activeTabId:v,onTabChange:e=>{null!=e.id&&y(e.id)},tabs:c},"modal-tabs");i?f=n:b=n,x=[f,(0,m.jsx)("div",{className:t,children:(0,m.jsx)(s,{...l})},"modal-content")]}return h&&(p=(0,m.jsx)("div",{className:"modal__footer",children:(0,m.jsx)(j,{actions:h})})),(0,m.jsxs)("div",{className:u,children:[(0,m.jsxs)("div",{className:g,children:[_,b]}),(0,m.jsxs)("div",{className:"modal__body",children:[x,p]})]})},J=()=>{const{i18n:e}=(0,d.uB)(),t={"by-url":{content:G,label:e._("torrents.add.tab.url.title")},"by-file":{content:W,label:e._("torrents.add.tab.file.title")},"by-creation":{content:O,label:e._("torrents.add.tab.create.title")}};return"add-torrents"!==_.A.activeModal?.id?null:(0,m.jsx)(Q,{heading:e._("torrents.add.heading"),tabs:t,initialTabId:_.A.activeModal.tab??h.A.floodSettings.UITorrentsAddTab??"by-url"})},Y=(0,r.PA)(()=>{if("confirm"!==_.A.activeModal?.id)return null;const{actions:e,content:t,heading:s}=_.A.activeModal||{};return(0,m.jsx)(Q,{actions:e,content:(0,m.jsx)("div",{className:"modal__content",children:t}),heading:s})});var K=s(1083),X=s(7813);const ee=new class{feeds=[];rules=[];items=[];constructor(){(0,X.l_)(this)}setFeeds(e){this.feeds=null!=e?[...e].sort((e,t)=>e.label.localeCompare(t.label)):[]}setRules(e){this.rules=null!=e?[...e].sort((e,t)=>e.label.localeCompare(t.label)):[]}handleFeedMonitorsFetchSuccess(e){this.setFeeds(e.feeds),this.setRules(e.rules)}handleItemsFetchSuccess(e){this.items=e}},{baseURI:te}=q.A,se={addFeed:e=>K.A.put(`${te}api/feed-monitor/feeds`,e).then(()=>se.fetchFeedMonitors()),modifyFeed:(e,t)=>K.A.patch(`${te}api/feed-monitor/feeds/${e}`,t).then(()=>se.fetchFeedMonitors()),addRule:e=>K.A.put(`${te}api/feed-monitor/rules`,e).then(()=>se.fetchFeedMonitors()),fetchFeedMonitors:()=>K.A.get(`${te}api/feed-monitor`).then(({data:e})=>{ee.handleFeedMonitorsFetchSuccess(e)},()=>{}),fetchItems:({id:e,search:t})=>K.A.get(`${te}api/feed-monitor/feeds/${e}/items`,{params:{search:t}}).then(({data:e})=>{ee.handleItemsFetchSuccess(e)},()=>{}),removeFeedMonitor:e=>K.A.delete(`${te}api/feed-monitor/${e}`).then(()=>se.fetchFeedMonitors(),()=>{})},ie=se,le=/^(?:https?|ftp):\/\/.{1,}\.{1}.{1,}/,ne=e=>null!=e&&""!==e,re=e=>{try{new RegExp(e)}catch{return!1}return!0},ae=({rule:e,isSubmitting:t,isPatternMatched:s,onCancel:i})=>{const{feeds:l}=ee,{i18n:n}=(0,d.uB)();return(0,m.jsxs)(o.eW,{children:[(0,m.jsxs)(o.fh,{children:[(0,m.jsx)(o.Rj,{id:"label",label:n._("feeds.label"),defaultValue:e.label}),(0,m.jsx)(o.l6,{disabled:!l.length,id:"feedID",label:n._("feeds.applicable.feed"),defaultID:e.feedIDs?.[0],children:0===l.length?[(0,m.jsx)(o.eb,{id:"placeholder",isPlaceholder:!0,children:(0,m.jsx)("em",{children:(0,m.jsx)(d.x6,{id:"feeds.no.feeds.available"})})},"empty")]:l.reduce((e,t)=>e.concat((0,m.jsx)(o.eb,{id:`${t._id}`,children:t.label},t._id)),[(0,m.jsx)(o.eb,{id:"placeholder",isPlaceholder:!0,children:(0,m.jsx)("em",{children:(0,m.jsx)(d.x6,{id:"feeds.select.feed"})})},"select-feed")])})]}),(0,m.jsxs)(o.fh,{children:[(0,m.jsx)(o.Rj,{id:"match",label:n._("feeds.match.pattern"),placeholder:n._("feeds.regEx"),defaultValue:e.match,width:"three-eighths"}),(0,m.jsx)(o.Rj,{id:"exclude",label:n._("feeds.exclude.pattern"),placeholder:n._("feeds.regEx"),defaultValue:e.exclude,width:"three-eighths"})]}),(0,m.jsx)(o.fh,{children:(0,m.jsx)(o.Rj,{addonPlacement:"after",id:"check",label:n._("feeds.test.match"),placeholder:n._("feeds.check"),children:s&&(0,m.jsx)(o.t0,{children:(0,m.jsx)(v.H4,{})})})}),(0,m.jsxs)(o.fh,{children:[(0,m.jsx)(o.ci,{children:(0,m.jsx)($,{id:"destination",label:n._("feeds.torrent.destination"),selectable:"directories",suggested:e.destination,showBasePathToggle:!0})}),(0,m.jsx)(F,{id:"tags",label:n._("feeds.apply.tags"),placeholder:n._("feeds.tags"),defaultValue:e.tags})]}),(0,m.jsxs)(o.fh,{align:"end",justify:"end",children:[(0,m.jsx)("br",{}),(0,m.jsx)(o.Sc,{id:"startOnLoad",defaultChecked:e.startOnLoad,matchTextboxHeight:!0,children:(0,m.jsx)(d.x6,{id:"feeds.start.on.load"})}),(0,m.jsx)(o.$n,{onClick:i,children:(0,m.jsx)(d.x6,{id:"button.cancel"})}),(0,m.jsx)(o.$n,{type:"submit",isLoading:t,children:(0,m.jsx)(d.x6,{id:"button.save.feed"})})]})]})},de=({children:e})=>(0,m.jsx)("h2",{className:"h4",children:e}),oe=(0,r.PA)(({currentRule:e,onSelect:t,onRemove:s})=>{const{rules:i}=ee;return 0===i.length?(0,m.jsx)("ul",{className:"interactive-list",children:(0,m.jsx)("li",{className:"interactive-list__item",children:(0,m.jsx)(d.x6,{id:"feeds.no.rules.defined"})})}):(0,m.jsx)("ul",{className:"interactive-list",children:i.map(i=>{const l=i.count||0;let n=null,r=null;if(i.exclude&&(n=(0,m.jsxs)("li",{className:"interactive-list__detail-list__item interactive-list__detail interactive-list__detail--tertiary",children:[(0,m.jsx)(d.x6,{id:"feeds.exclude"}),": ",i.exclude]})),i.tags&&i.tags.length>0){const e=i.tags.map(e=>(0,m.jsx)("span",{className:"tag",children:e},e));r=(0,m.jsxs)("li",{className:"interactive-list__detail-list__item interactive-list__detail interactive-list__detail--tertiary",children:[(0,m.jsx)(d.x6,{id:"feeds.tags"}),": ",e]})}return(0,m.jsxs)("li",{className:"interactive-list__item interactive-list__item--stacked-content",children:[(0,m.jsxs)("div",{className:"interactive-list__label",children:[(0,m.jsxs)("ul",{className:"interactive-list__detail-list",children:[(0,m.jsx)("li",{className:"interactive-list__detail-list__item interactive-list__detail--primary",children:i.label}),(0,m.jsx)("li",{className:"interactive-list__detail-list__item interactive-list__detail-list__item--overflow interactive-list__detail interactive-list__detail--secondary",children:(0,m.jsx)(d.x6,{id:"feeds.match.count",values:{count:l}})}),i===e&&(0,m.jsx)("li",{className:"interactive-list__detail-list__item interactive-list__detail--primary",children:"Modifying"})]}),(0,m.jsxs)("ul",{className:"interactive-list__detail-list",children:[(0,m.jsxs)("li",{className:"interactive-list__detail-list__item interactive-list__detail interactive-list__detail--tertiary",style:{maxWidth:"50%",overflow:"hidden",textOverflow:"ellipsis"},children:[(0,m.jsx)(d.x6,{id:"feeds.match"}),": ",i.match]}),(0,m.jsx)("div",{style:{width:"100%"}}),n,r]})]}),(0,m.jsx)("button",{className:"interactive-list__icon interactive-list__icon--action",type:"button",onClick:()=>t(i),children:(0,m.jsx)(v.ff,{})}),(0,m.jsx)("button",{className:"interactive-list__icon interactive-list__icon--action interactive-list__icon--action--warning",type:"button",onClick:()=>s(i),children:(0,m.jsx)(v.bm,{})})]},i._id)})})}),ce={label:"",feedIDs:[],match:"",exclude:"",tags:[],destination:"",startOnLoad:!1},he={destination:{isValid:ne,error:"feeds.validation.must.specify.destination"},feedID:{isValid:e=>ne(e)&&"placeholder"!==e,error:"feeds.validation.must.select.feed"},label:{isValid:ne,error:"feeds.validation.must.specify.label"},match:{isValid:e=>ne(e)&&re(e),error:"feeds.validation.invalid.regular.expression"},exclude:{isValid:e=>!ne(e)||re(e),error:"feeds.validation.invalid.regular.expression"}},ue=(e,t)=>he[e]?.isValid(t)?void 0:he[e]?.error,xe=()=>{const e=(0,n.useRef)(null),{i18n:t}=(0,d.uB)(),[s,i]=(0,n.useState)(null),[l,r]=(0,n.useState)({}),[a,c]=(0,n.useState)(!1),[h,u]=(0,n.useState)(!1),[x,_]=(0,n.useState)(!1),[j,g]=(0,n.useState)(!1);return(0,m.jsxs)(o.lV,{className:"inverse",onChange:({event:e,formData:t})=>{const s=e.target.name,i=t;r({...l,[s]:ue(s,i[s])}),g((()=>{const{check:e,match:t="",exclude:s=""}=i;if(ne(e)&&re(t)&&re(s)){const i=new RegExp(t,"gi").test(e),l=""!==s&&new RegExp(s,"gi").test(e);return i&&!l}return!1})()),_(!0)},onSubmit:async()=>{if(null==e.current)return;const t=e.current.getFormData(),l=Object.keys(he).reduce((e,s)=>{const i=s;return{...e,[i]:ue(i,t[i])}},{});r(l);const n=Object.keys(l).every(e=>void 0===l[e]);x&&n&&(u(!0),null!=s?._id&&await ie.removeFeedMonitor(s._id),await ie.addRule({label:t.label??ce.label,feedIDs:[t.feedID??""],field:t.field,match:t.match??ce.match,exclude:t.exclude??ce.exclude,destination:t.destination??ce.destination,tags:t.tags?.split(",")??ce.tags,startOnLoad:t.startOnLoad??ce.startOnLoad,isBasePath:t.isBasePath??!1}).then(()=>{e.current?.resetForm(),r({}),i(null),c(!1)},()=>{r({backend:"general.error.unknown"})}),u(!1))},ref:e,children:[(0,m.jsx)(de,{children:(0,m.jsx)(d.x6,{id:"feeds.existing.rules"})}),Object.keys(l).reduce((e,s)=>(null!=l[s]&&e.push((0,m.jsx)(o.fh,{children:(0,m.jsx)(o.jQ,{children:t._(l?.[s])})},`error-${s}`)),e),[]),(0,m.jsx)(o.fh,{children:(0,m.jsx)(o.ci,{children:(0,m.jsx)(oe,{currentRule:s,onSelect:e=>{i(e),c(!0)},onRemove:e=>{null!=e._id&&ie.removeFeedMonitor(e._id),e===s&&(i(null),c(!1))}})})}),a?(0,m.jsx)(ae,{rule:s??ce,isPatternMatched:j,isSubmitting:h,onCancel:()=>{i(null),c(!1)}},s?._id||"initial"):(0,m.jsxs)(o.fh,{align:"end",justify:"end",children:[(0,m.jsx)("br",{}),(0,m.jsx)(o.$n,{onClick:()=>{c(!0)},children:(0,m.jsx)(d.x6,{id:"button.new"})})]})]})},_e=({currentFeed:e,defaultFeed:t,intervalMultipliers:s,isSubmitting:i,onCancel:l})=>{const{i18n:n}=(0,d.uB)(),r=e?.interval??t.interval;let a=r,c=1;return s.forEach(e=>{const t=e.value;r%t===0&&(a=r/t,c=t)}),(0,m.jsxs)(o.eW,{children:[(0,m.jsxs)(o.fh,{children:[(0,m.jsx)(o.Rj,{id:"label",label:n._("feeds.label"),placeholder:n._("feeds.label"),defaultValue:e?.label??t.label}),(0,m.jsx)(o.Rj,{id:"interval",label:n._("feeds.select.interval"),placeholder:n._("feeds.interval"),defaultValue:a,width:"one-eighth"}),(0,m.jsx)(o.l6,{labelOffset:!0,defaultID:c,id:"intervalMultiplier",width:"one-eighth",children:s.map(e=>(0,m.jsx)(o.eb,{id:e.value,children:n._(e.message)},e.value))})]}),(0,m.jsxs)(o.fh,{children:[(0,m.jsx)(o.Rj,{id:"url",label:n._("feeds.url"),placeholder:n._("feeds.url"),defaultValue:e?.url??t?.url}),(0,m.jsx)(o.$n,{labelOffset:!0,onClick:l,children:(0,m.jsx)(d.x6,{id:"button.cancel"})}),(0,m.jsx)(o.$n,{labelOffset:!0,type:"submit",isLoading:i,children:(0,m.jsx)(d.x6,{id:"button.save.feed"})})]})]})},me=(0,r.PA)(({selectedFeedID:e})=>{const{items:t}=ee,s=[];if(e){const e={};t.forEach((t,i)=>{let{title:l}=t;const n=e[l];null==n?e[l]=2:(l=`${l} #${n}`,e[l]+=1),s.push((0,m.jsxs)("li",{className:"interactive-list__item interactive-list__item--stacked-content feed-list__feed",children:[(0,m.jsx)("div",{className:"interactive-list__label feed-list__feed-label",children:l}),(0,m.jsx)(o.Sc,{id:`${i}`})]},l))})}return(0,m.jsx)(o.fh,{children:0===s.length?(0,m.jsx)("ul",{className:"interactive-list",children:(0,m.jsx)("li",{className:"interactive-list__item",children:(0,m.jsx)("div",{className:"interactive-list__label",children:(0,m.jsx)(d.x6,{id:"feeds.no.items.matching"})})})}):(0,m.jsx)("ul",{className:"interactive-list feed-list",children:s})})}),je=(0,r.PA)(()=>{const{i18n:e}=(0,d.uB)(),t=(0,n.useRef)(null),[s,i]=(0,n.useState)(null),{feeds:l}=ee;return null!=s&&(l.some(e=>e._id===s)||i(null)),(0,m.jsxs)(o.lV,{className:"inverse",onChange:({event:e,formData:t})=>{const s=t;"checkbox"!==e.target.type&&(i(s.feedID),ie.fetchItems({id:s.feedID,search:s.search}))},onSubmit:()=>{if(null==t.current)return;const e=t.current.getFormData(),s=ee.items.filter((t,s)=>e[s]).map((e,t)=>({id:t,value:e.urls[0]}));_.A.setActiveModal({id:"add-torrents",tab:"by-url",urls:s})},ref:t,children:[(0,m.jsx)(de,{children:(0,m.jsx)(d.x6,{id:"feeds.browse.feeds"})}),(0,m.jsxs)(o.fh,{children:[(0,m.jsx)(o.l6,{disabled:!l.length,grow:!1,id:"feedID",label:e._("feeds.select.feed"),width:"three-eighths",children:l.length?l.reduce((e,t)=>null==t._id?e:e.concat((0,m.jsx)(o.eb,{id:t._id,children:t.label},t._id)),[(0,m.jsx)(o.eb,{id:"placeholder",isPlaceholder:!0,children:(0,m.jsx)("em",{children:(0,m.jsx)(d.x6,{id:"feeds.select.feed"})})},"select-feed")]):[(0,m.jsx)(o.eb,{id:"placeholder",isPlaceholder:!0,children:(0,m.jsx)("em",{children:(0,m.jsx)(d.x6,{id:"feeds.no.feeds.available"})})},"empty")]}),s&&(0,m.jsx)(o.Rj,{id:"search",label:e._("feeds.search.term"),placeholder:e._("feeds.search")}),s&&(0,m.jsx)(o.$n,{type:"submit",labelOffset:!0,children:(0,m.jsx)(d.x6,{id:"button.download"})},"button")]}),s&&(0,m.jsx)(me,{selectedFeedID:s})]})}),ge=(0,r.PA)(({currentFeed:e,intervalMultipliers:t,onSelect:s,onRemove:i})=>{const{feeds:l}=ee,{i18n:n}=(0,d.uB)();return 0===l.length?(0,m.jsx)("ul",{className:"interactive-list",children:(0,m.jsx)("li",{className:"interactive-list__item",children:(0,m.jsx)(d.x6,{id:"feeds.no.feeds.defined"})})}):(0,m.jsx)("ul",{className:"interactive-list feed-list",children:l.map(l=>{const r=l.count||0;let a=`${l.interval}`,o=t[0].message;return t.forEach(e=>{l.interval%e.value===0&&(a=""+l.interval/e.value,o=e.message)}),(0,m.jsxs)("li",{className:"interactive-list__item interactive-list__item--stacked-content feed-list__feed",children:[(0,m.jsxs)("div",{className:"interactive-list__label",children:[(0,m.jsxs)("ul",{className:"interactive-list__detail-list",children:[(0,m.jsx)("li",{className:"interactive-list__detail-list__item interactive-list__detail--primary",children:l.label}),(0,m.jsx)("li",{className:"interactive-list__detail-list__item interactive-list__detail-list__item--overflow interactive-list__detail interactive-list__detail--secondary",children:(0,m.jsx)(d.x6,{id:"feeds.match.count",values:{count:r}})}),l===e&&(0,m.jsx)("li",{className:"interactive-list__detail-list__item interactive-list__detail--primary",children:"Modifying"})]}),(0,m.jsxs)("ul",{className:"interactive-list__detail-list",children:[(0,m.jsx)("li",{className:"interactive-list__detail-list__item interactive-list__detail interactive-list__detail--tertiary",children:`${a} ${n._(o)}`}),(0,m.jsx)("li",{className:"interactive-list__detail-list__item interactive-list__detail-list__item--overflow interactive-list__detail interactive-list__detail--tertiary",children:(0,m.jsx)("a",{href:l.url,rel:"noopener noreferrer",target:"_blank",children:l.url})})]})]}),(0,m.jsx)("button",{className:"interactive-list__icon interactive-list__icon--action",type:"button",onClick:()=>s(l),children:(0,m.jsx)(v.ff,{})}),(0,m.jsx)("button",{className:"interactive-list__icon interactive-list__icon--action interactive-list__icon--action--warning",type:"button",onClick:()=>i(l),children:(0,m.jsx)(v.bm,{})})]},l._id)})})}),fe={url:{isValid:e=>null!=e&&""!==e&&null!==e.match(le),error:"feeds.validation.must.specify.valid.feed.url"},label:{isValid:ne,error:"feeds.validation.must.specify.label"},interval:{isValid:e=>{if(null===e||""===e)return!1;const t=parseInt(`${e}`,10);return!Number.isNaN(t)&&t>0},error:"feeds.validation.interval.not.positive"}},pe=(e,t)=>fe[e]?.isValid(t)?void 0:fe[e]?.error,be=[{message:"feeds.time.min",value:1},{message:"feeds.time.hr",value:60},{message:"feeds.time.day",value:1440}],ve={label:"",interval:5,url:""},ye=()=>{const e=(0,n.useRef)(null),{i18n:t}=(0,d.uB)(),[s,i]=(0,n.useState)(null),[l,r]=(0,n.useState)({}),[a,c]=(0,n.useState)(!1),[h,u]=(0,n.useState)(!1);return(0,m.jsxs)("div",{children:[(0,m.jsxs)(o.lV,{className:"inverse",onChange:({event:e,formData:t})=>{const s=e.target.name,i=t;r({...l,[s]:pe(s,i[s])})},onSubmit:async()=>{const t=e.current?.getFormData();if(null==e.current||null==t)return;u(!0);const l=Object.keys(fe).reduce((e,s)=>{const i=s;return{...e,[i]:pe(i,t[i])}},{});r(l);if(Object.keys(l).every(e=>void 0===l[e])){const l={label:t.label,url:t.url,interval:Number(t.interval)*Number(t.intervalMultiplier)};let n=!0;try{null===s?await ie.addFeed(l):null!=s?._id&&await ie.modifyFeed(s._id,l)}catch{n=!1}n?(e.current.resetForm(),r({}),i(null),c(!1)):r({backend:"general.error.unknown"})}u(!1)},ref:e,children:[(0,m.jsx)(de,{children:(0,m.jsx)(d.x6,{id:"feeds.existing.feeds"})}),Object.keys(l).reduce((e,s)=>(null!=l[s]&&e.push((0,m.jsx)(o.fh,{children:(0,m.jsx)(o.jQ,{children:t._(l?.[s])})},`error-${s}`)),e),[]),(0,m.jsx)(o.fh,{children:(0,m.jsx)(o.ci,{children:(0,m.jsx)(ge,{currentFeed:s,intervalMultipliers:be,onSelect:e=>{i(e),c(!0)},onRemove:e=>{e===s&&(a&&(r({}),c(!1)),i(null)),null!=e._id&&ie.removeFeedMonitor(e._id)}})})}),a?(0,m.jsx)(_e,{currentFeed:s,defaultFeed:ve,intervalMultipliers:be,isSubmitting:h,onCancel:()=>{r({}),c(!1),i(null)}},s?._id||"initial"):(0,m.jsxs)(o.fh,{children:[(0,m.jsx)(o.ci,{width:"auto"}),(0,m.jsx)(o.$n,{onClick:()=>{c(!0)},children:(0,m.jsx)(d.x6,{id:"button.new"})})]})]}),(0,m.jsx)(je,{})]})},ke=()=>{const{i18n:e}=(0,d.uB)();(0,n.useEffect)(()=>{ie.fetchFeedMonitors()},[]);const t={feeds:{content:ye,label:e._("feeds.tabs.feeds")},downloadRules:{content:xe,label:e._("feeds.tabs.download.rules")}};return(0,m.jsx)(Q,{heading:e._("feeds.tabs.heading"),orientation:"horizontal",size:"large",tabs:t})};var Ne=s(484);let Ae=function(e){return e[e.HTTP=1]="HTTP",e[e.UDP=2]="UDP",e[e.DHT=3]="DHT",e}({});const Se=(e,t)=>{let s=`magnet:?xt=urn:btih:${e}`;return t?.length&&t.forEach(e=>{s=`${s}&tr=${encodeURI(e)}`}),s},we=()=>{const e=(0,n.useRef)(null),t=(0,n.useRef)(null),{i18n:s}=(0,d.uB)(),[i,l]=(0,n.useState)(!1),[r,a]=(0,n.useState)(!1),[c,h]=(0,n.useState)({isLoadingTrackers:!0,magnetTrackersLink:""});(0,n.useEffect)(()=>{x.A.fetchTorrentTrackers(Ne.A.selectedTorrents[0]).then(e=>{null!=e&&h({isLoadingTrackers:!1,magnetTrackersLink:Se(Ne.A.selectedTorrents[0],e.filter(e=>e.type!==Ae.DHT).map(e=>e.url))})})},[]);const u=Se(Ne.A.selectedTorrents[0]);return(0,m.jsx)(Q,{heading:s._("torrents.generate.magnet.heading"),content:(0,m.jsx)("div",{className:"modal__content inverse",children:(0,m.jsxs)(o.lV,{children:[Ne.A.torrents[Ne.A.selectedTorrents[0]]?.isPrivate?(0,m.jsx)(o.fh,{children:(0,m.jsx)(o.jQ,{children:s._("torrents.generate.magnet.private.torrent")})}):null,(0,m.jsx)(o.fh,{children:(0,m.jsx)(o.Rj,{id:"magnet",ref:e,addonPlacement:"after",label:s._("torrents.generate.magnet.magnet"),defaultValue:u,readOnly:!0,children:(0,m.jsx)(o.t0,{onClick:()=>{"function"==typeof navigator.clipboard?.writeText?navigator.clipboard.writeText(u).then(()=>{l(!0)}):null!=e.current&&(e.current?.select(),document.execCommand("copy"),l(!0))},children:i?(0,m.jsx)(v.H4,{}):(0,m.jsx)(v.B0,{})})})}),(0,m.jsx)(o.fh,{children:c.isLoadingTrackers?(0,m.jsx)(o.Rj,{id:"loading",label:s._("torrents.generate.magnet.magnet.with.trackers"),placeholder:s._("torrents.generate.magnet.loading.trackers"),disabled:!0}):(0,m.jsx)(o.Rj,{id:"magnet-trackers",ref:t,addonPlacement:"after",label:s._("torrents.generate.magnet.magnet.with.trackers"),defaultValue:c.magnetTrackersLink,readOnly:!0,children:(0,m.jsx)(o.t0,{onClick:()=>{"function"==typeof navigator.clipboard?.writeText?navigator.clipboard.writeText(c.magnetTrackersLink).then(()=>{a(!0)}):null!=t.current&&(t.current?.select(),document.execCommand("copy"),a(!0))},children:r?(0,m.jsx)(v.H4,{}):(0,m.jsx)(v.B0,{})})})})]})}),actions:[{clickHandler:null,content:s._("button.close"),triggerDismiss:!0,type:"tertiary"}]})},Ce=e=>{let t="";for(let s=0;s<e[0].length;s+=1)for(let i=1;i<e.length;i+=1)e[0][s]!==e[i][s]&&(t=e[0].slice(0,s));for(let e=t.length-1;e>=0;e-=1)if("/"===t[e])return t.slice(0,e+1)},Te=()=>{const{i18n:e}=(0,d.uB)(),[t,s]=(0,n.useState)(!1);return(0,m.jsx)(Q,{heading:e._("torrents.move.heading"),content:(0,m.jsx)("div",{className:"modal__content",children:(0,m.jsxs)(o.lV,{className:"inverse",onSubmit:({formData:e})=>{const t=Ne.A.selectedTorrents;t.length>0&&(s(!0),x.A.moveTorrents({hashes:t,destination:e.destination,isBasePath:e.isBasePath,moveFiles:e.moveFiles,isCheckHash:e.isCheckHash}).then(()=>{_.A.setActiveModal(null),s(!1)}))},children:[(0,m.jsx)($,{id:"destination",selectable:"directories",suggested:Ce(Ne.A.selectedTorrents.map(e=>Ne.A.torrents[e].directory)),showBasePathToggle:!0}),(0,m.jsx)(j,{actions:[{checked:!0,content:e._("torrents.move.data.label"),id:"moveFiles",type:"checkbox"},{checked:!1,content:e._("torrents.move.check_hash.label"),id:"isCheckHash",type:"checkbox"},{content:e._("button.cancel"),triggerDismiss:!0,type:"tertiary"},{content:e._("torrents.move.button.set.location"),isLoading:t,submit:!0,type:"primary"}]})]})})})},Re=()=>{const{i18n:e}=(0,d.uB)(),[t,s]=(0,n.useState)(!1),{selectedTorrents:i}=Ne.A;return 0===i.length?(0,m.jsx)(Q,{heading:e._("torrents.remove"),content:(0,m.jsx)("div",{className:"modal__content inverse",children:(0,m.jsx)(o.lV,{children:(0,m.jsx)(o.fh,{children:(0,m.jsx)(d.x6,{id:"torrents.remove.error.no.torrents.selected"})})})}),actions:[{clickHandler:null,content:e._("button.ok"),triggerDismiss:!0,type:"primary"}]}):(0,m.jsx)(Q,{heading:e._("torrents.remove"),content:(0,m.jsx)("div",{className:"modal__content",children:(0,m.jsxs)(o.lV,{className:"inverse",onSubmit:({formData:e})=>{s(!0);const t=e.deleteData;x.A.deleteTorrents({hashes:Ne.A.selectedTorrents,deleteData:t}).then(()=>{s(!1),(({deleteData:e})=>{null!=e&&c.A.saveSetting("deleteTorrentData",e)})({deleteData:t}),_.A.setActiveModal(null)})},children:[(0,m.jsx)(o.fh,{children:(0,m.jsx)(d.x6,{id:"torrents.remove.are.you.sure",values:{count:i.length}})}),(0,m.jsx)(j,{actions:[{checked:h.A.floodSettings.deleteTorrentData,content:e._("torrents.remove.delete.data"),id:"deleteData",type:"checkbox"},{content:e._("button.no"),triggerDismiss:!0,type:"tertiary"},{content:e._("button.yes"),isLoading:t,submit:!0,type:"primary"}]})]})})})},De=()=>{const e=(0,n.useRef)(null),{i18n:t}=(0,d.uB)(),[s,i]=(0,n.useState)(!1);return(0,m.jsx)(Q,{heading:t._("torrents.set.tags.heading"),content:(0,m.jsx)("div",{className:"modal__content inverse",children:(0,m.jsx)(o.lV,{ref:e,children:(0,m.jsx)(o.fh,{children:(0,m.jsx)(F,{defaultValue:Ne.A.selectedTorrents.map(e=>Ne.A.torrents[e].tags)[0].slice(),id:"tags",placeholder:t._("torrents.set.tags.enter.tags")})})})}),actions:[{content:t._("button.cancel"),clickHandler:null,triggerDismiss:!0,type:"tertiary"},{content:t._("torrents.set.tags.button.set"),clickHandler:()=>{if(null==e.current)return;const{selectedTorrents:t}=Ne.A,s=e.current.getFormData(),l=s.tags?s.tags.split(",").filter(e=>!!e):[];i(!0),t?.length>0&&x.A.setTags({hashes:t,tags:l})},isLoading:s,triggerDismiss:!1,type:"primary"}]})},Me=()=>{const e=(0,n.useRef)(null),{i18n:t}=(0,d.uB)(),[s,i]=(0,n.useState)(!1),[l,r]=(0,n.useState)({isLoadingTrackers:!0,trackerURLs:[]});return(0,n.useEffect)(()=>{x.A.fetchTorrentTrackers(Ne.A.selectedTorrents[0]).then(e=>{null!=e&&r({isLoadingTrackers:!1,trackerURLs:e.filter(e=>e.type!==Ae.DHT).map(e=>e.url)})})},[]),(0,m.jsx)(Q,{heading:t._("torrents.set.trackers.heading"),content:(0,m.jsx)("div",{className:"modal__content inverse",children:(0,m.jsx)(o.lV,{ref:e,children:l.isLoadingTrackers?(0,m.jsx)(o.fh,{children:(0,m.jsx)(o.Rj,{id:"loading",placeholder:t._("torrents.set.trackers.loading.trackers"),disabled:!0})}):(0,m.jsx)(B,{id:"trackers",placeholder:t._("torrents.set.trackers.enter.tracker"),defaultValues:0===l.trackerURLs.length?void 0:l.trackerURLs.map((e,t)=>({id:t,value:e}))})})}),actions:[{clickHandler:null,content:t._("button.cancel"),triggerDismiss:!0,type:"tertiary"},{clickHandler:()=>{if(null==e.current||s||l.isLoadingTrackers)return;i(!0);const t=e.current.getFormData(),n=E(t,"trackers").filter(e=>""!==e);x.A.setTrackers({hashes:Ne.A.selectedTorrents,trackers:n}).then(()=>{i(!1),_.A.setActiveModal(null)})},content:t._("torrents.set.trackers.button.set"),isLoading:s||l.isLoadingTrackers,triggerDismiss:!1,type:"primary"}]})};var Pe=s(8334);const Ie=JSON.parse('{"rE":"0.0.0-master.01f5a4a"}'),$e="https://github.com/jesec/flood",Ve="# Flood <FloodVersion />\n\n[](https://www.npmjs.com/flood) <CommitBadge />\n\n[](https://github.com/jesec/flood/actions/workflows/build.yml) [](https://crowdin.com/project/flood) [](https://discord.gg/Z7yR5Uf)\n\nFlood is a monitoring service for various torrent clients. It's a Node.js service that communicates with your favorite torrent client and serves a decent web UI for administration. This project is based on the [original Flood project](https://github.com/Flood-UI/flood).\n\n#### Feedback\n\nIf you have a specific issue or bug, please file a [GitHub issue](https://github.com/jesec/flood/issues). Please join the [Flood Discord server](https://discord.gg/Z7yR5Uf) to discuss feature requests and implementation details.\n\n#### More Information\n\nCheck out the [Wiki](https://github.com/jesec/flood/wiki) for more information.\n".replaceAll("<FloodVersion />",Ie.rE).replaceAll("<CommitBadge />",Ie.rE.length>8?``:``),Le=()=>(0,m.jsx)(n.Suspense,{fallback:null,children:(0,m.jsx)(Pe.oz,{children:Ve})});var He=s(5767),Fe=s(7230),Ee=s(9119),Be=s(8045);const Oe=(0,r.PA)(()=>{const e=(0,n.useRef)(null),t=(0,n.useRef)(null),[s,r]=(0,n.useState)(null),[a,c]=(0,n.useState)(!1),[h,u]=(0,n.useState)(!1),{i18n:x}=(0,d.uB)();if((0,n.useEffect)(()=>{Fe.A.currentUser.isAdmin&&He.A.fetchUsers().then(()=>{c(!0)})},[]),!Fe.A.currentUser.isAdmin)return(0,m.jsxs)(o.lV,{children:[(0,m.jsx)(de,{children:(0,m.jsx)(d.x6,{id:"auth.user.accounts"})}),(0,m.jsx)(o.fh,{children:(0,m.jsx)(o.jQ,{children:(0,m.jsx)(d.x6,{id:"auth.message.not.admin"})})})]});const _=!a&&0===Fe.A.users.length,j=L()("interactive-list",{"interactive-list--loading":_});return(0,m.jsxs)(o.lV,{onSubmit:()=>{if(null==e.current||null==t.current)return;const s=e.current.getFormData();if(null==s.username||""===s.username)r("auth.error.username.empty");else if(null==s.password||""===s.password)r("auth.error.password.empty");else{u(!0);const i=t.current;if(null==i)return r("connection.settings.error.empty"),void u(!1);He.A.createUser({username:s.username,password:s.password,client:i,level:!0===s.isAdmin?Ee.h.ADMINISTRATOR:Ee.h.USER}).then(()=>{null!=e.current&&e.current.resetForm(),r(null),u(!1)},()=>{r("general.error.unknown"),u(!1)}).then(He.A.fetchUsers)}},ref:e,children:[(0,m.jsx)(de,{children:(0,m.jsx)(d.x6,{id:"auth.user.accounts"})}),(0,m.jsx)(o.fh,{children:(0,m.jsx)(o.ci,{children:(0,m.jsxs)("ul",{className:j,children:[(0,m.jsx)(l.A,{children:_&&(0,m.jsx)(i.A,{classNames:"interactive-list__loading-indicator",timeout:{enter:250,exit:250},children:(0,m.jsx)("div",{className:"interactive-list__loading-indicator",children:(0,m.jsx)(o.hg,{})},"loading-indicator")})}),Fe.A.users.slice().sort((e,t)=>e.username.localeCompare(t.username)).map(e=>{const t=e.username===Fe.A.currentUser.username;let s=null,i=null;t?s=(0,m.jsx)("span",{className:"interactive-list__label__tag tag",children:(0,m.jsx)(d.x6,{id:"auth.current.user"})}):i=(0,m.jsx)("button",{className:"interactive-list__icon interactive-list__icon--action interactive-list__icon--action--warning",type:"button",onClick:()=>He.A.deleteUser(e.username).then(He.A.fetchUsers),children:(0,m.jsx)(v.bm,{})});const l=L()("interactive-list__item",{"interactive-list__item--disabled":t});return(0,m.jsxs)("li",{className:l,children:[(0,m.jsxs)("span",{className:"interactive-list__label",children:[(0,m.jsx)("div",{className:"interactive-list__label__text",children:e.username}),s]}),i]},e.username)})]})})}),(0,m.jsx)(de,{children:(0,m.jsx)(d.x6,{id:"auth.add.user"})}),s&&(0,m.jsx)(o.fh,{children:(0,m.jsx)(o.jQ,{children:x._(s)})}),(0,m.jsxs)(o.fh,{children:[(0,m.jsx)(o.Rj,{id:"username",label:(0,m.jsx)(d.x6,{id:"auth.username"}),placeholder:x._("auth.username"),autoComplete:"username"}),(0,m.jsx)(o.Rj,{id:"password",label:(0,m.jsx)(d.x6,{id:"auth.password"}),placeholder:x._("auth.password"),autoComplete:"new-password"}),(0,m.jsx)(o.Sc,{grow:!1,id:"isAdmin",labelOffset:!0,matchTextboxHeight:!0,children:(0,m.jsx)(d.x6,{id:"auth.admin"})})]}),(0,m.jsx)(Be.A,{onSettingsChange:e=>{t.current=e}}),(0,m.jsx)("p",{}),(0,m.jsx)(o.fh,{justify:"end",children:(0,m.jsx)(o.$n,{isLoading:h,priority:"primary",type:"submit",children:(0,m.jsx)(d.x6,{id:"button.add"})})})]})}),Ue=(e,t)=>null!=e[t]?e[t]:h.A.clientSettings?.[t],ze=e=>{const t=e.target,s=t.name,{value:i,type:l,checked:n}=t;let r={};return r="checkbox"===l?{[s]:n}:{[s]:i},r},We=e=>{if(e&&0!==e.length)return e.join(", ")},qe=(e="")=>""===e?[]:e.replace(/\s/g,"").split(",").map(e=>Number(e)),Ge=({onSettingsChange:e,onClientSettingsChange:t})=>{const[s,i]=(0,n.useState)({});return(0,m.jsxs)(o.lV,{onChange:({event:l,formData:n})=>{const r=l.target;if("dropdownPresetDownload"===r.name||"dropdownPresetUpload"===r.name)return void e({speedLimits:{download:qe(n.dropdownPresetDownload),upload:qe(n.dropdownPresetUpload)}});const a={...s,...ze(l)};i(a),t(a)},children:[(0,m.jsx)(de,{children:(0,m.jsx)(d.x6,{id:"settings.bandwidth.transferrate.heading"})}),(0,m.jsx)(o.fh,{children:(0,m.jsx)(o.Rj,{defaultValue:null!=h.A.floodSettings.speedLimits?We(h.A.floodSettings.speedLimits.download):0,label:(0,m.jsx)(d.x6,{id:"settings.bandwidth.transferrate.dropdown.preset.download.label"}),id:"dropdownPresetDownload"})}),(0,m.jsx)(o.fh,{children:(0,m.jsx)(o.Rj,{defaultValue:null!=h.A.floodSettings.speedLimits?We(h.A.floodSettings.speedLimits.upload):0,label:(0,m.jsx)(d.x6,{id:"settings.bandwidth.transferrate.dropdown.preset.upload.label"}),id:"dropdownPresetUpload"})}),(0,m.jsxs)(o.fh,{children:[(0,m.jsx)(o.Rj,{defaultValue:Ue(s,"throttleGlobalDownSpeed"),label:(0,m.jsxs)("div",{children:[(0,m.jsx)(d.x6,{id:"settings.bandwidth.transferrate.global.throttle.download"})," ",(0,m.jsx)("em",{className:"unit",children:"(B/s)"})]}),id:"throttleGlobalDownSpeed"}),(0,m.jsx)(o.Rj,{defaultValue:Ue(s,"throttleGlobalUpSpeed"),label:(0,m.jsxs)("div",{children:[(0,m.jsx)(d.x6,{id:"settings.bandwidth.transferrate.global.throttle.upload"})," ",(0,m.jsx)("em",{className:"unit",children:"(B/s)"})]}),id:"throttleGlobalUpSpeed"})]}),(0,m.jsx)(de,{children:(0,m.jsx)(d.x6,{id:"settings.bandwidth.slots.heading"})}),(0,m.jsxs)(o.fh,{children:[(0,m.jsx)(o.Rj,{defaultValue:Ue(s,"throttleMaxUploads"),label:(0,m.jsx)(d.x6,{id:"settings.bandwidth.slots.upload.label"}),id:"throttleMaxUploads"}),(0,m.jsx)(o.Rj,{defaultValue:Ue(s,"throttleMaxUploadsGlobal"),label:(0,m.jsx)(d.x6,{id:"settings.bandwidth.slots.upload.global.label"}),id:"throttleMaxUploadsGlobal"})]}),(0,m.jsxs)(o.fh,{children:[(0,m.jsx)(o.Rj,{defaultValue:Ue(s,"throttleMaxDownloads"),label:(0,m.jsx)(d.x6,{id:"settings.bandwidth.slots.download.label"}),id:"throttleMaxDownloads"}),(0,m.jsx)(o.Rj,{defaultValue:Ue(s,"throttleMaxDownloadsGlobal"),label:(0,m.jsx)(d.x6,{id:"settings.bandwidth.slots.download.global.label"}),id:"throttleMaxDownloadsGlobal"})]})]})},Ze=({onClientSettingsChange:e})=>{const[t,s]=(0,n.useState)({});return(0,m.jsxs)(o.lV,{onChange:({event:i})=>{const l={...t,...ze(i)};s(l),e(l)},children:[(0,m.jsx)(de,{children:(0,m.jsx)(d.x6,{id:"settings.connectivity.incoming.heading"})}),(0,m.jsxs)(o.fh,{children:[(0,m.jsx)(o.Rj,{defaultValue:Ue(t,"networkPortRange"),id:"networkPortRange",label:(0,m.jsx)(d.x6,{id:"settings.connectivity.port.range.label"}),width:"one-quarter"}),(0,m.jsx)(o.Sc,{defaultChecked:Ue(t,"networkPortRandom"),grow:!1,id:"networkPortRandom",labelOffset:!0,matchTextboxHeight:!0,children:(0,m.jsx)(d.x6,{id:"settings.connectivity.port.randomize.label"})}),(0,m.jsx)(o.Sc,{defaultChecked:Ue(t,"networkPortOpen"),grow:!1,id:"networkPortOpen",labelOffset:!0,matchTextboxHeight:!0,children:(0,m.jsx)(d.x6,{id:"settings.connectivity.port.open.label"})})]}),(0,m.jsxs)(o.fh,{children:[(0,m.jsx)(o.Rj,{defaultValue:Ue(t,"networkLocalAddress"),id:"networkLocalAddress",label:(0,m.jsx)(d.x6,{id:"settings.connectivity.ip.hostname.label"})}),(0,m.jsx)(o.Rj,{defaultValue:Ue(t,"networkHttpMaxOpen"),id:"networkHttpMaxOpen",label:(0,m.jsx)(d.x6,{id:"settings.connectivity.max.http.connections"})})]}),(0,m.jsx)(de,{children:(0,m.jsx)(d.x6,{id:"settings.connectivity.dpd.heading"})}),(0,m.jsxs)(o.fh,{children:[(0,m.jsx)(o.Rj,{defaultValue:Ue(t,"dhtPort"),id:"dhtPort",label:(0,m.jsx)(d.x6,{id:"settings.connectivity.dht.port.label"}),width:"one-quarter"}),(0,m.jsx)(o.Sc,{defaultChecked:Ue(t,"dht"),grow:!1,id:"dht",labelOffset:!0,matchTextboxHeight:!0