9 lines
33 KiB
JavaScript
9 lines
33 KiB
JavaScript
import{j as t,r as a,y as ye,E as H,a as ge,o as ve}from"./vendor-codemirror-B1SGo4xl.js";import{Y as je,ae as le,B as Y,D as Pe,a as Ee,m as ee,c as Ne,d as Se}from"./index-Bp-M7P_8.js";import{u as ie}from"./use-toast-DNZLibQY.js";import{k as O,d as Te}from"./index-BkulU9RM.js";import{c as de}from"./k8s-yaml-utils-4KZB_Bq_.js";import{w as Fe,aF as Be,v as ue,d as Ce,L as V,$ as Ye,X as I,r as Ae,ad as Re,aU as Me,an as De,ao as Oe,H as _e,m as $e,f as Le,ah as Ve,R as ze,aV as Ie,aW as Ue}from"./vendor-icons-BWk-DH7F.js";import{S as te,a as se,b as re,c as oe,d as ne}from"./select-DbhcBWnH.js";import{x as We,a as He}from"./vendor-xterm-20M9KZE1.js";import{B as Je}from"./badge-B00SZHvE.js";function Ke({onClose:e,children:s,zIndex:r=100}){return je.createPortal(t.jsx("div",{"code-path":"src/components/ui/modal-overlay.tsx:13:5",className:"fixed inset-0 overflow-y-auto bg-black/60",style:{zIndex:r},onClick:e,children:t.jsx("div",{"code-path":"src/components/ui/modal-overlay.tsx:18:7",className:"flex min-h-full items-center justify-center p-4",children:s})}),document.body)}const Ge=new Set(["kubectl.kubernetes.io/last-applied-configuration","kubectl.kubernetes.io/change-cause","kubectl.kubernetes.io/restartedAt","deployment.kubernetes.io/revision","deployment.kubernetes.io/desired-replicas","deployment.kubernetes.io/max-replicas","control-plane.alpha.kubernetes.io/leader","autoscaling.alpha.kubernetes.io/conditions","kubernetes.io/config.hash","kubeadm.kubernetes.io/etcd.advertise-client-urls","pv.kubernetes.io/bind-completed","pv.kubernetes.io/bound-by-controller"]),qe=["managedFields","resourceVersion","uid","creationTimestamp","generation","selfLink","deletionTimestamp","ownerReferences","finalizers","clusterName","generateName"],Xe=new Set(["pod-template-hash","controller-revision-hash"]),Qe=["kube-api-access-","default-token-","kube-root-ca.crt"],Ze=["/var/run/secrets/kubernetes.io/serviceaccount","/var/run/secrets/sa"],et={dnsPolicy:"ClusterFirst",restartPolicy:"Always",schedulerName:"default-scheduler",terminationGracePeriodSeconds:30,enableServiceLinks:!0,serviceAccountName:"default",automountServiceAccountToken:!0,priority:0,preemptionPolicy:"PreemptLowerPriority"},tt={progressDeadlineSeconds:600,revisionHistoryLimit:10},st={terminationMessagePath:"/dev/termination-log",terminationMessagePolicy:"File",stdin:!1,tty:!1,stdinOnce:!1},rt={sessionAffinity:"None",externalTrafficPolicy:"Cluster",internalTrafficPolicy:"Cluster",ipFamilyPolicy:"SingleStack",allocateLoadBalancerNodePorts:!0},ot=["clusterIP","clusterIPs","ipFamilies","healthCheckNodePort"];function U(e){return Array.isArray(e)?e.length===0:e&&typeof e=="object"?Object.keys(e).length===0:!1}function nt(e,s){return s===e||typeof s=="number"&&typeof e=="string"&&String(s)===e?!0:typeof s=="boolean"&&typeof e=="string"?s&&e==="true"||!s&&e==="false":!1}function J(e){if(!(!e||typeof e!="object")){for(const s of qe)delete e[s];if(e.annotations){for(const s of Object.keys(e.annotations))Ge.has(s)&&delete e.annotations[s];Object.keys(e.annotations).length===0&&delete e.annotations}if(e.labels){for(const s of Xe)delete e.labels[s];Object.keys(e.labels).length===0&&delete e.labels}}}function K(e){if(!e||typeof e!="object")return;if(Array.isArray(e)){for(let r=e.length-1;r>=0;r--)K(e[r]),U(e[r])&&e.splice(r,1);return}const s=e;for(const r of Object.keys(s)){const n=s[r];n&&typeof n=="object"&&K(n),U(n)&&delete s[r]}}function W(e,s){if(!(!e||typeof e!="object"))for(const[r,n]of Object.entries(s))r in e&&nt(e[r],n)&&delete e[r]}function ae(e){return Qe.some(s=>e.startsWith(s)||e===s)}function at(e){return Ze.some(s=>e===s||e.startsWith(`${s}/`))}function ct(e){if(!e||typeof e!="object")return;const s=e.volumes;if(Array.isArray(s)){const r=new Set(s.filter(c=>c?.name&&ae(c.name)).map(c=>c.name));e.volumes=s.filter(c=>!c?.name||!ae(c.name)),e.volumes.length===0&&delete e.volumes;const n=c=>{if(Array.isArray(c))for(const x of c)Array.isArray(x.volumeMounts)&&(x.volumeMounts=x.volumeMounts.filter(N=>!(N?.name&&r.has(N.name)||N?.mountPath&&at(String(N.mountPath)))),x.volumeMounts.length===0&&delete x.volumeMounts)};n(e.containers),n(e.initContainers),n(e.ephemeralContainers)}}function lt(e){if(!(!e||typeof e!="object")){if(W(e,st),e.imagePullPolicy){const s=String(e.image||"").split(":").pop()||"",n=!String(e.image||"").includes(":")||s==="latest"?"Always":"IfNotPresent";e.imagePullPolicy===n&&delete e.imagePullPolicy}e.resources&&U(e.resources)&&delete e.resources,e.securityContext&&U(e.securityContext)&&delete e.securityContext}}function me(e){if(!(!e||typeof e!="object")){W(e,et),"serviceAccount"in e&&delete e.serviceAccount,e.nodeName&&delete e.nodeName,ct(e);for(const s of["containers","initContainers","ephemeralContainers"]){const r=e[s];if(Array.isArray(r))for(const n of r)lt(n)}}}function it(e){if(!e?.strategy||e.strategy.type!=="RollingUpdate")return;const s=e.strategy.rollingUpdate;if(!s||typeof s!="object")return;const r=s.maxUnavailable,n=s.maxSurge;(r==="25%"||r===0||r==="0")&&(n==="25%"||n===1||n==="1")&&Object.keys(s).length<=2&&delete e.strategy}function dt(e){if(!e||typeof e!="object")return;for(const r of ot)delete e[r];W(e,rt);const s=e.type||"ClusterIP";if(Array.isArray(e.ports))for(const r of e.ports)!r||typeof r!="object"||((s==="ClusterIP"||r.nodePort===0)&&delete r.nodePort,r.protocol==="TCP"&&Object.keys(r).length===3&&delete r.protocol)}function ut(e){!e||typeof e!="object"||e.ingressClassName||delete e.ingressClassName}function mt(e){if(!e?.template||typeof e.template!="object")return;e.template.metadata&&J(e.template.metadata);const s=e.template.spec;s&&me(s)}function xt(e){const s=String(e.kind||"").toLowerCase();e.spec&&((s==="deployment"||s==="statefulset"||s==="daemonset")&&(W(e.spec,tt),s==="deployment"&&it(e.spec),mt(e.spec)),s==="service"&&dt(e.spec),s==="ingress"&&ut(e.spec),s==="pod"&&me(e.spec))}function G(e){const s=JSON.parse(JSON.stringify(e));delete s.status,J(s.metadata);const r=s.spec?.template;return r?.metadata&&J(r.metadata),xt(s),K(s),s}async function q(e){if(!e?.trim())return null;try{return JSON.parse(e)}catch{}try{const r=(await le(()=>import("./js-yaml-37NdyH6G.js"),[])).load(e);return r&&typeof r=="object"?r:null}catch{return null}}async function xe(e){return(await le(()=>import("./js-yaml-37NdyH6G.js"),[])).dump(e,{lineWidth:120,noRefs:!0,sortKeys:!1})}async function X(e){const s=G(e),r=await xe(s);return de(r)}async function pe(e){const s=await q(e);if(!s)return{manifest:null,yaml:e};const r=G(s),n=await X(r);return{manifest:r,yaml:n}}async function fe(e){return X(e)}async function he(e){const s=await q(e);return s?fe(s):de(e)}const Tt=Object.freeze(Object.defineProperty({__proto__:null,dumpManifest:xe,manifestToEditableYaml:X,parseEditableManifest:pe,parseManifest:q,prepareManifestForSave:fe,prepareYamlForSave:he,stripRuntimeFields:G},Symbol.toStringTag,{value:"Module"})),pt={deployments:{label:"Deployment",exportFolder:"deployments",readOnly:!1,visualEdit:!1},pods:{label:"Pod",exportFolder:"pods",readOnly:!0,visualEdit:!1},services:{label:"Service",exportFolder:"services",readOnly:!1,visualEdit:!0},ingresses:{label:"Ingress",exportFolder:"ingresses",readOnly:!1,visualEdit:!0}};function be(e){const s=e.replace(/\/$/,"").toLowerCase();return pt[s]??{label:s,exportFolder:s,readOnly:!1,visualEdit:!1}}function ce(e,s,r){const n=be(e);return`${s}-${n.exportFolder}-${r}.yaml`}function ft({editing:e,saving:s=!1,copied:r=!1,showRaw:n=!1,compact:c=!1,readOnly:x=!1,showRawToggle:N=!0,onCopy:b,onDownload:v,onEdit:i,onCancel:m,onSave:F,onToggleRaw:j}){const g=c?"h-7 text-xs":"h-8";return t.jsxs("div",{"code-path":"src/components/kubernetes/YamlEditorToolbar.tsx:28:5",className:"flex items-center gap-2 flex-wrap",children:[t.jsxs(Y,{"code-path":"src/components/kubernetes/YamlEditorToolbar.tsx:29:7",variant:"outline",size:"sm",className:`${g} border-slate-700 text-slate-300`,onClick:b,children:[r?t.jsx(Fe,{"code-path":"src/components/kubernetes/YamlEditorToolbar.tsx:30:19",className:"h-3 w-3 mr-1 text-emerald-400"}):t.jsx(Be,{"code-path":"src/components/kubernetes/YamlEditorToolbar.tsx:30:73",className:"h-3 w-3 mr-1"}),r?"已复制":"复制"]}),v&&t.jsxs(Y,{"code-path":"src/components/kubernetes/YamlEditorToolbar.tsx:34:9",variant:"outline",size:"sm",className:`${g} border-slate-700 text-slate-300`,onClick:v,children:[t.jsx(ue,{"code-path":"src/components/kubernetes/YamlEditorToolbar.tsx:35:11",className:"h-3 w-3 mr-1"}),"下载"]}),!x&&(e?t.jsxs(t.Fragment,{children:[t.jsx(Y,{"code-path":"src/components/kubernetes/YamlEditorToolbar.tsx:45:13",variant:"outline",size:"sm",className:`${g} border-slate-700 text-slate-300`,onClick:m,children:"取消"}),t.jsxs(Y,{"code-path":"src/components/kubernetes/YamlEditorToolbar.tsx:46:13",size:"sm",className:`${g} bg-blue-600 hover:bg-blue-700`,onClick:F,disabled:s,children:[s?t.jsx(V,{"code-path":"src/components/kubernetes/YamlEditorToolbar.tsx:47:25",className:"h-3 w-3 animate-spin mr-1"}):t.jsx(Ye,{"code-path":"src/components/kubernetes/YamlEditorToolbar.tsx:47:77",className:"h-3 w-3 mr-1"}),"保存"]})]}):t.jsxs(Y,{"code-path":"src/components/kubernetes/YamlEditorToolbar.tsx:40:11",variant:"outline",size:"sm",className:`${g} border-slate-700 text-slate-300`,onClick:i,children:[t.jsx(Ce,{"code-path":"src/components/kubernetes/YamlEditorToolbar.tsx:41:13",className:"h-3 w-3 mr-1"}),"编辑"]})),N&&j&&t.jsx("button",{"code-path":"src/components/kubernetes/YamlEditorToolbar.tsx:54:9",type:"button",onClick:j,className:"text-[11px] text-slate-500 hover:text-slate-300 underline-offset-2 hover:underline",children:n?"精简视图":"原始 YAML"})]})}const ht=H.theme({"&":{height:"100%"},".cm-scroller":{overflow:"auto"}});function bt({value:e,onChange:s,editing:r=!0,fill:n=!1,height:c="480px",className:x="",fontSize:N="13px"}){const b=a.useRef(null),[v,i]=a.useState(400);a.useEffect(()=>{if(!n||!b.current)return;const g=b.current,w=()=>i(Math.max(200,g.clientHeight)),S=new ResizeObserver(w);return S.observe(g),w(),()=>S.disconnect()},[n]);const m=a.useMemo(()=>[ye(),H.lineWrapping,ht,...r?[]:[H.editable.of(!1)]],[r]),F=n?`${v}px`:c,j=t.jsx(ge,{"code-path":"src/components/kubernetes/YamlCodeMirror.tsx:57:5",value:e,height:F,theme:ve,extensions:m,onChange:s,basicSetup:{lineNumbers:!0,foldGutter:!0,highlightActiveLine:r,highlightActiveLineGutter:r,autocompletion:r,bracketMatching:!0,closeBrackets:r,indentOnInput:r},style:{fontSize:N}});return n?t.jsx("div",{"code-path":"src/components/kubernetes/YamlCodeMirror.tsx:79:7",ref:b,className:`flex-1 min-h-0 h-full overflow-hidden rounded-lg border border-slate-700 ${x}`,children:j}):t.jsx("div",{"code-path":"src/components/kubernetes/YamlCodeMirror.tsx:86:5",className:`overflow-auto rounded-lg border border-slate-700 ${x}`,children:j})}function Ft({clusterCode:e,namespace:s,resource:r,name:n,onClose:c,onSaved:x,autoEdit:N=!1,inline:b=!1,initialYaml:v,readOnly:i}){const{toast:m}=ie(),F=be(r),j=i??F.readOnly,[g,w]=a.useState(v||""),[S,T]=a.useState(""),[A,k]=a.useState(""),[_,C]=a.useState(!v),[M,R]=a.useState(!1),[P,D]=a.useState(N&&!j),[z,d]=a.useState(!1),[B,E]=a.useState(!1),p=a.useCallback(async h=>{const{yaml:L}=await pe(h);return T(L),k(L),L},[]),u=a.useCallback(async()=>{if(v){w(v),await p(v),C(!1);return}C(!0);try{const h=await O.getResourceYaml(e,s,r,n);w(h),await p(h)}catch(h){m({title:"获取YAML失败",description:h.message,variant:"destructive"});const L=`# Error: ${h.message}`;w(L),T(L),k(L)}finally{C(!1)}},[e,s,r,n,v,p,m]);a.useEffect(()=>{u()},[u]);const o=()=>{k(S),D(!0),E(!1)},l=async()=>{D(!1),await u()},y=async()=>{R(!0);try{const h=await he(A);await O.updateResourceYaml(e,s,r,n,h),m({title:"保存成功",description:`${r}/${n} 已更新`}),D(!1),w(h),T(h),k(h),x?.()}catch(h){m({title:"保存失败",description:h?.message||String(h),variant:"destructive"})}finally{R(!1)}},$=()=>P?A:B?g:S,f=async()=>{await navigator.clipboard.writeText($()),d(!0),setTimeout(()=>d(!1),2e3)},we=()=>{Te(ce(r,s,n),$()),m({title:"已下载",description:ce(r,s,n)})},ke=P?A:B?g:S,Q=t.jsx(ft,{"code-path":"src/components/kubernetes/YamlViewer.tsx:117:5",editing:P,saving:M,copied:z,showRaw:B,compact:b,readOnly:j,onCopy:f,onDownload:we,onEdit:o,onCancel:l,onSave:y,onToggleRaw:()=>E(h=>!h)}),Z=_?t.jsx("div",{"code-path":"src/components/kubernetes/YamlViewer.tsx:134:5",className:"flex items-center justify-center h-full min-h-[200px]",children:t.jsx(V,{"code-path":"src/components/kubernetes/YamlViewer.tsx:135:7",className:"h-6 w-6 animate-spin text-slate-500"})}):t.jsx(bt,{"code-path":"src/components/kubernetes/YamlViewer.tsx:138:5",value:ke,editing:P,fill:!0,fontSize:b?"12px":"13px",onChange:h=>P&&k(h)});return b?t.jsxs("div",{"code-path":"src/components/kubernetes/YamlViewer.tsx:149:7",className:"flex flex-col gap-3 min-h-[400px] h-[calc(100vh-220px)] max-h-[720px]",children:[t.jsxs("div",{"code-path":"src/components/kubernetes/YamlViewer.tsx:150:9",className:"flex items-center justify-between gap-3 flex-wrap shrink-0",children:[t.jsxs("p",{"code-path":"src/components/kubernetes/YamlViewer.tsx:151:11",className:"text-xs text-slate-500",children:[t.jsxs("code",{"code-path":"src/components/kubernetes/YamlViewer.tsx:152:13",className:"text-slate-400",children:[r,"/",n]})," · ",s]}),Q]}),t.jsx("div",{"code-path":"src/components/kubernetes/YamlViewer.tsx:156:9",className:"flex-1 min-h-0 flex flex-col overflow-hidden",children:Z})]}):t.jsx(Ke,{"code-path":"src/components/kubernetes/YamlViewer.tsx:162:5",onClose:c,children:t.jsxs("div",{"code-path":"src/components/kubernetes/YamlViewer.tsx:163:7",className:"bg-slate-900 border border-slate-700 rounded-xl w-[92vw] max-w-5xl h-[85vh] flex flex-col shadow-2xl",onClick:h=>h.stopPropagation(),children:[t.jsxs("div",{"code-path":"src/components/kubernetes/YamlViewer.tsx:167:9",className:"flex items-center justify-between p-4 border-b border-slate-700 gap-3 shrink-0",children:[t.jsxs("div",{"code-path":"src/components/kubernetes/YamlViewer.tsx:168:11",className:"min-w-0",children:[t.jsxs("h2",{"code-path":"src/components/kubernetes/YamlViewer.tsx:169:13",className:"text-lg font-bold text-slate-100 truncate",children:[F.label," YAML — ",n,j&&t.jsx("span",{"code-path":"src/components/kubernetes/YamlViewer.tsx:171:28",className:"ml-2 text-xs font-normal text-slate-500",children:"只读"})]}),t.jsxs("p",{"code-path":"src/components/kubernetes/YamlViewer.tsx:173:13",className:"text-xs text-slate-500",children:[s," · ",e]})]}),t.jsxs("div",{"code-path":"src/components/kubernetes/YamlViewer.tsx:175:11",className:"flex items-center gap-2 shrink-0",children:[Q,t.jsx(Y,{"code-path":"src/components/kubernetes/YamlViewer.tsx:177:13",variant:"ghost",size:"icon",className:"h-8 w-8 text-slate-400",onClick:c,children:t.jsx(I,{"code-path":"src/components/kubernetes/YamlViewer.tsx:177:102",className:"h-4 w-4"})})]})]}),t.jsx("div",{"code-path":"src/components/kubernetes/YamlViewer.tsx:180:9",className:"flex-1 min-h-0 flex flex-col overflow-hidden p-4",children:Z})]})})}const wt=[{value:"sh",label:"/bin/sh"},{value:"bash",label:"/bin/bash"}];function Bt({open:e,onOpenChange:s,clusterId:r,namespace:n,podName:c,containers:x=[],initialContainer:N}){const{toast:b}=ie(),v=a.useRef(null),i=a.useRef(null),m=a.useRef(null),F=a.useRef(null),j=a.useRef(!1),g=a.useRef(!1),[w,S]=a.useState("idle"),[T,A]=a.useState(!1),[k,_]=a.useState(N||x[0]||""),[C,M]=a.useState("sh");a.useEffect(()=>{e||(A(!1),j.current=!1)},[e]),a.useEffect(()=>{e&&!k&&x.length>0&&_(N||x[0])},[e,x,N,k]);const R=a.useCallback(()=>{if(!i.current){console.error("[PodExec:connect] ABORT: termRef.current is null");return}const d=i.current;if(m.current){try{m.current.close()}catch{}m.current=null}S("connecting"),d.clear(),d.writeln(`\x1B[36m[正在连接 ${c}${k?"/"+k:""} shell=${C} ...]\x1B[0m`);const B=O.buildPodExecWsUrl(r,n,c,k||void 0,C),E=new WebSocket(B);m.current=E,E.onopen=()=>{S("connected"),d.reset();try{const{cols:u,rows:o}=d;E.send(JSON.stringify({status:1,cols:u,rows:o}))}catch(u){console.error("[PodExec:connect] resize error:",u)}const p=()=>{try{d.focus()}catch{}};p(),setTimeout(p,100),setTimeout(p,300)},E.onmessage=p=>{try{const u=JSON.parse(p.data);if(u.status===0&&typeof u.data=="string")d.write(u.data);else if(u.status===2||u.error){const o=u.data||u.message||u.error||"执行错误";if(o.includes("not found")&&C==="bash"){d.writeln(`\r
|
|
\x1B[33m⚠ bash 不可用,请切换 /bin/sh 后重连。\x1B[0m`),g.current=!0;return}d.write(o.includes("\x1B")?o:`\r
|
|
\x1B[31m${o}\x1B[0m\r
|
|
`)}}catch{typeof p.data=="string"&&d.write(p.data)}},E.onclose=p=>{S(u=>u==="error"?u:"closed"),g.current||d.write(`\r
|
|
\x1B[33m[连接已关闭]\x1B[0m\r
|
|
`)},E.onerror=p=>{console.error("[PodExec:connect] WS error event fired, readyState=",E.readyState,"type=",p.type),S("error"),d.write(`\r
|
|
\x1B[31m[连接发生错误]\x1B[0m\r
|
|
`)}},[r,n,c,k,C]);a.useEffect(()=>{if(!e)return;if(!r){console.error("[PodExec:initEffect] ABORT: clusterId is falsy:",r);return}if(!c){console.error("[PodExec:initEffect] ABORT: podName is falsy:",c);return}let d=!1,B=0;const E=performance.now(),p=()=>{if(d)return;const u=v.current;if(!u){B++,B<20?requestAnimationFrame(p):console.error("[PodExec:tryInit] FAILED: containerRef still null after 20 retries (",Math.round(performance.now()-E),"ms)");return}const o=new We.Terminal({cursorBlink:!0,fontSize:14,fontFamily:'Menlo, Monaco, "Courier New", monospace',allowProposedApi:!0,scrollback:5e3,theme:{background:"#0f172a",foreground:"#e2e8f0",cursor:"#38bdf8",selectionBackground:"#1e40af",black:"#1e293b",red:"#ef4444",green:"#10b981",yellow:"#f59e0b",blue:"#3b82f6",magenta:"#a855f7",cyan:"#06b6d4",white:"#e2e8f0",brightBlack:"#475569",brightRed:"#f87171",brightGreen:"#34d399",brightYellow:"#fbbf24",brightBlue:"#60a5fa",brightMagenta:"#c084fc",brightCyan:"#22d3ee",brightWhite:"#f8fafc"}}),l=new He.FitAddon;o.loadAddon(l),i.current=o,F.current=l,o.onData(y=>{m.current&&m.current.readyState===WebSocket.OPEN?m.current.send(JSON.stringify({status:0,data:y})):console.warn("[PodExec:term] TX dropped — WS not open, readyState=",m.current?.readyState)}),o.open(u),requestAnimationFrame(()=>{try{l.fit()}catch{}}),j.current=!0,R()};return requestAnimationFrame(p),()=>{d=!0}},[e,r,c]),a.useEffect(()=>{if(!e){try{m.current?.close()}catch{}try{i.current?.dispose()}catch{}i.current=null,m.current=null,F.current=null,j.current=!1,S("idle")}},[e]),a.useEffect(()=>{e&&i.current&&j.current&&R()},[k,C]),a.useEffect(()=>{if(!e)return;const d=v.current;if(!d)return;let B;const E=new ResizeObserver(()=>{clearTimeout(B),B=setTimeout(()=>{if(F.current&&i.current)try{F.current.fit(),i.current.focus();const{cols:p,rows:u}=i.current;m.current?.readyState===WebSocket.OPEN&&m.current.send(JSON.stringify({status:1,cols:p,rows:u}))}catch{}},60)});return E.observe(d),()=>{clearTimeout(B),E.disconnect()}},[e,T]);const P=w==="connected"?"bg-emerald-400":w==="error"?"bg-red-400":w==="closed"?"bg-slate-500":"bg-amber-400",D=w==="connected"?"已连接":w==="connecting"?"连接中":w==="error"?"连接错误":w==="closed"?"已断开":"空闲",z=a.useCallback(()=>{try{i.current?.focus()}catch{}},[]);return t.jsx(Pe,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:279:5",open:e,onOpenChange:s,children:t.jsxs(Ee,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:280:7",showCloseButton:!1,className:ee("bg-[var(--dg-bg-secondary)] border-[var(--dg-border)] p-0 gap-0","!duration-0 !transition-none",T?"!max-w-none !w-screen !h-screen !rounded-none !translate-x-0 !translate-y-0 !left-0 !top-0":""),style:T?{maxWidth:"100vw",width:"100vw",height:"100vh"}:{maxWidth:"960px",width:"92vw"},children:[t.jsxs(Ne,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:289:9",className:"sr-only",children:["exec — ",c]}),t.jsx(Se,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:290:9",className:"sr-only",children:"进入 Pod 容器执行命令"}),t.jsxs("div",{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:293:9",className:"flex items-center justify-between gap-2 px-4 py-2 border-b border-[var(--dg-border)] flex-wrap",children:[t.jsxs("div",{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:294:11",className:"flex items-center gap-2 text-sm min-w-0",children:[t.jsx("div",{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:295:13",className:ee("w-2 h-2 rounded-full shrink-0",P),title:D}),t.jsx(Ae,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:296:13",className:"h-4 w-4 text-blue-400 shrink-0"}),t.jsxs("span",{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:297:13",className:"text-[var(--dg-text-primary)] font-medium truncate",children:["exec — ",c]}),w==="connecting"&&t.jsx(V,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:298:44",className:"h-3 w-3 animate-spin text-[var(--dg-text-muted)]"}),t.jsx("span",{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:299:13",className:"text-xs text-[var(--dg-text-muted)]",children:D})]}),t.jsxs("div",{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:301:11",className:"flex items-center gap-2",children:[x.length>0&&t.jsxs(te,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:303:15",value:k,onValueChange:_,children:[t.jsxs(se,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:304:17",className:"h-8 w-[150px] text-xs bg-[var(--dg-bg-hover)] border-[var(--dg-border)]",children:[t.jsx(Re,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:305:19",className:"h-3 w-3 mr-1 text-[var(--dg-text-muted)]"}),t.jsx(re,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:306:19",placeholder:"容器"})]}),t.jsx(oe,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:308:17",children:x.map(d=>t.jsx(ne,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:308:55",value:d,children:d},d))})]}),t.jsxs(te,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:311:13",value:C,onValueChange:M,children:[t.jsx(se,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:312:15",className:"h-8 w-[110px] text-xs bg-[var(--dg-bg-hover)] border-[var(--dg-border)]",children:t.jsx(re,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:313:17"})}),t.jsx(oe,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:315:15",children:wt.map(d=>t.jsx(ne,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:315:47",value:d.value,children:d.label},d.value))})]}),t.jsx(Y,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:317:13",variant:"ghost",size:"sm",className:"h-8 px-2 text-[var(--dg-text-secondary)] hover:text-[var(--dg-text-primary)]",onClick:()=>{R(),b({title:"正在重连…"})},title:"重连",children:t.jsx(Me,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:319:15",className:"h-3.5 w-3.5"})}),t.jsx("button",{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:321:13",onClick:()=>A(!T),className:"p-1.5 rounded hover:bg-[var(--dg-bg-hover)] text-[var(--dg-text-secondary)]",title:T?"退出全屏":"全屏",children:T?t.jsx(De,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:322:29",className:"h-4 w-4"}):t.jsx(Oe,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:322:65",className:"h-4 w-4"})}),t.jsx("button",{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:324:13",onClick:()=>s(!1),className:"p-1.5 rounded hover:bg-[var(--dg-bg-hover)] text-[var(--dg-text-secondary)]",title:"关闭",children:t.jsx(I,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:325:15",className:"h-4 w-4"})})]})]}),t.jsx("div",{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:331:9",ref:v,className:"bg-[#0f172a] cursor-text",style:{height:T?"calc(100vh - 49px)":"480px"},onClick:z})]})})}function Ct({open:e,onOpenChange:s,clusterCode:r,namespace:n,podName:c,containers:x=[],initialContainer:N}){const[b,v]=a.useState(N||x[0]||""),[i,m]=a.useState("/"),[F,j]=a.useState([]),[g,w]=a.useState(!1),[S,T]=a.useState(""),[A,k]=a.useState(null),[_,C]=a.useState(!1),M=a.useRef(null),R=a.useRef(!1),P=a.useCallback(async o=>{w(!0),T(""),k(null);try{const l=await O.listPodFiles(r,n,c,o,b||void 0),$=(l?.entries||l?.files||l?.data?.entries||l?.data?.files||(Array.isArray(l)?l:[])).map(f=>({name:f.name??f.Name??"",isDir:!!(f.isDir??f.is_dir??f.IsDir??f.dir??f.directory),size:typeof f.size=="number"?f.size:f.Size?Number(f.Size):void 0,modTime:f.modTime??f.mod_time??f.ModTime??f.mtime??f.modified})).filter(f=>f.name&&f.name!==".");j($),m(o)}catch(l){T(l.message||"加载文件列表失败"),j([])}finally{w(!1)}},[r,n,c,b]);a.useEffect(()=>{e?(async()=>{if(R.current){P(i);return}w(!0);try{const l=await O.execPod(r,n,c,["pwd"],b||void 0),y=(l?.stdout||l?.data?.stdout||"").trim(),$=y&&y.startsWith("/")?y:"/";R.current=!0,m($),P($)}catch{R.current=!0,P("/")}})():R.current=!1},[e,b]);const D=o=>{if(o.isDir){const l=i==="/"?`/${o.name}`:`${i}/${o.name}`;P(l)}else z(o.name)},z=async o=>{const l=i==="/"?`/${o}`:`${i}/${o}`;try{const y=await O.readPodFileText(r,n,c,l,b||void 0);k({file:o,content:y})}catch(y){k({file:o,content:`读取失败: ${y.message}`})}},d=o=>{const l=i==="/"?`/${o}`:`${i}/${o}`,y=O.buildPodFileDownloadUrl(r,n,c,l,b||void 0);window.open(y,"_blank")},B=async o=>{const l=o.target.files?.[0];if(l){C(!0);try{await O.uploadPodFile(r,n,c,i,l,b||void 0),P(i)}catch(y){T(`上传失败: ${y.message}`)}finally{C(!1),M.current&&(M.current.value="")}}},E=()=>{if(i==="/")return;const o=i.split("/").filter(Boolean);o.pop(),P(o.length===0?"/":`/${o.join("/")}`)},p=o=>o==null?"-":o<1024?`${o} B`:o<1024*1024?`${(o/1024).toFixed(1)} KB`:`${(o/(1024*1024)).toFixed(1)} MB`,u=i.split("/").filter(Boolean);return e?t.jsx("div",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:163:5",className:"fixed inset-0 z-50 flex items-center justify-center bg-black/70",onClick:()=>s(!1),children:t.jsxs("div",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:164:7",className:"bg-slate-900 border border-slate-700 rounded-xl w-[90vw] max-w-5xl h-[80vh] flex flex-col shadow-2xl",onClick:o=>o.stopPropagation(),children:[t.jsxs("div",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:169:9",className:"flex items-center justify-between p-3 border-b border-slate-700 shrink-0",children:[t.jsxs("div",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:170:11",className:"flex items-center gap-2",children:[t.jsx(_e,{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:171:13",className:"h-4 w-4 text-amber-400"}),t.jsxs("span",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:172:13",className:"text-sm font-semibold text-slate-200",children:["文件浏览器: ",c]}),t.jsx(Je,{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:173:13",variant:"outline",className:"border-slate-700 text-slate-400 text-[10px]",children:n})]}),t.jsxs("div",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:175:11",className:"flex items-center gap-2",children:[x.length>0&&t.jsx("select",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:177:15",value:b,onChange:o=>{v(o.target.value)},className:"bg-slate-800 border border-slate-700 rounded text-xs text-slate-300 px-2 py-1",children:x.map(o=>t.jsx("option",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:182:40",value:o,children:o},o))}),t.jsx(Y,{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:185:13",variant:"ghost",size:"icon",className:"h-7 w-7 text-slate-400",onClick:()=>s(!1),children:t.jsx(I,{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:186:15",className:"h-4 w-4"})})]})]}),t.jsxs("div",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:192:9",className:"flex items-center justify-between p-2 border-b border-slate-800 shrink-0",children:[t.jsxs("div",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:193:11",className:"flex items-center gap-1 text-xs text-slate-400",children:[t.jsx(Y,{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:194:13",variant:"ghost",size:"icon",className:"h-6 w-6 text-slate-500",onClick:E,disabled:i==="/",children:t.jsx($e,{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:195:15",className:"h-3.5 w-3.5"})}),t.jsx("button",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:197:13",className:"hover:text-slate-200",onClick:()=>P("/"),children:"root"}),u.map((o,l)=>{const y=`/${u.slice(0,l+1).join("/")}`;return t.jsxs("span",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:201:17",className:"flex items-center gap-1",children:[t.jsx(Le,{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:202:19",className:"h-3 w-3"}),t.jsx("button",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:203:19",className:"hover:text-slate-200",onClick:()=>P(y),children:o})]},y)})]}),t.jsxs("div",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:208:11",className:"flex items-center gap-2",children:[t.jsx("input",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:209:13",type:"file",ref:M,className:"hidden",onChange:B}),t.jsxs(Y,{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:210:13",size:"sm",variant:"outline",className:"h-7 border-slate-700 text-slate-300 text-xs",onClick:()=>M.current?.click(),disabled:_,children:[_?t.jsx(V,{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:211:28",className:"h-3 w-3 animate-spin mr-1"}):t.jsx(Ve,{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:211:80",className:"h-3 w-3 mr-1"}),"上传"]}),t.jsx(Y,{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:213:13",size:"sm",variant:"outline",className:"h-7 border-slate-700 text-slate-300 text-xs",onClick:()=>P(i),disabled:g,children:g?t.jsx(V,{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:214:26",className:"h-3 w-3 animate-spin"}):t.jsx(ze,{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:214:73",className:"h-3 w-3"})})]})]}),t.jsxs("div",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:220:9",className:"flex-1 overflow-hidden flex",children:[t.jsxs("div",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:222:11",className:`${A?"w-1/2":"w-full"} overflow-auto p-2 border-r border-slate-800`,children:[S&&t.jsx("p",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:223:23",className:"text-xs text-red-400 p-2",children:S}),g?t.jsx("div",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:225:15",className:"flex items-center justify-center h-32",children:t.jsx(V,{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:225:70",className:"h-5 w-5 animate-spin text-slate-500"})}):F.length===0?t.jsx("p",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:227:15",className:"text-xs text-slate-500 p-4 text-center",children:"空目录"}):t.jsx("div",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:229:15",className:"space-y-0.5",children:F.sort((o,l)=>o.isDir===l.isDir?o.name.localeCompare(l.name):o.isDir?-1:1).map(o=>t.jsxs("div",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:231:19",className:"flex items-center gap-2 px-2 py-1.5 rounded hover:bg-slate-800/50 cursor-pointer group",onClick:()=>D(o),children:[o.isDir?t.jsx(Ie,{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:237:23",className:"h-4 w-4 text-blue-400 shrink-0"}):t.jsx(Ue,{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:239:23",className:"h-4 w-4 text-slate-500 shrink-0"}),t.jsx("span",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:241:21",className:`text-xs truncate ${o.isDir?"text-blue-300":"text-slate-300"}`,children:o.name}),!o.isDir&&t.jsx("span",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:245:23",className:"text-[10px] text-slate-600 ml-auto shrink-0",children:p(o.size)}),!o.isDir&&t.jsx(Y,{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:248:23",variant:"ghost",size:"icon",className:"h-5 w-5 opacity-0 group-hover:opacity-100 text-slate-400 hover:text-emerald-400 shrink-0",onClick:l=>{l.stopPropagation(),d(o.name)},title:"下载",children:t.jsx(ue,{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:253:25",className:"h-3 w-3"})})]},o.name))})]}),A&&t.jsxs("div",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:264:13",className:"w-1/2 flex flex-col overflow-hidden",children:[t.jsxs("div",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:265:15",className:"flex items-center justify-between p-2 border-b border-slate-800 shrink-0",children:[t.jsx("span",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:266:17",className:"text-xs text-slate-300 font-mono",children:A.file}),t.jsx(Y,{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:267:17",variant:"ghost",size:"icon",className:"h-6 w-6 text-slate-400",onClick:()=>k(null),children:t.jsx(I,{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:268:19",className:"h-3.5 w-3.5"})})]}),t.jsx("div",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:271:15",className:"flex-1 overflow-auto p-3",children:t.jsx("pre",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:272:17",className:"text-xs text-slate-300 font-mono whitespace-pre-wrap break-all bg-slate-950 rounded p-3",children:A.content||"(空文件)"})})]})]})]})}):null}export{Ke as M,Bt as P,Ft as Y,Ct as a,bt as b,pe as c,ft as d,q as e,he as f,be as g,xe as h,Tt as k,fe as p,ce as y};
|