import{eX as a,aA as t,N as e,P as s,eY as n,eZ as r,e_ as l,p as o,e$ as c,f0 as i,f1 as u,f2 as d,b as m,f3 as v,f4 as p,f5 as g}from"./utils-lib.js?v=1761009159";import{r as y,e as f}from"./base-lib.js?v=1761009159";import{c as w,h as _,i as b}from"./validator.js?v=1761009159";import{c as h}from"./column.js?v=1761009159";import{u as q}from"./useStore9.js?v=1761009159";y(!1);const N=async(a,t,e)=>{try{return(await s({loading:"正在".concat(t?"修改":"添加","节点，请稍后..."),request:t?n(a):r(a),data:{status:Boolean},message:!0,success:a=>{C.value=[],S.value=!0,e&&e(a)}})).status}catch(l){return!1}},{isRefreshNodeList:S,rowData:j,nodeCategory:k,nodeStatus:C,forcedFlushes:x}=q(),J=a=>({label:"状态",isCustom:!0,render:a=>f("span",{class:"node_state state_"+a.data.status},[["在线","","离线","异常","重启中..."][a.data.status]])});let O={};const T=async e=>{e.category_id||0===e.category_id||delete e.category_id;const s=JSON.stringify(e),n=Date.now();try{const{data:{data:r,page:l,error:o}}=await a({...e});return O[s]={data:{data:r,total:t(l),other:{error:o}},timestamp:n},O[s].data}catch(r){return"canceled"===r.message&&O[s]&&n-O[s].timestamp<100?O[s].data:{data:[],total:0}}finally{delete e.refresh,x.value=0}},A=async a=>{s({request:l({node_id:a.id}),loading:"正在前往访问节点，请稍后...",success:a=>{a.data.status&&window.open("".concat(a.data.data.target_panel_url),"_blank")}})},D=async a=>{try{await o({icon:"warning-filled",title:"删除节点【".concat(a.address,"】"),content:"删除节点后，将失去该节点的访问权限，是否继续操作？"}),await s({loading:"正在删除节点，请稍后...",request:c({ids:a.id}),message:!0,success:a=>{C.value=[],S.value=!0}})}catch(t){}},L=async()=>{try{let a=[];return await s({request:i(),data:{msg:Array},success:({msg:t})=>{a=[{label:"全部分类",value:"all"},{label:"默认分类",value:"0"},...t.map(a=>({label:a.name,value:String(a.id)}))],k.value=a}}),a||[]}catch(a){return[]}},M=async(a,t,e,n)=>{await w({name:"节点分类",options:e.value.filter(a=>"all"!==a.value),selectList:a.value,request:async(e,r)=>{const l=a.value.map(a=>a.id),{enable:o,exclude:c}=n,i=_(a.value,c,o,{params:{category_id:Number(e.id),ids:JSON.stringify(l)}});await s({loading:"正在批量设置节点分类，请稍后...",request:v(i),message:!0}),t(),C.value=[],S.value=!0,r()}})},P=async(a,t,e,s,n,r)=>{const{label:l,value:o}=s,{enable:c,exclude:i}=r,d=new Map([["delete","批量删除已选的节点，删除后将失去该节点的访问和操作权限"],["panel","批量重启已选的节点面板"],["server","批量重启已选的节点服务器"]]);if("panel"===o||"server"===o)for(const u of e.value)if("local"===u.api_key&&"local"===u.app_key)return void m().error("本机节点无法操作");await a({title:"批量".concat(l),content:"".concat(d.get(o),"，是否继续操作！"),column:[{label:"地址",prop:"address"},h()],onConfirm:async()=>{var a;if("panel"===o||"server"===o)return await t(a=>(async(a,t)=>{const{id:e}=a;return await u(e,t)})(a,o)),void(S.value=!0);const s=await(async()=>{const a=new Map([["delete",g]]).get(o);switch(o){case"start":case"stop":const t="start"===o?1:0,s=_(e.value,i,c,{params:{status:t}});if(a)return await a(s);break;case"delete":const n=_(e.value,i,c,{params:{ids:JSON.stringify(e.value.map(a=>a.id))}});if(a)return await a(n)}})();C.value=[],S.value=!0;const{data:r,msg:l}=b(s.data);n&&n(),(null==s?void 0:s.status)||(null==(a=null==s?void 0:s.data)?void 0:a.status)?m().success(l||"操作成功！"):m().error(l||"操作失败，请重试")}})},B=()=>({isCustom:!0,label:"CPU/内存",render:a=>{var t,e;return 4==(null==(t=null==a?void 0:a.data)?void 0:t.status)?"--":2==(null==(e=null==a?void 0:a.data)?void 0:e.status)?"-- / --":"".concat(a.data.cpu_usage,"核 (").concat(a.data.cpu,"%) / ").concat(a.data.memNewTotal," (").concat(a.data.memory,"%)")}}),F=()=>{O={},e(["/mod/node/node/get_category_list","/panel/public/get_soft_status","/mod/node/node/get_node_list"])},R=async(a,t)=>{await o({icon:"warning-filled",title:"重启".concat("panel"===t?"面板":"服务器"),content:"即将重启节点【".concat(a.remarks,"】").concat("panel"===t?"面板":"服务器","，是否继续操作？")}),await s({request:u(a.id,t),loading:"正在重启".concat("panel"===t?"面板":"服务器","，请稍后..."),message:!0,success:()=>{S.value=!0}})};let U=null;const X=async(a,t)=>{const e=await s({request:d(a)});if(e.data.status){let e=!1;const s=()=>{e=!0,U&&(clearTimeout(U),U=null)},n=async()=>{e||await Y(a,a=>{a&&a.status?(s(),t&&t(a)):e||(U=setTimeout(n,2e3))})};return e=!1,n(),s}return m().error(e.data.msg),!1},Y=async(a,t)=>{const e=await s({request:p(a)});t&&t(e.data)};export{J as a,B as b,L as c,A as d,D as e,P as f,T as g,X as h,N as i,R as r,M as s,F as u};
