- 新增 log_datasource.go / log_proxy.go / user_api_token.go 后端控制器 - 新增 log_datasource.go model - 新增 monitor/log-center.ts API 模块 - 新增 LogCenter 前端组件及页面 - 重构 deployment 相关组件 (HPDA/UpdateImageModal/bundle-yaml 等) - 新增 ResetPasswordDialog / code-snippet-block / copy-button 等 UI 组件 - 重构多个 k8s 相关组件 (TopologyView/ResourceVisualEditor/PodFileBrowser 等) - 更新多个 API 和工具函数 (auth.ts/monitor/index.ts/request.ts 等) - 更新静态资源 (index.html + 新 JS/CSS bundle) - 删除废弃静态资源文件
14 lines
33 KiB
JavaScript
14 lines
33 KiB
JavaScript
import{j as t,r as a,y as Pe,E as J,a as Ee,o as Ne}from"./vendor-codemirror-B1SGo4xl.js";import{$ as Se,ah as ue,B as Y,D as Te,a as Fe,m as re,c as Be,d as Ce}from"./index-lgmWPQDG.js";import{u as me}from"./use-toast-DNZLibQY.js";import{k as O,d as Ye}from"./index-BW7A0O1o.js";import{c as xe}from"./k8s-yaml-utils-4KZB_Bq_.js";import{w as Ae,az as Re,v as pe,d as Me,L as z,$ as De,X as I,r as Oe,ad as $e,am as _e,at as Le,au as Ve,H as ze,m as Ie,f as Ue,ah as We,R as He,aX as Je,aY as Ke}from"./vendor-icons-BlY7QrxS.js";import{S as oe,a as ne,b as ae,c as ce,d as le}from"./select-Bv_WioDg.js";import{x as Ge,a as Xe}from"./vendor-xterm-20M9KZE1.js";import{B as qe}from"./badge-Ca5YHtna.js";function Qe({onClose:e,children:s,zIndex:r=100}){return Se.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 Ze=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"]),et=["managedFields","resourceVersion","uid","creationTimestamp","generation","selfLink","deletionTimestamp","ownerReferences","finalizers","clusterName","generateName"],tt=new Set(["pod-template-hash","controller-revision-hash"]),st=["kube-api-access-","default-token-","kube-root-ca.crt"],rt=["/var/run/secrets/kubernetes.io/serviceaccount","/var/run/secrets/sa"],ot={dnsPolicy:"ClusterFirst",restartPolicy:"Always",schedulerName:"default-scheduler",terminationGracePeriodSeconds:30,enableServiceLinks:!0,serviceAccountName:"default",automountServiceAccountToken:!0,priority:0,preemptionPolicy:"PreemptLowerPriority"},nt={progressDeadlineSeconds:600,revisionHistoryLimit:10},at={terminationMessagePath:"/dev/termination-log",terminationMessagePolicy:"File",stdin:!1,tty:!1,stdinOnce:!1},ct={sessionAffinity:"None",externalTrafficPolicy:"Cluster",internalTrafficPolicy:"Cluster",ipFamilyPolicy:"SingleStack",allocateLoadBalancerNodePorts:!0},lt=["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 it(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 K(e){if(!(!e||typeof e!="object")){for(const s of et)delete e[s];if(e.annotations){for(const s of Object.keys(e.annotations))Ze.has(s)&&delete e.annotations[s];Object.keys(e.annotations).length===0&&delete e.annotations}if(e.labels){for(const s of tt)delete e.labels[s];Object.keys(e.labels).length===0&&delete e.labels}}}function G(e){if(!e||typeof e!="object")return;if(Array.isArray(e)){for(let r=e.length-1;r>=0;r--)G(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"&&G(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&&it(e[r],n)&&delete e[r]}function ie(e){return st.some(s=>e.startsWith(s)||e===s)}function dt(e){return rt.some(s=>e===s||e.startsWith(`${s}/`))}function ut(e){if(!e||typeof e!="object")return;const s=e.volumes;if(Array.isArray(s)){const r=new Set(s.filter(c=>c?.name&&ie(c.name)).map(c=>c.name));e.volumes=s.filter(c=>!c?.name||!ie(c.name)),e.volumes.length===0&&delete e.volumes;const n=c=>{if(Array.isArray(c))for(const m of c)Array.isArray(m.volumeMounts)&&(m.volumeMounts=m.volumeMounts.filter(j=>!(j?.name&&r.has(j.name)||j?.mountPath&&dt(String(j.mountPath)))),m.volumeMounts.length===0&&delete m.volumeMounts)};n(e.containers),n(e.initContainers),n(e.ephemeralContainers)}}function mt(e){if(!(!e||typeof e!="object")){if(W(e,at),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 fe(e){if(!(!e||typeof e!="object")){W(e,ot),"serviceAccount"in e&&delete e.serviceAccount,e.nodeName&&delete e.nodeName,ut(e);for(const s of["containers","initContainers","ephemeralContainers"]){const r=e[s];if(Array.isArray(r))for(const n of r)mt(n)}}}function xt(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 pt(e){if(!e||typeof e!="object")return;for(const r of lt)delete e[r];W(e,ct);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 ft(e){!e||typeof e!="object"||e.ingressClassName||delete e.ingressClassName}function ht(e){if(!e?.template||typeof e.template!="object")return;e.template.metadata&&K(e.template.metadata);const s=e.template.spec;s&&fe(s)}function bt(e){const s=String(e.kind||"").toLowerCase();e.spec&&((s==="deployment"||s==="statefulset"||s==="daemonset")&&(W(e.spec,nt),s==="deployment"&&xt(e.spec),ht(e.spec)),s==="service"&&pt(e.spec),s==="ingress"&&ft(e.spec),s==="pod"&&fe(e.spec))}function q(e){const s=JSON.parse(JSON.stringify(e));delete s.status,K(s.metadata);const r=s.spec?.template;return r?.metadata&&K(r.metadata),bt(s),G(s),s}async function wt(e){return(await H(e))[0]||null}async function H(e){if(!e?.trim())return[];try{const s=JSON.parse(e);return s&&typeof s=="object"?[s]:[]}catch{}try{return(await ue(()=>import("./js-yaml-37NdyH6G.js"),[])).loadAll(e).filter(n=>!!n&&typeof n=="object")}catch{return[]}}async function he(e){return(await ue(()=>import("./js-yaml-37NdyH6G.js"),[])).dump(e,{lineWidth:120,noRefs:!0,sortKeys:!1})}async function Q(e){const s=q(e),r=await he(s);return xe(r)}async function Z(e){const s=await H(e);if(s.length===0)return{manifests:[],yaml:e};const r=s.map(c=>q(c)),n=[];for(const c of r)n.push(await Q(c));return{manifests:r,yaml:n.join(`
|
|
---
|
|
`)}}async function be(e){const{manifests:s,yaml:r}=await Z(e);return{manifest:s[0]||null,yaml:r}}async function X(e){return Q(e)}async function we(e){const s=await H(e);if(s.length===0)return xe(e);if(s.length===1)return X(s[0]);const r=[];for(const n of s)r.push(await X(n));return r.join(`
|
|
---
|
|
`)}const At=Object.freeze(Object.defineProperty({__proto__:null,dumpManifest:he,manifestToEditableYaml:Q,parseEditableManifest:be,parseEditableManifests:Z,parseManifest:wt,parseManifests:H,prepareManifestForSave:X,prepareYamlForSave:we,stripRuntimeFields:q},Symbol.toStringTag,{value:"Module"})),kt={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 ke(e){const s=e.replace(/\/$/,"").toLowerCase();return kt[s]??{label:s,exportFolder:s,readOnly:!1,visualEdit:!1}}function de(e,s,r){const n=ke(e);return`${s}-${n.exportFolder}-${r}.yaml`}function yt({editing:e,saving:s=!1,copied:r=!1,showRaw:n=!1,compact:c=!1,readOnly:m=!1,showRawToggle:j=!0,onCopy:w,onDownload:g,onEdit:d,onCancel:p,onSave:N,onToggleRaw:P}){const f=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:`${f} border-slate-700 text-slate-300`,onClick:w,children:[r?t.jsx(Ae,{"code-path":"src/components/kubernetes/YamlEditorToolbar.tsx:30:19",className:"h-3 w-3 mr-1 text-emerald-400"}):t.jsx(Re,{"code-path":"src/components/kubernetes/YamlEditorToolbar.tsx:30:73",className:"h-3 w-3 mr-1"}),r?"已复制":"复制"]}),g&&t.jsxs(Y,{"code-path":"src/components/kubernetes/YamlEditorToolbar.tsx:34:9",variant:"outline",size:"sm",className:`${f} border-slate-700 text-slate-300`,onClick:g,children:[t.jsx(pe,{"code-path":"src/components/kubernetes/YamlEditorToolbar.tsx:35:11",className:"h-3 w-3 mr-1"}),"下载"]}),!m&&(e?t.jsxs(t.Fragment,{children:[t.jsx(Y,{"code-path":"src/components/kubernetes/YamlEditorToolbar.tsx:45:13",variant:"outline",size:"sm",className:`${f} border-slate-700 text-slate-300`,onClick:p,children:"取消"}),t.jsxs(Y,{"code-path":"src/components/kubernetes/YamlEditorToolbar.tsx:46:13",size:"sm",className:`${f} bg-blue-600 hover:bg-blue-700`,onClick:N,disabled:s,children:[s?t.jsx(z,{"code-path":"src/components/kubernetes/YamlEditorToolbar.tsx:47:25",className:"h-3 w-3 animate-spin mr-1"}):t.jsx(De,{"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:`${f} border-slate-700 text-slate-300`,onClick:d,children:[t.jsx(Me,{"code-path":"src/components/kubernetes/YamlEditorToolbar.tsx:41:13",className:"h-3 w-3 mr-1"}),"编辑"]})),j&&P&&t.jsx("button",{"code-path":"src/components/kubernetes/YamlEditorToolbar.tsx:54:9",type:"button",onClick:P,className:"text-[11px] text-slate-500 hover:text-slate-300 underline-offset-2 hover:underline",children:n?"精简视图":"原始 YAML"})]})}const gt=J.theme({"&":{height:"100%"},".cm-scroller":{overflow:"auto"}});function vt({value:e,onChange:s,editing:r=!0,fill:n=!1,height:c="480px",className:m="",fontSize:j="13px"}){const w=a.useRef(null),[g,d]=a.useState(400);a.useEffect(()=>{if(!n||!w.current)return;const f=w.current,y=()=>d(Math.max(200,f.clientHeight)),S=new ResizeObserver(y);return S.observe(f),y(),()=>S.disconnect()},[n]);const p=a.useMemo(()=>[Pe(),J.lineWrapping,gt,...r?[]:[J.editable.of(!1)]],[r]),N=n?`${g}px`:c,P=t.jsx(Ee,{"code-path":"src/components/kubernetes/YamlCodeMirror.tsx:57:5",value:e,height:N,theme:Ne,extensions:p,onChange:s,basicSetup:{lineNumbers:!0,foldGutter:!0,highlightActiveLine:r,highlightActiveLineGutter:r,autocompletion:r,bracketMatching:!0,closeBrackets:r,indentOnInput:r},style:{fontSize:j}});return n?t.jsx("div",{"code-path":"src/components/kubernetes/YamlCodeMirror.tsx:79:7",ref:w,className:`flex-1 min-h-0 h-full overflow-hidden rounded-lg border border-slate-700 ${m}`,children:P}):t.jsx("div",{"code-path":"src/components/kubernetes/YamlCodeMirror.tsx:86:5",className:`overflow-auto rounded-lg border border-slate-700 ${m}`,children:P})}function Rt({clusterCode:e,namespace:s,resource:r,name:n,onClose:c,onSaved:m,autoEdit:j=!1,inline:w=!1,initialYaml:g,readOnly:d,loadYamlFn:p,saveYamlFn:N,resourceHint:P}){const{toast:f}=me(),y=ke(r),S=d??y.readOnly,[F,A]=a.useState(g||""),[v,D]=a.useState(""),[C,R]=a.useState(""),[M,T]=a.useState(!g),[_,L]=a.useState(!1),[i,B]=a.useState(j&&!S),[E,k]=a.useState(!1),[u,o]=a.useState(!1),l=a.useCallback(async x=>{const{yaml:$}=x.includes(`
|
|
---`)?await Z(x):await be(x);return D($),R($),$},[]),h=a.useCallback(async()=>{if(g){A(g),await l(g),T(!1);return}T(!0);try{const x=p?await p():await O.getResourceYaml(e,s,r,n);A(x),await l(x)}catch(x){f({title:"获取YAML失败",description:x.message,variant:"destructive"});const $=`# Error: ${x.message}`;A($),D($),R($)}finally{T(!1)}},[e,s,r,n,g,p,l,f]);a.useEffect(()=>{h()},[h]);const V=()=>{R(v),B(!0),o(!1)},b=async()=>{B(!1),await h()},ye=async()=>{L(!0);try{const x=await we(C);N?await N(x):await O.updateResourceYaml(e,s,r,n,x),f({title:"保存成功",description:N?"多文档 YAML 已应用":`${r}/${n} 已更新`}),B(!1),A(x),D(x),R(x),m?.()}catch(x){f({title:"保存失败",description:x?.message||String(x),variant:"destructive"})}finally{L(!1)}},ee=()=>i?C:u?F:v,ge=async()=>{await navigator.clipboard.writeText(ee()),k(!0),setTimeout(()=>k(!1),2e3)},ve=()=>{Ye(de(r,s,n),ee()),f({title:"已下载",description:de(r,s,n)})},je=i?C:u?F:v,te=t.jsx(yt,{"code-path":"src/components/kubernetes/YamlViewer.tsx:132:5",editing:i,saving:_,copied:E,showRaw:u,compact:w,readOnly:S,onCopy:ge,onDownload:ve,onEdit:V,onCancel:b,onSave:ye,onToggleRaw:()=>o(x=>!x)}),se=M?t.jsx("div",{"code-path":"src/components/kubernetes/YamlViewer.tsx:149:5",className:"flex items-center justify-center h-full min-h-[200px]",children:t.jsx(z,{"code-path":"src/components/kubernetes/YamlViewer.tsx:150:7",className:"h-6 w-6 animate-spin text-slate-500"})}):t.jsx(vt,{"code-path":"src/components/kubernetes/YamlViewer.tsx:153:5",value:je,editing:i,fill:!0,fontSize:w?"12px":"13px",onChange:x=>i&&R(x)});return w?t.jsxs("div",{"code-path":"src/components/kubernetes/YamlViewer.tsx:164: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:165:9",className:"flex items-center justify-between gap-3 flex-wrap shrink-0",children:[t.jsxs("p",{"code-path":"src/components/kubernetes/YamlViewer.tsx:166:11",className:"text-xs text-slate-500",children:[t.jsxs("code",{"code-path":"src/components/kubernetes/YamlViewer.tsx:167:13",className:"text-slate-400",children:[r,"/",n]}),P?t.jsxs("span",{"code-path":"src/components/kubernetes/YamlViewer.tsx:168:29",className:"text-slate-600",children:[" · ",P]}):null," · ",s]}),te]}),t.jsx("div",{"code-path":"src/components/kubernetes/YamlViewer.tsx:173:9",className:"flex-1 min-h-0 flex flex-col overflow-hidden",children:se})]}):t.jsx(Qe,{"code-path":"src/components/kubernetes/YamlViewer.tsx:179:5",onClose:c,children:t.jsxs("div",{"code-path":"src/components/kubernetes/YamlViewer.tsx:180:7",className:"bg-slate-900 border border-slate-700 rounded-xl w-[92vw] max-w-5xl h-[85vh] flex flex-col shadow-2xl",onClick:x=>x.stopPropagation(),children:[t.jsxs("div",{"code-path":"src/components/kubernetes/YamlViewer.tsx:184: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:185:11",className:"min-w-0 flex-1",children:[t.jsxs("h2",{"code-path":"src/components/kubernetes/YamlViewer.tsx:186:13",className:"text-lg font-bold text-slate-100 truncate",title:`${y.label} YAML — ${n}`,children:[y.label," YAML — ",n,S&&t.jsx("span",{"code-path":"src/components/kubernetes/YamlViewer.tsx:188:28",className:"ml-2 text-xs font-normal text-slate-500",children:"只读"})]}),t.jsxs("p",{"code-path":"src/components/kubernetes/YamlViewer.tsx:190:13",className:"text-xs text-slate-500 truncate",title:`${s} · ${e}`,children:[s," · ",e]})]}),t.jsxs("div",{"code-path":"src/components/kubernetes/YamlViewer.tsx:192:11",className:"flex items-center gap-2 shrink-0",children:[te,t.jsx(Y,{"code-path":"src/components/kubernetes/YamlViewer.tsx:194: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:194:102",className:"h-4 w-4"})})]})]}),t.jsx("div",{"code-path":"src/components/kubernetes/YamlViewer.tsx:197:9",className:"flex-1 min-h-0 flex flex-col overflow-hidden p-4",children:se})]})})}const jt=[{value:"sh",label:"/bin/sh"},{value:"bash",label:"/bin/bash"}];function Mt({open:e,onOpenChange:s,clusterId:r,namespace:n,podName:c,containers:m=[],initialContainer:j}){const{toast:w}=me(),g=a.useRef(null),d=a.useRef(null),p=a.useRef(null),N=a.useRef(null),P=a.useRef(!1),f=a.useRef(!1),[y,S]=a.useState("idle"),[F,A]=a.useState(!1),[v,D]=a.useState(j||m[0]||""),[C,R]=a.useState("sh");a.useEffect(()=>{e||(A(!1),P.current=!1)},[e]),a.useEffect(()=>{e&&!v&&m.length>0&&D(j||m[0])},[e,m,j,v]);const M=a.useCallback(()=>{if(!d.current){console.error("[PodExec:connect] ABORT: termRef.current is null");return}const i=d.current;if(p.current){try{p.current.close()}catch{}p.current=null}S("connecting"),i.clear(),i.writeln(`\x1B[36m[正在连接 ${c}${v?"/"+v:""} shell=${C} ...]\x1B[0m`);const B=O.buildPodExecWsUrl(r,n,c,v||void 0,C),E=new WebSocket(B);p.current=E,E.onopen=()=>{S("connected"),i.reset();try{const{cols:u,rows:o}=i;E.send(JSON.stringify({status:1,cols:u,rows:o}))}catch(u){console.error("[PodExec:connect] resize error:",u)}const k=()=>{try{i.focus()}catch{}};k(),setTimeout(k,100),setTimeout(k,300)},E.onmessage=k=>{try{const u=JSON.parse(k.data);if(u.status===0&&typeof u.data=="string")i.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"){i.writeln(`\r
|
|
\x1B[33m⚠ bash 不可用,请切换 /bin/sh 后重连。\x1B[0m`),f.current=!0;return}i.write(o.includes("\x1B")?o:`\r
|
|
\x1B[31m${o}\x1B[0m\r
|
|
`)}}catch{typeof k.data=="string"&&i.write(k.data)}},E.onclose=k=>{S(u=>u==="error"?u:"closed"),f.current||i.write(`\r
|
|
\x1B[33m[连接已关闭]\x1B[0m\r
|
|
`)},E.onerror=k=>{console.error("[PodExec:connect] WS error event fired, readyState=",E.readyState,"type=",k.type),S("error"),i.write(`\r
|
|
\x1B[31m[连接发生错误]\x1B[0m\r
|
|
`)}},[r,n,c,v,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 i=!1,B=0;const E=performance.now(),k=()=>{if(i)return;const u=g.current;if(!u){B++,B<20?requestAnimationFrame(k):console.error("[PodExec:tryInit] FAILED: containerRef still null after 20 retries (",Math.round(performance.now()-E),"ms)");return}const o=new Ge.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 Xe.FitAddon;o.loadAddon(l),d.current=o,N.current=l,o.onData(h=>{p.current&&p.current.readyState===WebSocket.OPEN?p.current.send(JSON.stringify({status:0,data:h})):console.warn("[PodExec:term] TX dropped — WS not open, readyState=",p.current?.readyState)}),o.open(u),requestAnimationFrame(()=>{try{l.fit()}catch{}}),P.current=!0,M()};return requestAnimationFrame(k),()=>{i=!0}},[e,r,c]),a.useEffect(()=>{if(!e){try{p.current?.close()}catch{}try{d.current?.dispose()}catch{}d.current=null,p.current=null,N.current=null,P.current=!1,S("idle")}},[e]),a.useEffect(()=>{e&&d.current&&P.current&&M()},[v,C]),a.useEffect(()=>{if(!e)return;const i=g.current;if(!i)return;let B;const E=new ResizeObserver(()=>{clearTimeout(B),B=setTimeout(()=>{if(N.current&&d.current)try{N.current.fit(),d.current.focus();const{cols:k,rows:u}=d.current;p.current?.readyState===WebSocket.OPEN&&p.current.send(JSON.stringify({status:1,cols:k,rows:u}))}catch{}},60)});return E.observe(i),()=>{clearTimeout(B),E.disconnect()}},[e,F]);const T=y==="connected"?"bg-emerald-400":y==="error"?"bg-red-400":y==="closed"?"bg-slate-500":"bg-amber-400",_=y==="connected"?"已连接":y==="connecting"?"连接中":y==="error"?"连接错误":y==="closed"?"已断开":"空闲",L=a.useCallback(()=>{try{d.current?.focus()}catch{}},[]);return t.jsx(Te,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:279:5",open:e,onOpenChange:s,children:t.jsxs(Fe,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:280:7",showCloseButton:!1,className:re("bg-[var(--dg-bg-secondary)] border-[var(--dg-border)] p-0 gap-0","!duration-0 !transition-none",F?"!max-w-none !w-screen !h-screen !rounded-none !translate-x-0 !translate-y-0 !left-0 !top-0":""),style:F?{maxWidth:"100vw",width:"100vw",height:"100vh"}:{maxWidth:"960px",width:"92vw"},children:[t.jsxs(Be,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:289:9",className:"sr-only",children:["exec — ",c]}),t.jsx(Ce,{"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:re("w-2 h-2 rounded-full shrink-0",T),title:_}),t.jsx(Oe,{"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]}),y==="connecting"&&t.jsx(z,{"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:_})]}),t.jsxs("div",{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:301:11",className:"flex items-center gap-2",children:[m.length>0&&t.jsxs(oe,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:303:15",value:v,onValueChange:D,children:[t.jsxs(ne,{"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($e,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:305:19",className:"h-3 w-3 mr-1 text-[var(--dg-text-muted)]"}),t.jsx(ae,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:306:19",placeholder:"容器"})]}),t.jsx(ce,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:308:17",children:m.map(i=>t.jsx(le,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:308:55",value:i,children:i},i))})]}),t.jsxs(oe,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:311:13",value:C,onValueChange:R,children:[t.jsx(ne,{"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(ae,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:313:17"})}),t.jsx(ce,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:315:15",children:jt.map(i=>t.jsx(le,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:315:47",value:i.value,children:i.label},i.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:()=>{M(),w({title:"正在重连…"})},title:"重连",children:t.jsx(_e,{"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(!F),className:"p-1.5 rounded hover:bg-[var(--dg-bg-hover)] text-[var(--dg-text-secondary)]",title:F?"退出全屏":"全屏",children:F?t.jsx(Le,{"code-path":"src/components/kubernetes/PodExecTerminal.tsx:322:29",className:"h-4 w-4"}):t.jsx(Ve,{"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:g,className:"bg-[#0f172a] cursor-text",style:{height:F?"calc(100vh - 49px)":"480px"},onClick:L})]})})}function Dt({open:e,onOpenChange:s,clusterCode:r,namespace:n,podName:c,containers:m=[],initialContainer:j}){const[w,g]=a.useState(j||m[0]||""),[d,p]=a.useState("/"),[N,P]=a.useState([]),[f,y]=a.useState(!1),[S,F]=a.useState(""),[A,v]=a.useState(null),[D,C]=a.useState(!1),R=a.useRef(null),M=a.useRef(!1),T=a.useCallback(async o=>{y(!0),F(""),v(null);try{const l=await O.listPodFiles(r,n,c,o,w||void 0),V=(l?.entries||l?.files||l?.data?.entries||l?.data?.files||(Array.isArray(l)?l:[])).map(b=>({name:b.name??b.Name??"",isDir:!!(b.isDir??b.is_dir??b.IsDir??b.dir??b.directory),size:typeof b.size=="number"?b.size:b.Size?Number(b.Size):void 0,modTime:b.modTime??b.mod_time??b.ModTime??b.mtime??b.modified})).filter(b=>b.name&&b.name!==".");P(V),p(o)}catch(l){F(l.message||"加载文件列表失败"),P([])}finally{y(!1)}},[r,n,c,w]);a.useEffect(()=>{e?(async()=>{if(M.current){T(d);return}y(!0);try{const l=await O.execPod(r,n,c,["pwd"],w||void 0),h=(l?.stdout||l?.data?.stdout||"").trim(),V=h&&h.startsWith("/")?h:"/";M.current=!0,p(V),T(V)}catch{M.current=!0,T("/")}})():M.current=!1},[e,w]);const _=o=>{if(o.isDir){const l=d==="/"?`/${o.name}`:`${d}/${o.name}`;T(l)}else L(o.name)},L=async o=>{const l=d==="/"?`/${o}`:`${d}/${o}`;try{const h=await O.readPodFileText(r,n,c,l,w||void 0);v({file:o,content:h})}catch(h){v({file:o,content:`读取失败: ${h.message}`})}},i=o=>{const l=d==="/"?`/${o}`:`${d}/${o}`,h=O.buildPodFileDownloadUrl(r,n,c,l,w||void 0);window.open(h,"_blank")},B=async o=>{const l=o.target.files?.[0];if(l){C(!0);try{await O.uploadPodFile(r,n,c,d,l,w||void 0),T(d)}catch(h){F(`上传失败: ${h.message}`)}finally{C(!1),R.current&&(R.current.value="")}}},E=()=>{if(d==="/")return;const o=d.split("/").filter(Boolean);o.pop(),T(o.length===0?"/":`/${o.join("/")}`)},k=o=>o==null?"-":o<1024?`${o} B`:o<1024*1024?`${(o/1024).toFixed(1)} KB`:`${(o/(1024*1024)).toFixed(1)} MB`,u=d.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 gap-3",children:[t.jsxs("div",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:170:11",className:"flex items-center gap-2 min-w-0 flex-1",children:[t.jsx(ze,{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:171:13",className:"h-4 w-4 shrink-0 text-amber-400"}),t.jsxs("span",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:172:13",className:"text-sm font-semibold text-slate-200 truncate",title:c,children:["文件: ",c]}),t.jsx(qe,{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:173:13",variant:"outline",className:"border-slate-700 text-slate-400 text-[10px] shrink-0",children:n})]}),t.jsxs("div",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:175:11",className:"flex items-center gap-2",children:[m.length>0&&t.jsx("select",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:177:15",value:w,onChange:o=>{g(o.target.value)},className:"bg-slate-800 border border-slate-700 rounded text-xs text-slate-300 px-2 py-1",children:m.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:d==="/",children:t.jsx(Ie,{"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:()=>T("/"),children:"root"}),u.map((o,l)=>{const h=`/${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(Ue,{"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:()=>T(h),children:o})]},h)})]}),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:R,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:()=>R.current?.click(),disabled:D,children:[D?t.jsx(z,{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:211:28",className:"h-3 w-3 animate-spin mr-1"}):t.jsx(We,{"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:()=>T(d),disabled:f,children:f?t.jsx(z,{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:214:26",className:"h-3 w-3 animate-spin"}):t.jsx(He,{"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}),f?t.jsx("div",{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:225:15",className:"flex items-center justify-center h-32",children:t.jsx(z,{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:225:70",className:"h-5 w-5 animate-spin text-slate-500"})}):N.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:N.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:()=>_(o),children:[o.isDir?t.jsx(Je,{"code-path":"src/components/kubernetes/PodFileBrowser.tsx:237:23",className:"h-4 w-4 text-blue-400 shrink-0"}):t.jsx(Ke,{"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:k(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(),i(o.name)},title:"下载",children:t.jsx(pe,{"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:()=>v(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{Qe as M,Mt as P,Rt as Y,Dt as a,vt as b,be as c,yt as d,wt as e,we as f,ke as g,Z as h,he as i,At as k,Q as m,X as p,de as y};
|