mirror of
https://github.com/Ed1s0nZ/CyberStrikeAI.git
synced 2026-12-02 15:33:24 +01:00
1 line
4.0 KiB
JavaScript
1 line
4.0 KiB
JavaScript
import{n as e}from"./rolldown-runtime-WkwZ5CU-.js";import{S as t,t as n}from"./react-QV7DAAIx.js";import{A as r,B as i,F as a,H as o,M as s,N as c,_ as l,c as u,et as d,tt as f}from"./semi-2PUNK4Bq.js";import{I as p,P as m,R as h,p as g,u as _}from"./index-DEaqvjFh.js";var v=e(t(),1),y=e(n(),1),{Text:b,Paragraph:x}=o,S={get:`blue`,post:`green`,put:`orange`,delete:`red`,patch:`violet`,head:`grey`,options:`grey`};function C(e){let t=e?.paths||{},n=[];return Object.entries(t).forEach(([e,t])=>{Object.entries(t||{}).forEach(([t,r])=>{Object.hasOwn(S,t)&&r&&n.push({id:`${t.toUpperCase()} ${e}`,method:t.toUpperCase(),path:e,summary:r.summary||r.description||``,tag:r.tags&&r.tags[0]||`default`,operation:r})})}),n.sort((e,t)=>e.path.localeCompare(t.path)||e.method.localeCompare(t.method))}function w(){let e=m(),[t,n]=(0,v.useState)(null),[o,w]=(0,v.useState)(!0),[T,E]=(0,v.useState)(null),[D,O]=(0,v.useState)(``),[k,A]=(0,v.useState)(`all`),[j,M]=(0,v.useState)(null),N=async()=>{w(!0),E(null);try{let e=await p.get(`/openapi/spec`);n(e)}catch(e){E(e)}finally{w(!1)}};(0,v.useEffect)(()=>{N()},[]);let P=(0,v.useMemo)(()=>C(t),[t]),F=(0,v.useMemo)(()=>P.filter(e=>{if(k!==`all`&&e.method!==k)return!1;if(!D)return!0;let t=D.toLowerCase();return e.path.toLowerCase().includes(t)||e.summary.toLowerCase().includes(t)||e.method.toLowerCase().includes(t)}),[P,D,k]),I=F.find(e=>e.id===j)||F[0]||null,L=(0,v.useMemo)(()=>{let e=new Map;return F.forEach(t=>{e.has(t.tag)||e.set(t.tag,[]),e.get(t.tag).push(t)}),[...e.entries()]},[F]);return(0,y.jsxs)(`div`,{className:`api-docs-page`,children:[(0,y.jsx)(g,{title:e(`apiDocs.title`,null,`API 文档`),description:t?.info?.description||`CyberStrikeAI 开放接口`,extra:(0,y.jsxs)(c,{wrap:!0,children:[(0,y.jsx)(a,{icon:(0,y.jsx)(f,{}),onClick:N,loading:o,children:e(`common.refresh`,null,`刷新`)}),(0,y.jsx)(b,{link:{href:`/api-docs`},children:e(`apiDocs.openConsole`,null,`打开 API 控制台`)})]})}),(0,y.jsxs)(`div`,{className:`api-docs-layout`,children:[(0,y.jsxs)(s,{className:`api-docs-sidebar`,bordered:!1,children:[(0,y.jsxs)(c,{vertical:!0,style:{width:`100%`},spacing:8,children:[(0,y.jsx)(i,{prefix:(0,y.jsx)(d,{}),value:D,onChange:O,placeholder:`搜索路径或说明`}),(0,y.jsx)(l,{value:k,onChange:A,style:{width:`100%`},optionList:[{value:`all`,label:`全部方法`},...[`GET`,`POST`,`PUT`,`DELETE`,`PATCH`].map(e=>({value:e,label:e}))]})]}),(0,y.jsxs)(`div`,{className:`api-docs-list`,children:[L.map(([e,t])=>(0,y.jsxs)(`div`,{className:`api-docs-group`,children:[(0,y.jsx)(b,{type:`tertiary`,className:`api-docs-group-title`,children:e}),t.map(e=>(0,y.jsxs)(`button`,{type:`button`,className:`api-docs-item ${I?.id===e.id?`is-active`:``}`,onClick:()=>M(e.id),children:[(0,y.jsx)(r,{size:`small`,color:S[e.method.toLowerCase()],children:e.method}),(0,y.jsx)(`span`,{className:`api-docs-item-path`,children:e.path})]},e.id))]},e)),!o&&L.length===0&&(0,y.jsx)(b,{type:`tertiary`,children:`没有匹配的接口`})]})]}),(0,y.jsxs)(`div`,{className:`api-docs-detail`,children:[T&&(0,y.jsx)(s,{bordered:!1,children:(0,y.jsx)(b,{type:`danger`,children:h(T)})}),I?(0,y.jsxs)(s,{bordered:!1,children:[(0,y.jsxs)(`div`,{className:`api-docs-detail-head`,children:[(0,y.jsx)(r,{color:S[I.method.toLowerCase()],children:I.method}),(0,y.jsx)(`code`,{className:`api-docs-detail-path`,children:I.path})]}),(0,y.jsx)(x,{children:I.summary||`无说明`}),(0,y.jsxs)(u,{type:`line`,children:[(0,y.jsx)(u.TabPane,{itemKey:`params`,tab:`参数`,children:(0,y.jsx)(_,{value:I.operation.parameters||[],title:`Request Parameters`,collapsed:!0})}),(0,y.jsx)(u.TabPane,{itemKey:`body`,tab:`请求体`,children:(0,y.jsx)(_,{value:I.operation.requestBody||{},title:`Request Body`,collapsed:!0})}),(0,y.jsx)(u.TabPane,{itemKey:`responses`,tab:`响应`,children:(0,y.jsx)(_,{value:I.operation.responses||{},title:`Responses`,collapsed:!0})})]})]}):(0,y.jsx)(s,{bordered:!1,children:(0,y.jsx)(b,{type:`tertiary`,children:o?`加载中…`:`选择左侧接口查看详情`})})]})]})]})}export{w as default}; |