Files
yakpanel-core/YakPanel-server/frontend/dist/assets/FilesPage-oDxR4Lhi.js

2 lines
18 KiB
JavaScript
Raw Normal View History

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