Settings-DfSJsq0-.js 12 KB

1
  1. import{a as e,n as t,r as n}from"./react-dom-stZKkA6x.js";import{d as r,f as i,o as a,r as o}from"./theme-JEAJA3Ef.js";import{G as s,i as c,kt as l,n as u,st as d,t as f}from"./jsx-runtime-dm82oUI8.js";import{o as p}from"./grid-oQFtU3R0.js";import{t as m}from"./table-DZMCIB4H.js";import{n as h,t as g}from"./SectionCard-DDGEHf10.js";import{t as _}from"./form-lkDIWt8f.js";import{t as v}from"./input-0_Xo22Fl.js";import{t as y}from"./switch-CsMGEdLR.js";import{t as b}from"./ReloadOutlined-B6H5UA27.js";import{d as x,n as S,r as C,u as w}from"./index-avDTLp8M.js";import{n as T}from"./domain-model-BLOrIAIx.js";import{t as E}from"./StatusTag-BHQIjmW3.js";var D=n((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default={icon:{tag:`svg`,attrs:{viewBox:`64 64 896 896`,focusable:`false`},children:[{tag:`path`,attrs:{d:`M893.3 293.3L730.7 130.7c-7.5-7.5-16.7-13-26.7-16V112H144c-17.7 0-32 14.3-32 32v736c0 17.7 14.3 32 32 32h736c17.7 0 32-14.3 32-32V338.5c0-17-6.7-33.2-18.7-45.2zM384 184h256v104H384V184zm456 656H184V184h136v136c0 17.7 14.3 32 32 32h320c17.7 0 32-14.3 32-32V205.8l136 136V840zM512 442c-79.5 0-144 64.5-144 144s64.5 144 144 144 144-64.5 144-144-64.5-144-144-144zm0 224c-44.2 0-80-35.8-80-80s35.8-80 80-80 80 35.8 80 80-35.8 80-80 80z`}}]},name:`save`,theme:`outlined`}})),O=e(t()),k=e(D());function A(){return A=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},A.apply(this,arguments)}var j=O.forwardRef((e,t)=>O.createElement(r,A({},e,{ref:t,icon:k.default}))),M=f();function N(){let{message:e,modal:t}=i.useApp(),{locale:n,t:r}=a(),{user:f}=S(),[D]=_.useForm(),k=_.useWatch(`appBaseUrl`,D),[A,N]=(0,O.useState)(null),[z,B]=(0,O.useState)(!0),[V,H]=(0,O.useState)(!1),[U,W]=(0,O.useState)(``),[G,K]=(0,O.useState)(!1),q=(0,O.useRef)(null),J=(0,O.useMemo)(()=>n.startsWith(`en`)?{title:`Discard unsaved changes?`,content:`You have unsaved settings. Leaving this page will discard them.`,confirm:`Leave page`,cancel:`Keep editing`}:{title:`放弃未保存的更改?`,content:`当前设置尚未保存,离开此页面将丢失这些更改。`,confirm:`离开页面`,cancel:`继续编辑`},[n]),Y=n.startsWith(`en`)?R:L,X=I(k,n),Z=x((0,O.useCallback)(({currentLocation:e,nextLocation:t})=>G&&P(e)!==P(t),[G]));w((0,O.useCallback)(e=>{G&&(e.preventDefault(),e.returnValue=``)},[G]),{capture:!0});let Q=(0,O.useCallback)(async()=>{B(!0),W(``);try{if(f?.role!==`admin`)return;let e=await o.adminSettings();N(e.settings),D.setFieldsValue(e.settings),K(!1)}catch(e){W(e instanceof Error?e.message:r(`common.error`))}finally{B(!1)}},[D,f?.role,r]);(0,O.useEffect)(()=>{Q()},[Q]),(0,O.useEffect)(()=>{Z.state!==`blocked`||q.current||(q.current=t.confirm({title:J.title,content:J.content,okText:J.confirm,cancelText:J.cancel,okButtonProps:{danger:!0},onOk:()=>{q.current=null,K(!1),Z.proceed()},onCancel:()=>{q.current=null,Z.reset()},afterClose:()=>{q.current=null}}))},[Z,J,t]),(0,O.useEffect)(()=>()=>{q.current?.destroy(),q.current=null},[]);async function $(t){H(!0);try{let n=await o.saveAdminSettings(t);N(n.settings),D.setFieldsValue(n.settings),K(!1),e.success(r(`actions.settingsSaved`))}catch(t){e.error(t instanceof Error?t.message:r(`common.error`))}finally{H(!1)}}if(!z&&f?.role!==`admin`)return(0,M.jsxs)(c,{direction:`vertical`,size:20,className:`full-width`,children:[(0,M.jsx)(h,{title:r(`nav.settings`)}),(0,M.jsx)(p,{type:`warning`,showIcon:!0,message:r(`settings.noPermission`)})]});let ee=[{title:r(`settings.checkItem`),dataIndex:`label`,width:160},{title:r(`dnsRecord.hostname`),dataIndex:`host`,width:180,render:e=>(0,M.jsx)(u.Text,{code:!0,children:e||`—`})},{title:r(`dnsRecord.targetValue`),dataIndex:`value`,width:220,render:e=>(0,M.jsx)(u.Text,{code:!0,children:e||`—`})},{title:r(`dnsRecord.currentValue`),width:260,render:(e,t)=>{let n=T(t);return n.length?(0,M.jsx)(c,{direction:`vertical`,size:4,children:n.map(e=>(0,M.jsx)(u.Text,{code:!0,children:e},e))}):(0,M.jsx)(u.Text,{type:`secondary`,children:r(`dnsRecord.emptyCurrent`)})}},{title:r(`common.status`),width:120,render:(e,t)=>(0,M.jsx)(E,{record:t})}],te=A?.systemChecks?.ptr?[A.systemChecks.ptr]:[];return(0,M.jsxs)(c,{direction:`vertical`,size:20,className:`full-width`,children:[(0,M.jsx)(h,{title:r(`nav.settings`),subtitle:n.startsWith(`en`)?`Runtime and delivery defaults for this MailHub instance.`:`配置当前 MailHub 实例的运行参数和投递默认行为。`,extra:(0,M.jsx)(l,{type:`primary`,icon:(0,M.jsx)(j,{}),loading:V,disabled:!G||z,onClick:()=>D.submit(),style:{minHeight:44},children:r(`settings.save`)})}),U?(0,M.jsx)(p,{type:`error`,showIcon:!0,message:U,action:(0,M.jsx)(l,{icon:(0,M.jsx)(b,{}),onClick:()=>void Q(),children:r(`common.refresh`)})}):null,z?(0,M.jsx)(g,{children:(0,M.jsx)(d,{active:!0,paragraph:{rows:10}})}):(0,M.jsx)(_,{form:D,layout:`vertical`,onFinish:$,onValuesChange:()=>K(!0),children:(0,M.jsxs)(c,{direction:`vertical`,size:20,className:`full-width`,children:[(0,M.jsxs)(g,{title:n.startsWith(`en`)?`Instance`:`实例配置`,children:[X?(0,M.jsx)(p,{type:`error`,showIcon:!0,message:Y.publicUrlInvalid,description:X,style:{marginBottom:20}}):null,(0,M.jsxs)(`div`,{className:`form-grid two`,children:[(0,M.jsx)(_.Item,{name:`appBaseUrl`,label:Y.publicUrl,extra:F(`APP_BASE_URL`),rules:[{required:!0,message:Y.publicUrlRequired},{validator:(e,t)=>I(t,n)?Promise.reject(Error(I(t,n))):Promise.resolve()}],children:(0,M.jsx)(v,{"aria-label":`APP_BASE_URL`,inputMode:`url`,placeholder:`https://mail.example.com`})}),(0,M.jsx)(_.Item,{name:`mailHostname`,label:Y.mailHostname,extra:F(`MAIL_HOSTNAME`),children:(0,M.jsx)(v,{"aria-label":`MAIL_HOSTNAME`})}),(0,M.jsx)(_.Item,{name:`sendingIp`,label:Y.sendingIp,extra:F(`SENDING_IP`),children:(0,M.jsx)(v,{"aria-label":`SENDING_IP`,inputMode:`decimal`})}),(0,M.jsx)(_.Item,{name:`defaultSpfMechanisms`,label:Y.spfMechanisms,extra:F(`DEFAULT_SPF_MECHANISMS`),children:(0,M.jsx)(v,{"aria-label":`DEFAULT_SPF_MECHANISMS`})}),(0,M.jsx)(_.Item,{name:`dmarcPolicy`,label:Y.dmarcPolicy,extra:F(`DMARC_POLICY`),children:(0,M.jsx)(s,{"aria-label":`DMARC_POLICY`,options:[`none`,`quarantine`,`reject`].map(e=>({value:e,label:e}))})}),(0,M.jsx)(_.Item,{name:`dmarcRua`,label:Y.dmarcReports,extra:F(`DMARC_RUA`),children:(0,M.jsx)(v,{"aria-label":`DMARC_RUA`,inputMode:`email`})})]})]}),(0,M.jsx)(g,{title:r(`settings.registrationPolicy`),children:(0,M.jsx)(_.Item,{name:`registrationRequiresApproval`,label:r(`settings.registrationRequiresApproval`),extra:r(`settings.registrationRequiresApprovalHint`),valuePropName:`checked`,style:{marginBottom:0},children:(0,M.jsx)(y,{"aria-label":r(`settings.registrationRequiresApproval`),checkedChildren:r(`settings.approvalRequired`),unCheckedChildren:r(`settings.approvalNotRequired`)})})}),(0,M.jsxs)(g,{title:n.startsWith(`en`)?`Message and tracking defaults`:`邮件与跟踪默认值`,children:[(0,M.jsxs)(`div`,{className:`form-grid two`,children:[(0,M.jsx)(_.Item,{name:`listUnsubscribeMailto`,label:Y.unsubscribeEmail,extra:F(`LIST_UNSUBSCRIBE_MAILTO`),children:(0,M.jsx)(v,{"aria-label":`LIST_UNSUBSCRIBE_MAILTO`,placeholder:`unsubscribe@example.com`})}),(0,M.jsx)(_.Item,{name:`listUnsubscribeUrl`,label:Y.unsubscribeUrl,extra:F(`LIST_UNSUBSCRIBE_URL`),children:(0,M.jsx)(v,{"aria-label":`LIST_UNSUBSCRIBE_URL`,placeholder:`https://example.com/unsubscribe/{eventId}`})}),(0,M.jsx)(_.Item,{name:`reportAbuseTo`,label:Y.abuseMailbox,extra:F(`REPORT_ABUSE_TO`),children:(0,M.jsx)(v,{"aria-label":`REPORT_ABUSE_TO`,placeholder:`abuse@example.com`})}),(0,M.jsx)(_.Item,{name:`csaComplaintsTo`,label:Y.csaMailbox,extra:F(`CSA_COMPLAINTS_TO`),children:(0,M.jsx)(v,{"aria-label":`CSA_COMPLAINTS_TO`,placeholder:`csa-complaints@example.com`})}),(0,M.jsx)(_.Item,{name:`bounceAddress`,label:Y.bounceAddress,extra:F(`BOUNCE_ADDRESS`),children:(0,M.jsx)(v,{"aria-label":`BOUNCE_ADDRESS`,placeholder:`bounce@example.com`})})]}),(0,M.jsxs)(c,{direction:`vertical`,size:16,children:[(0,M.jsx)(_.Item,{name:`engagementTrackingEnabled`,label:r(`settings.engagementTracking`),valuePropName:`checked`,style:{marginBottom:0},children:(0,M.jsx)(y,{})}),(0,M.jsx)(_.Item,{name:`listUnsubscribePostEnabled`,label:Y.oneClickUnsubscribe,extra:F(`LIST_UNSUBSCRIBE_POST_ENABLED`),valuePropName:`checked`,style:{marginBottom:0},children:(0,M.jsx)(y,{"aria-label":`LIST_UNSUBSCRIBE_POST_ENABLED`})}),(0,M.jsx)(_.Item,{name:`feedbackIdEnabled`,label:Y.feedbackId,extra:F(`FEEDBACK_ID_ENABLED`),valuePropName:`checked`,style:{marginBottom:0},children:(0,M.jsx)(y,{"aria-label":`FEEDBACK_ID_ENABLED`})})]})]}),(0,M.jsx)(g,{title:r(`settings.deliveryChecks`),extra:A?.systemChecks?.checkedAt?(0,M.jsx)(u.Text,{type:`secondary`,children:new Date(A.systemChecks.checkedAt).toLocaleString()}):null,children:(0,M.jsx)(m,{rowKey:`key`,columns:ee,dataSource:te,pagination:!1,scroll:{x:940}})}),(0,M.jsxs)(g,{title:(0,M.jsxs)(c,{children:[(0,M.jsx)(C,{style:{color:`#D92D20`}}),n.startsWith(`en`)?`Danger zone`:`高风险设置`]}),children:[(0,M.jsx)(p,{type:`warning`,showIcon:!0,message:n.startsWith(`en`)?`Changes here alter the sending security boundary.`:`以下设置会改变发信安全边界,请在保存前确认影响。`,description:A?.usingDefaultAdminPassword?n.startsWith(`en`)?`The default administrator password is still in use. Change it before exposing this instance.`:`当前仍在使用默认管理员密码,请在对外开放前完成修改。`:void 0,style:{marginBottom:20}}),(0,M.jsxs)(c,{direction:`vertical`,size:16,children:[(0,M.jsx)(_.Item,{name:`sendRequiresVerified`,label:Y.requireVerifiedDomain,extra:F(`SEND_REQUIRES_VERIFIED`),valuePropName:`checked`,style:{marginBottom:0},children:(0,M.jsx)(y,{"aria-label":`SEND_REQUIRES_VERIFIED`})}),(0,M.jsx)(_.Item,{name:`bounceEnvelopeEnabled`,label:Y.bounceEnvelope,extra:F(`BOUNCE_ENVELOPE_ENABLED`),valuePropName:`checked`,style:{marginBottom:0},children:(0,M.jsx)(y,{"aria-label":`BOUNCE_ENVELOPE_ENABLED`})})]})]})]})})]})}function P(e){return`${e.pathname}${e.search}${e.hash}`}function F(e){return(0,M.jsx)(u.Text,{type:`secondary`,code:!0,children:e})}function I(e,t){if(!e)return``;let n;try{n=new URL(String(e))}catch{return t.startsWith(`en`)?`Enter a valid absolute URL.`:`请输入有效的完整访问地址。`}let r=n.hostname===`localhost`||n.hostname===`127.0.0.1`||n.hostname===`::1`;return n.protocol!==`https:`&&!r?t.startsWith(`en`)?`Public instances must use HTTPS so API credentials are never sent over plaintext HTTP.`:`公网实例必须使用 HTTPS,避免 API 密钥通过明文 HTTP 传输。`:``}var L={publicUrl:`公开访问地址`,publicUrlInvalid:`公开访问地址不安全`,publicUrlRequired:`请输入公开访问地址`,mailHostname:`邮件服务器主机名`,sendingIp:`发信公网 IP`,spfMechanisms:`默认 SPF 扩展`,dmarcPolicy:`默认 DMARC 策略`,dmarcReports:`DMARC 报告邮箱`,unsubscribeEmail:`退订邮箱`,unsubscribeUrl:`退订链接`,abuseMailbox:`滥用举报邮箱`,csaMailbox:`CSA 投诉邮箱`,bounceAddress:`退信地址`,oneClickUnsubscribe:`启用一键退订`,feedbackId:`启用 Feedback-ID`,requireVerifiedDomain:`仅允许已验证域名发信`,bounceEnvelope:`启用退信信封地址`},R={publicUrl:`Public URL`,publicUrlInvalid:`Public URL is insecure`,publicUrlRequired:`Enter the public URL`,mailHostname:`Mail server hostname`,sendingIp:`Public sending IP`,spfMechanisms:`Default SPF mechanisms`,dmarcPolicy:`Default DMARC policy`,dmarcReports:`DMARC report mailbox`,unsubscribeEmail:`Unsubscribe mailbox`,unsubscribeUrl:`Unsubscribe URL`,abuseMailbox:`Abuse mailbox`,csaMailbox:`CSA complaints mailbox`,bounceAddress:`Bounce address`,oneClickUnsubscribe:`Enable one-click unsubscribe`,feedbackId:`Enable Feedback-ID`,requireVerifiedDomain:`Require a verified sending domain`,bounceEnvelope:`Enable bounce envelope address`};export{N as default};