码桶
发现社区成员的开源项目
Tokens-DIrNevUl.js4.7 KB
import{u as R,r as n,b as u,j as e,o as D,B as h,T as _,F,C as O,N as P}from"./index-GWuvg2UH.js";import{B as l}from"./index-DihvOmSo.js";import{E as $}from"./index-VbOLTMR0.js";import{M as g}from"./Modal-08QhW3n9.js";import{S as C}from"./index-BZDftoba.js";import{T as L}from"./index-mZVFvfKe.js";import{T as d}from"./index-BW_2QB9V.js";import{I as K}from"./IconDelete-CdbtfS3z.js";import{I as A}from"./IconPlus-Dkwh5Gs5.js";import"./IconTickCircle-BYgwCdAe.js";import"./_baseDifference-DopHgqVv.js";import"./index-DIHsQVbu.js";import"./slice-B6jKCnyX.js";import"./object-DkPZvw8u.js";import"./index-BMbdBPA2.js";const H=[0,30,90,365];function oe(){const{t:s}=R(),[c,S]=n.useState(null),[f,j]=n.useState(""),[T,m]=n.useState(!1),[I,v]=n.useState(!1),[w,p]=n.useState(""),[i,x]=n.useState({name:"",expires_in_days:0}),[o,k]=n.useState(null),r=n.useCallback(async()=>{try{const t=await u.tokens();S(t.items||[]),j("")}catch(t){j(t.message)}},[]);n.useEffect(()=>{r()},[r]);const N=async()=>{if(!i.name.trim()){p(s("tokenName"));return}v(!0);try{const t=await u.createToken({name:i.name.trim(),expires_in_days:i.expires_in_days});m(!1),k(t),await r()}catch(t){p(t.message)}finally{v(!1)}},b=t=>{g.confirm({title:s("tokenRevoke"),content:s("tokenRevokeConfirm"),onOk:async()=>{try{await u.deleteToken(t.id),d.success(s("tokenRevoked")),await r()}catch(a){d.error(a.message)}}})},B=async()=>{try{await navigator.clipboard.writeText((o==null?void 0:o.token)||""),d.success(s("tokenCopied"))}catch{d.error(s("tokenCopyFail"))}},y=t=>t>0?new Date(t*1e3).toLocaleString():"—",E=[{title:s("tokenName"),dataIndex:"name",ellipsis:{showTitle:!0}},{title:s("tokenKey"),dataIndex:"token_masked",width:170,render:t=>e.jsx("span",{style:{fontFamily:"monospace",fontSize:12},children:t})},{title:s("tokenExpires"),dataIndex:"expires_at",width:170,render:t=>t>0?y(t):e.jsx(D,{size:"small",color:"green",children:s("tokenNever")})},{title:s("tokenLastUsed"),dataIndex:"last_used_at",width:170,render:y},{title:s("tokenCreated"),dataIndex:"created_at",width:170,render:y},{title:"",dataIndex:"op",width:90,render:(t,a)=>e.jsx(h,{size:"small",type:"danger",icon:e.jsx(K,{}),onClick:()=>b(a),children:s("tokenRevoke")})}],z=t=>`curl -H "Authorization: Bearer <${s("tokenKey")}>" "${window.location.origin}/open/v1/${t}"`;return e.jsxs("div",{className:"page",children:[e.jsxs("div",{className:"toolbar",children:[e.jsx(_.Title,{heading:5,style:{margin:0},children:s("tokens")}),e.jsx(h,{size:"small",icon:e.jsx(A,{}),theme:"solid",onClick:()=>{p(""),x({name:"",expires_in_days:0}),m(!0)},children:s("tokenNew")})]}),f&&e.jsx(l,{type:"danger",description:f,style:{marginBottom:12}}),e.jsx(l,{type:"info",description:s("tokensHint"),style:{marginBottom:14},closeIcon:null}),e.jsx("div",{className:"card",style:{padding:0,overflow:"hidden"},children:c===null?e.jsx(C,{active:!0,placeholder:e.jsx(C.Paragraph,{rows:5}),loading:!0,style:{padding:16}}):c.length===0?e.jsx($,{style:{margin:"40px 0"},description:s("tokensEmpty")}):e.jsx(L,{columns:E,dataSource:c,rowKey:"id",pagination:!1,size:"small"})}),e.jsxs("div",{className:"card",style:{marginTop:14},children:[e.jsx("div",{className:"card-title",children:s("tokenApiDoc")}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8},children:["overview?site_id=1&start=2026-09-01&end=2026-09-12","pages?site_id=1&limit=20","online?site_id=1"].map(t=>e.jsx("pre",{style:{margin:0,padding:"8px 12px",background:"var(--semi-color-fill-0)",borderRadius:6,fontSize:12,overflowX:"auto"},children:z(t)},t))})]}),e.jsx(g,{title:s("tokenNew"),visible:T,onCancel:()=>m(!1),onOk:N,okButtonProps:{loading:I},width:460,children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:14,paddingTop:6},children:[w&&e.jsx(l,{type:"danger",description:w}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:13,marginBottom:6},children:s("tokenName")}),e.jsx(F,{placeholder:s("tokenNamePh"),value:i.name,onChange:t=>x(a=>({...a,name:t}))})]}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:13,marginBottom:6},children:s("tokenExpires")}),e.jsx(O,{style:{width:"100%"},value:i.expires_in_days,onChange:t=>x(a=>({...a,expires_in_days:t})),optionList:H.map(t=>({value:t,label:t===0?s("tokenNever"):s("tokenDays").replace("{n}",String(t))}))})]})]})}),e.jsxs(g,{title:s("tokenCreated"),visible:o!==null,onCancel:()=>k(null),onOk:()=>k(null),okText:s("tokenDone"),showClose:!1,closable:!1,width:520,children:[e.jsx(l,{type:"warning",description:s("tokenOnce"),closeIcon:null,style:{marginBottom:12}}),e.jsxs("div",{style:{display:"flex",gap:8,alignItems:"center"},children:[e.jsx(_.Text,{code:!0,style:{flex:1,wordBreak:"break-all"},children:o==null?void 0:o.token}),e.jsx(h,{icon:e.jsx(P,{}),onClick:B,children:s("tokenCopy")})]})]})]})}export{oe as default};