| 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-B5baUfEh.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-DaQoG6GE.js";import{t as ee}from"./table-7bnHOUOM.js";import{n as f,t as p}from"./SectionCard--RQCBj1c.js";import{t as m}from"./input-number-5vwSxUlw.js";import{t as h}from"./descriptions-vs1os_w7.js";import{t as g}from"./form-GQckeBSC.js";import{t as _}from"./input-0_Xo22Fl.js";import{t as v}from"./popconfirm-BvP3t7-7.js";import{n as y,t as b}from"./EditOutlined-C5punjK1.js";import{t as x}from"./PlusOutlined-aj3TL3Tz.js";import{t as S}from"./ReloadOutlined-Cmwy5NFg.js";import{t as C}from"./ThunderboltOutlined-CAOlQtzj.js";import{b as w,f as te,h as ne,p as re}from"./index-Dztone_T.js";import{t as T}from"./EmptyState-rI31ioMm.js";import{t as E}from"./StatusPill-BM21x0ED.js";import{n as D,t as ie}from"./navigation-state-ixI_efPF.js";var O=e(t(),1),k=u();function A(){let{message:e}=r.useApp(),{t}=n(),u=te(),A=re(),[N,P]=ne(),[F]=g.useForm(),[I,oe]=(0,O.useState)([]),[L,R]=(0,O.useState)(!0),[z,B]=(0,O.useState)(``),[V,H]=(0,O.useState)(``),[U,W]=(0,O.useState)(!1),[G,K]=(0,O.useState)(null),q=g.useWatch(`provider`,F)||`cloudflare`,J=M(N.get(`credentialId`)),Y=(0,O.useMemo)(()=>J&&I.find(e=>e.id===J)||null,[I,J]),X=(0,O.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,O.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:ie(`${u.pathname}${u.search}`,1)})}function $(){let e=D(u.state);if(e){A(-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,k.jsx)(c.Text,{strong:!0,children:e})},{title:`Provider`,dataIndex:`provider`,render:j},{title:t(`dnsApi.zone`),dataIndex:`zoneName`,render:e=>(0,k.jsx)(c.Text,{code:!0,children:e})},{title:`TTL`,dataIndex:`defaultTtl`,width:100},{title:t(`common.status`),dataIndex:`credentialSet`,width:140,render:e=>(0,k.jsx)(E,{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,k.jsxs)(o,{onClick:e=>e.stopPropagation(),children:[(0,k.jsx)(s,{"aria-label":`${t(`domains.test`)} ${n.name}`,icon:(0,k.jsx)(C,{}),loading:V===`test:${n.id}`,onClick:()=>void le(n),children:t(`domains.test`)}),(0,k.jsx)(s,{"aria-label":`${t(`common.edit`)} ${n.name}`,icon:(0,k.jsx)(b,{}),onClick:()=>se(n)}),(0,k.jsx)(v,{title:t(`dnsApi.deleteConfirm`),onConfirm:()=>void ue(n),children:(0,k.jsx)(s,{"aria-label":`${t(`common.delete`)} ${n.name}`,danger:!0,icon:(0,k.jsx)(y,{}),loading:V===`delete:${n.id}`})})]})}];return(0,k.jsxs)(o,{direction:`vertical`,size:20,className:`full-width`,children:[(0,k.jsx)(f,{title:t(`dnsApi.title`),subtitle:t(`dnsApi.secretHint`),extra:(0,k.jsx)(s,{type:`primary`,icon:(0,k.jsx)(x,{}),onClick:Z,style:{minHeight:44},children:t(`dnsApi.create`)})}),z?(0,k.jsx)(d,{type:`error`,showIcon:!0,message:z,action:(0,k.jsx)(s,{icon:(0,k.jsx)(S,{}),onClick:()=>void X(),children:t(`common.refresh`)})}):null,z&&!I.length?null:(0,k.jsx)(p,{title:t(`dnsApi.title`),extra:(0,k.jsx)(E,{tone:`neutral`,children:I.length}),children:L?(0,k.jsx)(l,{active:!0,paragraph:{rows:5}}):I.length?(0,k.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,k.jsx)(T,{description:t(`dnsApi.secretHint`),action:(0,k.jsx)(s,{icon:(0,k.jsx)(x,{}),onClick:Z,children:t(`dnsApi.create`)})})}),(0,k.jsxs)(w,{title:G?`${t(`dnsApi.editTitle`)} ${G.name}`:t(`dnsApi.createTitle`),width:560,open:U,onClose:()=>W(!1),destroyOnHidden:!0,footer:(0,k.jsxs)(o,{style:{display:`flex`,justifyContent:`flex-end`},children:[(0,k.jsx)(s,{onClick:()=>W(!1),children:t(`common.cancel`)}),(0,k.jsx)(s,{type:`primary`,loading:V===`create`||V.startsWith(`save:`),onClick:()=>void ce(),children:t(G?`dnsApi.save`:`dnsApi.create`)})]}),children:[(0,k.jsx)(d,{type:`info`,showIcon:!0,message:t(`dnsApi.secretHint`),style:{marginBottom:20}}),(0,k.jsxs)(g,{form:F,layout:`vertical`,initialValues:{provider:`cloudflare`,defaultTtl:600},children:[(0,k.jsx)(g.Item,{name:`name`,label:t(`tokens.name`),rules:[{required:!0,message:t(`tokens.nameRequired`)}],children:(0,k.jsx)(_,{placeholder:`Primary Cloudflare`})}),(0,k.jsx)(g.Item,{name:`provider`,label:`Provider`,rules:[{required:!0}],children:(0,k.jsx)(a,{options:ae})}),(0,k.jsx)(g.Item,{name:`zoneName`,label:t(`dnsApi.zone`),rules:[{required:!0,message:t(`dnsApi.zoneRequired`)}],extra:t(q===`cloudflare`?`dnsApi.cloudflareZoneExtra`:`dnsApi.zoneExtra`),children:(0,k.jsx)(_,{placeholder:`example.com`})}),(0,k.jsx)(g.Item,{name:`defaultTtl`,label:`TTL`,children:(0,k.jsx)(m,{min:60,max:86400,className:`full-width`})}),q===`cloudflare`?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(g.Item,{name:`apiToken`,label:`Cloudflare API Token`,extra:t(G?`dnsApi.keepSecret`:`dnsApi.tokenExtra`),children:(0,k.jsx)(_.Password,{autoComplete:`new-password`})}),(0,k.jsx)(g.Item,{name:`zoneId`,label:`Cloudflare Zone ID`,children:(0,k.jsx)(_,{autoComplete:`off`})})]}):null,q===`aliyun`?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(g.Item,{name:`accessKeyId`,label:`AccessKeyId`,extra:G?t(`dnsApi.keepSecret`):void 0,children:(0,k.jsx)(_,{autoComplete:`off`})}),(0,k.jsx)(g.Item,{name:`accessKeySecret`,label:`AccessKeySecret`,extra:G?t(`dnsApi.keepSecret`):void 0,children:(0,k.jsx)(_.Password,{autoComplete:`new-password`})})]}):null,q===`dnspod`?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(g.Item,{name:`secretId`,label:`SecretId`,extra:G?t(`dnsApi.keepSecret`):void 0,children:(0,k.jsx)(_,{autoComplete:`off`})}),(0,k.jsx)(g.Item,{name:`secretKey`,label:`SecretKey`,extra:G?t(`dnsApi.keepSecret`):void 0,children:(0,k.jsx)(_.Password,{autoComplete:`new-password`})})]}):null]})]}),(0,k.jsx)(w,{title:Y?.name||t(`dnsApi.title`),width:480,open:!!J,onClose:$,children:L&&!Y?(0,k.jsx)(l,{active:!0,paragraph:{rows:5}}):Y?(0,k.jsxs)(h,{bordered:!0,column:1,size:`small`,children:[(0,k.jsx)(h.Item,{label:`Provider`,children:j(Y.provider)}),(0,k.jsx)(h.Item,{label:t(`dnsApi.zone`),children:(0,k.jsx)(c.Text,{code:!0,children:Y.zoneName})}),(0,k.jsx)(h.Item,{label:`TTL`,children:Y.defaultTtl}),(0,k.jsx)(h.Item,{label:t(`common.status`),children:(0,k.jsx)(E,{tone:Y.credentialSet===!1?`warning`:`success`,children:Y.credentialSet===!1?t(`common.notConfigured`):t(`smtp.passwordSet`)})}),(0,k.jsx)(h.Item,{label:t(`tokens.createdAt`),children:new Date(Y.createdAt).toLocaleString()})]}):z&&J?(0,k.jsx)(d,{type:`error`,showIcon:!0,message:z,action:(0,k.jsx)(s,{icon:(0,k.jsx)(S,{}),onClick:()=>void X(),children:t(`common.refresh`)})}):J?(0,k.jsx)(T,{description:t(`common.notFound`)}):null})]})}var ae=[{value:`cloudflare`,label:`Cloudflare`},{value:`aliyun`,label:`Aliyun DNS`},{value:`dnspod`,label:`Tencent DNSPod`}];function j(e){return{cloudflare:(0,k.jsx)(E,{tone:`info`,children:`Cloudflare`}),aliyun:(0,k.jsx)(E,{tone:`warning`,children:`Aliyun DNS`}),dnspod:(0,k.jsx)(E,{tone:`neutral`,children:`Tencent DNSPod`})}[e]||(0,k.jsx)(E,{tone:`neutral`,children:e})}function M(e){let t=Number(e);return Number.isInteger(t)&&t>0?t:null}export{A as default};
|