2 lines
17 KiB
JavaScript
2 lines
17 KiB
JavaScript
|
|
import{r as a,p as Ze,j as e,D as d,q as Je,t as Ye,v as es,w as ss,x as ge,y as ts,z as ns,A as as,B as ls,C as is,E as rs,F as cs,G as os,H as ds}from"./index-CRR9sQ49.js";import{M as l}from"./Modal-B7V4w_St.js";import{A as ms}from"./AdminAlert-DW1IRWce.js";import{A as r}from"./AdminButton-Bd2cLTu3.js";import{A as hs}from"./AdminTable-BLiLxfnS.js";import{E as us}from"./EmptyState-C61VdEFl.js";import{P as ps}from"./PageHeader-BcjNf7GG.js";function f(n,p){return n==="/"?`/${p}`:`${n.replace(/\/$/,"")}/${p}`}function Ne(n){const p=n.replace(/\/$/,"").split("/").filter(Boolean);return p.pop(),p.length===0?"/":`/${p.join("/")}`}function be(n){return n<1024?`${n} B`:n<1024*1024?`${(n/1024).toFixed(1)} KB`:n<1024*1024*1024?`${(n/1024/1024).toFixed(1)} MB`:`${(n/1024/1024/1024).toFixed(2)} GB`}const xs=[".txt",".html",".htm",".css",".js",".json",".xml",".md",".py",".php",".sh",".conf",".env",".ini",".log",".yml",".yaml"];function vs(){const[n,p]=a.useState("/"),[W,G]=a.useState("/"),[k,Ce]=a.useState([]),[M,K]=a.useState(!0),[O,m]=a.useState(""),[H,ye]=a.useState(""),[g,N]=a.useState(()=>new Set),[h,b]=a.useState(null),[U,q]=a.useState({}),[ve,Q]=a.useState(null),[V,X]=a.useState(!1),[S,w]=a.useState(null),[Z,J]=a.useState(""),[Y,ee]=a.useState(!1),[ke,F]=a.useState(!1),[se,z]=a.useState(""),[Se,$]=a.useState(!1),[te,D]=a.useState(""),[x,B]=a.useState(null),[T,_]=a.useState(""),[we,P]=a.useState(!1),[j,E]=a.useState(null),[ne,ae]=a.useState("0644"),[le,ie]=a.useState(!1),[Fe,C]=a.useState(!1),[R,A]=a.useState("archive.zip"),[ze,L]=a.useState(!1),[I,$e]=a.useState(""),[re,ce]=a.useState(!1),[oe,de]=a.useState([]),me=a.useRef(null),c=a.useCallback(s=>{K(!0),m(""),N(new Set),Ze(s).then(t=>{p(t.path),G(t.path),Ce(t.items.sort((i,v)=>i.is_dir===v.is_dir?0:i.is_dir?-1:1)),q({})}).catch(t=>m(t.message)).finally(()=>K(!1))},[]);a.useEffect(()=>{c(n)},[]);const u=a.useMemo(()=>{const s=H.trim().toLowerCase();return s?k.filter(t=>t.name.toLowerCase().includes(s)):k},[k,H]),y=n.replace(/\/$/,"").split("/").filter(Boolean),he=y.length>0,De=s=>{N(t=>{const i=new Set(t);return i.has(s)?i.delete(s):i.add(s),i})},Be=()=>{g.size===u.length?N(new Set):N(new Set(u.map(s=>s.name)))},o=a.useMemo(()=>u.filter(s=>g.has(s.name)),[u,g]),ue=s=>{s.is_dir&&c(f(n,s.name))},_e=()=>{he&&c(Ne(n))},pe=()=>{const s=W.trim()||"/";c(s.startsWith("/")?s:`/${s}`)},xe=s=>{if(s.is_dir)return;const t=f(n,s.name);Q(s.name),Ye(t).catch(i=>m(i.message)).finally(()=>Q(null))},Pe=s=>{var i;const t=(i=s.target.files)==null?void 0:i[0];t&&(X(!0),m(""),Je(n,t).then(()=>c(n)).catch(v=>m(v.message)).finally(()=>{X(!1),s.target.value=""}))},Ee=s=>{const t=f(n,s.name);ds(t).then(i=>{w(t),J(typeof i.content=="string"?i.content:String(i.content))}).catch(i=>m(i.message))},Ie=()=>{S&&(ee(!0),rs(S,Z).then(()=>{w(null),c(n)}).catch(s=>m(s.message)).finally(()=>ee(!1)))},Me=s=>xs.some(t=>s.toLowerCase().endsWith(t)),He=s=>{s.preventDefault();const t=se.trim();t&&ns(n,t).then(()=>{F(!1),z(""),c(n)}).catch(i=>m(i.message))},Te=s=>{s.preventDefault();const t=te.trim();t&&as(n,t).then(()=>{$(!1),D(""),c(n)}).catch(i=>m(i.message))},je=()=>{if(!x||!T.trim())return;const s=T.trim();if(s===x.name){B(null);return}os(n,x.name,s).then(()=>{B(null),_(""),c(n)}).catch(t=>m(t.message))},Re=s=>{confirm(`Delete ${s.is_dir?"folder":"file"} "${s.name}"?`)&&ge(n,s.name,s.is_dir).then(()=>c(n)).catch(t=>m(t.message))},Ae=()=>{o.length!==0&&confirm(`Delete ${o.length} item(s)?`)&&Promise.all(o.map(s=>ge(n,s.name,s.is_dir))).then(()=>c(n)).catch(s=>m(s.message))},Le=()=>{o.length!==0&&b({op:"copy",entries:o.map(s=>({parent:n,name:s.name}))})},We=()=>{o.length!==0&&b({op:"cut",entries:o.map(s=>({parent:n,name:s.name}))})},Ge=()=>{if(!h||h.entries.length===0)return;const s=h.entries.map(t=>h.op==="copy"?es(t.parent,t.name,n):ss(t.parent,t.name,n));Promise.all(s).then(()=>{(h==null?void 0:h.op)==="cut"&&b(null),c(n)}).catch(t=>m(t.message))},Ke=s=>{E(s),ae(s.mode?s.mode.padStart(3,"0"):"0644"),ie(s.is_dir),P(!0)},Oe=()=>{if(!j)return;const s=f(n,j.name);ls(s,ne,le&&j.is_dir).then(()=>{P(!1),E(null),c(n)}).c
|