DnsApi-BFsXA3-6.js 8.4 KB

1
  1. import{a as e,n as t}from"./react-dom-stZKkA6x.js";import{a as n,d as r,r as i}from"./theme-DNlqAiGO.js";import{G as a,i as o,kt as s,n as c,st as l,t as u}from"./jsx-runtime-dm82oUI8.js";import{o as d}from"./grid-DcIFgt5N.js";import{t as ee}from"./table-CHt5qwx3.js";import{n as f,r as p,t as m}from"./StatusPill-Bcw_ne6L.js";import{t as h}from"./input-number-5vwSxUlw.js";import{t as g}from"./descriptions-vs1os_w7.js";import{t as _}from"./form-BRrMNJiX.js";import{t as v}from"./input-0_Xo22Fl.js";import{t as y}from"./popconfirm-DHzKhZl9.js";import{n as b,t as x}from"./EditOutlined-BjvG9r8B.js";import{t as S}from"./PlusOutlined-CILz_LKx.js";import{t as C}from"./ReloadOutlined-Cq8HKCaL.js";import{t as te}from"./ThunderboltOutlined-CMOzejTs.js";import{b as w,f as ne,h as re,p as ie}from"./index-CBPGvhVC.js";import{t as T}from"./EmptyState-rI31ioMm.js";import{n as E,t as ae}from"./navigation-state-ixI_efPF.js";var D=e(t(),1),O=u();function k(){let{message:e}=r.useApp(),{t}=n(),u=ne(),k=ie(),[N,P]=re(),[F]=_.useForm(),[I,oe]=(0,D.useState)([]),[L,R]=(0,D.useState)(!0),[z,B]=(0,D.useState)(``),[V,H]=(0,D.useState)(``),[U,W]=(0,D.useState)(!1),[G,K]=(0,D.useState)(null),q=_.useWatch(`provider`,F)||`cloudflare`,J=M(N.get(`credentialId`)),Y=(0,D.useMemo)(()=>J&&I.find(e=>e.id===J)||null,[I,J]),X=(0,D.useCallback)(async()=>{R(!0),B(``);try{let e=await i.dnsCredentials();oe(e.credentials||[])}catch(e){B(e instanceof Error?e.message:t(`common.error`))}finally{R(!1)}},[t]);(0,D.useEffect)(()=>{X()},[X]);function Z(){K(null),F.resetFields(),F.setFieldsValue({provider:`cloudflare`,defaultTtl:600}),W(!0)}function se(e){K(e),F.resetFields(),F.setFieldsValue({name:e.name,provider:e.provider,zoneName:e.zoneName,defaultTtl:e.defaultTtl}),W(!0)}async function ce(){let n=await F.validateFields(),r=G?`save:${G.id}`:`create`;H(r);try{await i.saveDnsCredential(n,G?.id),e.success(t(G?`actions.dnsApiUpdated`:`actions.dnsApiCreated`)),W(!1),K(null),F.resetFields(),await X()}catch(n){e.error(n instanceof Error?n.message:t(`common.error`))}finally{H(``)}}async function le(n){H(`test:${n.id}`);try{let r=await i.testDnsCredential(n.id);r.ok?e.success(r.detail||t(`actions.dnsApiTestCompleted`)):e.error(r.error||t(`common.error`))}catch(n){e.error(n instanceof Error?n.message:t(`common.error`))}finally{H(``)}}async function ue(n){H(`delete:${n.id}`);try{await i.deleteDnsCredential(n.id),e.success(t(`actions.dnsApiDeleted`)),J===n.id&&$(),await X()}catch(n){e.error(n instanceof Error?n.message:t(`common.error`))}finally{H(``)}}function Q(e){let t=new URLSearchParams(N);t.set(`credentialId`,String(e.id)),P(t,{state:ae(`${u.pathname}${u.search}`,1)})}function $(){let e=E(u.state);if(e){k(-e.depth);return}let t=new URLSearchParams(N);t.delete(`credentialId`),P(t,{replace:!0,state:null})}let de=[{title:t(`tokens.name`),dataIndex:`name`,render:e=>(0,O.jsx)(c.Text,{strong:!0,children:e})},{title:`Provider`,dataIndex:`provider`,render:j},{title:t(`dnsApi.zone`),dataIndex:`zoneName`,render:e=>(0,O.jsx)(c.Text,{code:!0,children:e})},{title:`TTL`,dataIndex:`defaultTtl`,width:100},{title:t(`common.status`),dataIndex:`credentialSet`,width:140,render:e=>(0,O.jsx)(m,{tone:e===!1?`warning`:`success`,children:t(e===!1?`common.notConfigured`:`smtp.passwordSet`)})},{title:t(`tokens.createdAt`),dataIndex:`updatedAt`,width:190,render:e=>e?new Date(e).toLocaleString():`—`},{title:t(`common.actions`),width:220,render:(e,n)=>(0,O.jsxs)(o,{onClick:e=>e.stopPropagation(),children:[(0,O.jsx)(s,{"aria-label":`${t(`domains.test`)} ${n.name}`,icon:(0,O.jsx)(te,{}),loading:V===`test:${n.id}`,onClick:()=>void le(n),children:t(`domains.test`)}),(0,O.jsx)(s,{"aria-label":`${t(`common.edit`)} ${n.name}`,icon:(0,O.jsx)(x,{}),onClick:()=>se(n)}),(0,O.jsx)(y,{title:t(`dnsApi.deleteConfirm`),onConfirm:()=>void ue(n),children:(0,O.jsx)(s,{"aria-label":`${t(`common.delete`)} ${n.name}`,danger:!0,icon:(0,O.jsx)(b,{}),loading:V===`delete:${n.id}`})})]})}];return(0,O.jsxs)(o,{direction:`vertical`,size:20,className:`full-width`,children:[(0,O.jsx)(p,{title:t(`dnsApi.title`),subtitle:t(`dnsApi.secretHint`),extra:(0,O.jsx)(s,{type:`primary`,icon:(0,O.jsx)(S,{}),onClick:Z,style:{minHeight:44},children:t(`dnsApi.create`)})}),z?(0,O.jsx)(d,{type:`error`,showIcon:!0,message:z,action:(0,O.jsx)(s,{icon:(0,O.jsx)(C,{}),onClick:()=>void X(),children:t(`common.refresh`)})}):null,z&&!I.length?null:(0,O.jsx)(f,{title:t(`dnsApi.title`),extra:(0,O.jsx)(m,{tone:`neutral`,children:I.length}),children:L?(0,O.jsx)(l,{active:!0,paragraph:{rows:5}}):I.length?(0,O.jsx)(ee,{rowKey:`id`,columns:de,dataSource:I,scroll:{x:940},onRow:e=>({onClick:()=>Q(e),style:{cursor:`pointer`},tabIndex:0,onKeyDown:t=>{t.target===t.currentTarget&&(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),Q(e))}})}):(0,O.jsx)(T,{description:t(`dnsApi.secretHint`),action:(0,O.jsx)(s,{icon:(0,O.jsx)(S,{}),onClick:Z,children:t(`dnsApi.create`)})})}),(0,O.jsxs)(w,{title:G?`${t(`dnsApi.editTitle`)} ${G.name}`:t(`dnsApi.createTitle`),width:560,open:U,onClose:()=>W(!1),destroyOnHidden:!0,footer:(0,O.jsxs)(o,{style:{display:`flex`,justifyContent:`flex-end`},children:[(0,O.jsx)(s,{onClick:()=>W(!1),children:t(`common.cancel`)}),(0,O.jsx)(s,{type:`primary`,loading:V===`create`||V.startsWith(`save:`),onClick:()=>void ce(),children:t(G?`dnsApi.save`:`dnsApi.create`)})]}),children:[(0,O.jsx)(d,{type:`info`,showIcon:!0,message:t(`dnsApi.secretHint`),style:{marginBottom:20}}),(0,O.jsxs)(_,{form:F,layout:`vertical`,initialValues:{provider:`cloudflare`,defaultTtl:600},children:[(0,O.jsx)(_.Item,{name:`name`,label:t(`tokens.name`),rules:[{required:!0,message:t(`tokens.nameRequired`)}],children:(0,O.jsx)(v,{placeholder:`Primary Cloudflare`})}),(0,O.jsx)(_.Item,{name:`provider`,label:`Provider`,rules:[{required:!0}],children:(0,O.jsx)(a,{options:A})}),(0,O.jsx)(_.Item,{name:`zoneName`,label:t(`dnsApi.zone`),rules:[{required:!0,message:t(`dnsApi.zoneRequired`)}],extra:t(q===`cloudflare`?`dnsApi.cloudflareZoneExtra`:`dnsApi.zoneExtra`),children:(0,O.jsx)(v,{placeholder:`example.com`})}),(0,O.jsx)(_.Item,{name:`defaultTtl`,label:`TTL`,children:(0,O.jsx)(h,{min:60,max:86400,className:`full-width`})}),q===`cloudflare`?(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(_.Item,{name:`apiToken`,label:`Cloudflare API Token`,extra:t(G?`dnsApi.keepSecret`:`dnsApi.tokenExtra`),children:(0,O.jsx)(v.Password,{autoComplete:`new-password`})}),(0,O.jsx)(_.Item,{name:`zoneId`,label:`Cloudflare Zone ID`,children:(0,O.jsx)(v,{autoComplete:`off`})})]}):null,q===`aliyun`?(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(_.Item,{name:`accessKeyId`,label:`AccessKeyId`,extra:G?t(`dnsApi.keepSecret`):void 0,children:(0,O.jsx)(v,{autoComplete:`off`})}),(0,O.jsx)(_.Item,{name:`accessKeySecret`,label:`AccessKeySecret`,extra:G?t(`dnsApi.keepSecret`):void 0,children:(0,O.jsx)(v.Password,{autoComplete:`new-password`})})]}):null,q===`dnspod`?(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(_.Item,{name:`secretId`,label:`SecretId`,extra:G?t(`dnsApi.keepSecret`):void 0,children:(0,O.jsx)(v,{autoComplete:`off`})}),(0,O.jsx)(_.Item,{name:`secretKey`,label:`SecretKey`,extra:G?t(`dnsApi.keepSecret`):void 0,children:(0,O.jsx)(v.Password,{autoComplete:`new-password`})})]}):null]})]}),(0,O.jsx)(w,{title:Y?.name||t(`dnsApi.title`),width:480,open:!!J,onClose:$,children:L&&!Y?(0,O.jsx)(l,{active:!0,paragraph:{rows:5}}):Y?(0,O.jsxs)(g,{bordered:!0,column:1,size:`small`,children:[(0,O.jsx)(g.Item,{label:`Provider`,children:j(Y.provider)}),(0,O.jsx)(g.Item,{label:t(`dnsApi.zone`),children:(0,O.jsx)(c.Text,{code:!0,children:Y.zoneName})}),(0,O.jsx)(g.Item,{label:`TTL`,children:Y.defaultTtl}),(0,O.jsx)(g.Item,{label:t(`common.status`),children:(0,O.jsx)(m,{tone:Y.credentialSet===!1?`warning`:`success`,children:Y.credentialSet===!1?t(`common.notConfigured`):t(`smtp.passwordSet`)})}),(0,O.jsx)(g.Item,{label:t(`tokens.createdAt`),children:new Date(Y.createdAt).toLocaleString()})]}):z&&J?(0,O.jsx)(d,{type:`error`,showIcon:!0,message:z,action:(0,O.jsx)(s,{icon:(0,O.jsx)(C,{}),onClick:()=>void X(),children:t(`common.refresh`)})}):J?(0,O.jsx)(T,{description:t(`common.notFound`)}):null})]})}var A=[{value:`cloudflare`,label:`Cloudflare`},{value:`aliyun`,label:`Aliyun DNS`},{value:`dnspod`,label:`Tencent DNSPod`}];function j(e){return{cloudflare:(0,O.jsx)(m,{tone:`info`,children:`Cloudflare`}),aliyun:(0,O.jsx)(m,{tone:`warning`,children:`Aliyun DNS`}),dnspod:(0,O.jsx)(m,{tone:`neutral`,children:`Tencent DNSPod`})}[e]||(0,O.jsx)(m,{tone:`neutral`,children:e})}function M(e){let t=Number(e);return Number.isInteger(t)&&t>0?t:null}export{k as default};