码桶
发现社区成员的开源项目
Settings-Dp7hZelb.js17.5 KB
import{Y as de,a5 as ce,R as X,u as pe,bn as me,r as c,j as e,T as l,B as h,F as j,S as k,C as he,b as u}from"./index-GWuvg2UH.js";import{B as R}from"./index-DihvOmSo.js";import{C as T}from"./index-BVKuUSRW.js";import{M as ge}from"./Modal-08QhW3n9.js";import{F as G}from"./textarea-BIzdQNE8.js";import{I as K}from"./index-BMbdBPA2.js";import{R as ye,a as xe}from"./index-DIHsQVbu.js";import{S as ue}from"./index-CfWZ9ycl.js";import{T as o}from"./index-BW_2QB9V.js";import{I as fe}from"./IconRefresh-BRkV1NtY.js";import"./IconTickCircle-BYgwCdAe.js";import"./index-BZDftoba.js";import"./_baseDifference-DopHgqVv.js";import"./object-DkPZvw8u.js";const je={PREFIX:`${de}`};var _e=function(s,p){var y={};for(var d in s)Object.prototype.hasOwnProperty.call(s,d)&&p.indexOf(d)<0&&(y[d]=s[d]);if(s!=null&&typeof Object.getOwnPropertySymbols=="function")for(var g=0,d=Object.getOwnPropertySymbols(s);g<d.length;g++)p.indexOf(d[g])<0&&Object.prototype.propertyIsEnumerable.call(s,d[g])&&(y[d[g]]=s[d[g]]);return y};const _=je.PREFIX,B=s=>{const{layout:p="horizontal",dashed:y,align:d="center",className:g,margin:x,style:C,children:f}=s,b=_e(s,["layout","dashed","align","className","margin","style","children"]),z=ce(`${_}-divider`,g,{[`${_}-divider-horizontal`]:p==="horizontal",[`${_}-divider-vertical`]:p==="vertical",[`${_}-divider-dashed`]:!!y,[`${_}-divider-with-text`]:f&&p==="horizontal",[`${_}-divider-with-text-${d}`]:f&&p==="horizontal"});let v={};return x!==void 0&&(p==="vertical"?v={marginLeft:x,marginRight:x}:p==="horizontal"&&(v={marginTop:x,marginBottom:x})),X.createElement("div",Object.assign({},b,{className:z,style:Object.assign(Object.assign({},v),C)}),f&&p==="horizontal"?typeof f=="string"?X.createElement("span",{className:`${_}-divider_inner-text`,"x-semi-prop":"children"},f):f:null)},w="ui-monospace,SFMono-Regular,Consolas,Menlo,monospace";function Oe(){const{t:s}=pe(),p=me(),y=!!(p&&p.is_admin),[d,g]=c.useState(!0),[x,C]=c.useState(!1),[f,b]=c.useState(!1),[z,v]=c.useState(""),[i,V]=c.useState(null),[H,q]=c.useState(""),[r,E]=c.useState(null),[Y,N]=c.useState(!1),[J,W]=c.useState(!1),[n,L]=c.useState(null),[Q,M]=c.useState(!1),[U,$]=c.useState(""),[A,I]=c.useState(!1),Z=async()=>{M(!0),$("");try{L(await u.ipCheck())}catch(t){L(null),$(t&&t.message?t.message:String(t))}finally{M(!1)}},ee=async()=>{I(!0);try{await u.settingsSave({ip_source:i.ip_source||"remote_addr",ip_source_header:String(i.ip_source_header??"").trim()}),o.success(s("setSaved")),await S()}catch(t){o.error(t.message)}finally{I(!1)}},se=async t=>{I(!0);try{await u.settingsSave({ip_source:t}),V(m=>({...m,ip_source:t})),o.success(s("setSaved")),await S()}catch(m){o.error(m.message)}finally{I(!1)}},S=async()=>{g(!0);try{const t=await u.settingsGet();V(t),v(""),u.settingsVersion().then(E).catch(()=>{})}catch(t){v(t.message)}finally{g(!1)}};if(c.useEffect(()=>{y?S():g(!1)},[y]),!y)return e.jsxs("div",{className:"page",children:[e.jsx(l.Title,{heading:5,style:{marginBottom:12},children:s("settings")}),e.jsx(R,{type:"warning",description:s("setAdminOnly")})]});const a=(t,m)=>V(D=>({...D,[t]:m})),F=async()=>{if((i.ip_source||"remote_addr")==="custom"&&String(i.ip_source_header??"").trim()===""){o.error(s("setIpHeaderRequired"));return}C(!0);try{await u.settingsSave({registration_enabled:i.registration_enabled,email_verify_enabled:i.email_verify_enabled,collect_enabled:i.collect_enabled,alert_enabled:i.alert_enabled,bot_filter_enabled:i.bot_filter_enabled,retention_days:String(i.retention_days??"").trim(),screen_password:String(i.screen_password??""),sdk_snippet:String(i.sdk_snippet??"").trim(),inject_code:String(i.inject_code??"").trim(),ip_source:i.ip_source||"remote_addr",ip_source_header:String(i.ip_source_header??"").trim(),smtp_host:i.smtp_host,smtp_port:i.smtp_port,smtp_secure:i.smtp_secure,smtp_username:i.smtp_username,smtp_password:i.smtp_password,smtp_from_name:i.smtp_from_name,smtp_from_email:i.smtp_from_email}),o.success(s("setSaved")),await S()}catch(t){o.error(t.message)}finally{C(!1)}},te=async()=>{if(!H)return o.error(s("setTestTo"));b(!0);try{const t=await u.settingsEmailTest(H);t&&t.ok?o.success(s("setTestOk")+"("+(t.via||"")+")"):o.error(t&&t.msg||s("setTestFail"))}catch(t){o.error(t.message)}finally{b(!1)}},ie=[{key:"registration_enabled",title:s("setRegTitle"),desc:s("setRegDesc")},{key:"email_verify_enabled",title:s("setEmailVerify"),desc:s("setEmailVerifyDesc"),warn:i&&i.captcha_ready?"":s("setEmailVerifyWarn")},{key:"collect_enabled",title:s("setCollectTitle"),desc:s("setCollectDesc")},{key:"alert_enabled",title:s("setAlertTitle"),desc:s("setAlertDesc")},{key:"bot_filter_enabled",title:s("setBotTitle"),desc:s("setBotDesc")}],re=async()=>{N(!0);try{const t=await u.settingsVersion();E(t||{}),t&&t.has_update?o.warning(s("setVerNew")+":"+t.latest):t&&t.latest&&o.success(s("setVerUpToDate"))}catch(t){o.error(t.message)}finally{N(!1)}},le=()=>{ge.confirm({title:s("setVerUpgrade"),content:s("setVerUpgradeConfirm"),okText:s("setVerUpgrade"),okButtonProps:{type:"warning",theme:"solid"},onOk:async()=>{W(!0);try{const t=await u.settingsUpdate();o.success(t&&t.notice||s("setVerUpgraded")),await S()}catch(t){o.error(t.message)}finally{W(!1)}}})},O=String(i&&i.sdk_snippet||"").trim(),P=i&&i.sdk_snippet_default||"",ne=O||P,ae=O!==""&&!/\{site_key\}/.test(O),oe=ne.replace(/\{site_key\}/g,"sk_3f9a1c7d2e").replace(/\{(?:host|origin)\}/g,typeof location<"u"&&location.origin||"https://stats.example.com");return e.jsxs("div",{className:"page",children:[e.jsxs("div",{className:"toolbar",children:[e.jsx(l.Title,{heading:5,style:{margin:0},children:s("settings")}),e.jsx(h,{icon:e.jsx(fe,{}),size:"small",theme:"borderless",onClick:S,children:s("alRefresh")})]}),z&&e.jsx(R,{type:"danger",description:z,style:{marginBottom:12},closeIcon:null}),d&&!i?e.jsx(l.Text,{type:"tertiary",children:s("loading")||"…"}):i?e.jsxs(e.Fragment,{children:[e.jsx(T,{title:s("setTogglesTitle"),style:{marginBottom:16},children:e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:18},children:[ie.map(t=>e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:24},children:[e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontWeight:600,marginBottom:2},children:t.title}),e.jsx("div",{style:{fontSize:13,color:"#86909c",lineHeight:1.6},children:t.desc}),t.warn&&e.jsxs("div",{style:{fontSize:13,color:"#d4380d",lineHeight:1.6,marginTop:4},children:["⚠ ",t.warn]})]}),e.jsx(ue,{checked:(i[t.key]??"1")==="1"||i[t.key]===1,onChange:m=>a(t.key,m?"1":"0")})]},t.key)),e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:24},children:[e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontWeight:600,marginBottom:2},children:s("setRetention")}),e.jsx("div",{style:{fontSize:13,color:"#86909c",lineHeight:1.6},children:s("setRetentionDesc")})]}),e.jsx(K,{value:i.retention_days===""||i.retention_days==null?void 0:Number(i.retention_days),onChange:t=>a("retention_days",t==null?"":String(t)),min:30,max:3650,style:{width:140},placeholder:s("setRetentionPH")})]}),e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:24},children:[e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontWeight:600,marginBottom:2},children:s("setScreenPwd")}),e.jsx("div",{style:{fontSize:13,color:"#86909c",lineHeight:1.6},children:s("setScreenPwdDesc")})]}),e.jsx(j,{mode:"password",value:i.screen_password==="******"?"******":String(i.screen_password??""),onChange:t=>a("screen_password",t),placeholder:s("setScreenPwdPH"),style:{width:220}})]})]})}),e.jsxs(T,{title:s("setSdkTitle"),style:{marginBottom:16},children:[e.jsx("div",{style:{fontSize:13,color:"#86909c",lineHeight:1.7,marginBottom:10},children:s("setSdkDesc")}),e.jsx(G,{value:String(i.sdk_snippet??""),onChange:t=>a("sdk_snippet",t),autosize:{minRows:3,maxRows:10},placeholder:P,style:{fontFamily:"ui-monospace,SFMono-Regular,Consolas,Menlo,monospace",fontSize:12.5}}),e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,flexWrap:"wrap",marginTop:10},children:[e.jsx(l.Text,{type:"tertiary",size:"small",children:s("setSdkPh")}),e.jsxs(k,{children:[e.jsx(h,{size:"small",onClick:()=>a("sdk_snippet",P),children:s("setSdkUseDefault")}),e.jsx(h,{size:"small",onClick:()=>a("sdk_snippet",""),children:s("setSdkReset")}),e.jsx(h,{theme:"solid",size:"small",loading:x,onClick:F,children:s("save")})]})]}),ae?e.jsxs("div",{style:{fontSize:13,color:"#d4380d",lineHeight:1.6,marginTop:8},children:["⚠ ",s("setSdkNoKey")]}):null,e.jsxs("div",{style:{marginTop:14},children:[e.jsx("div",{style:{fontWeight:600,marginBottom:6,fontSize:13},children:s("setSdkPreview")}),e.jsx("pre",{style:{background:"#0f172a",color:"#e2e8f0",padding:"10px 12px",borderRadius:8,margin:0,fontSize:12.5,overflowX:"auto",whiteSpace:"pre-wrap",wordBreak:"break-all"},children:oe})]})]}),e.jsxs(T,{title:s("setInjTitle"),style:{marginBottom:16},children:[e.jsx("div",{style:{fontSize:13,color:"#86909c",lineHeight:1.7,marginBottom:10},children:s("setInjDesc")}),e.jsx(G,{value:String(i.inject_code??""),onChange:t=>a("inject_code",t),autosize:{minRows:3,maxRows:12},placeholder:s("setInjPh"),style:{fontFamily:"ui-monospace,SFMono-Regular,Consolas,Menlo,monospace",fontSize:12.5}}),e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,flexWrap:"wrap",marginTop:10},children:[e.jsx(l.Text,{type:"tertiary",size:"small",children:s("setInjPos")}),e.jsxs(k,{children:[e.jsx(h,{size:"small",onClick:()=>a("inject_code",""),children:s("setSdkReset")}),e.jsx(h,{theme:"solid",size:"small",loading:x,onClick:F,children:s("save")})]})]})]}),e.jsxs(T,{title:s("setIpTitle"),style:{marginBottom:16},children:[e.jsx("div",{style:{fontSize:13,color:"#86909c",lineHeight:1.7,marginBottom:10},children:s("setIpDesc")}),e.jsx(ye,{value:i.ip_source||"remote_addr",onChange:t=>a("ip_source",t.target.value),direction:"vertical",children:[["x_forwarded_for","X-Forwarded-For",s("setIpOptXffHint")],["x_real_ip","X-Real-IP",s("setIpOptXriHint")],["remote_addr","REMOTE_ADDR",s("setIpOptRemoteHint")],["custom",s("setIpOptCustom"),s("setIpOptCustomHint")]].map(([t,m,D])=>e.jsxs(xe,{value:t,style:{marginBottom:4},children:[e.jsx("span",{style:{fontFamily:w,fontSize:13},children:m}),e.jsx("div",{style:{fontSize:12,color:"#86909c",lineHeight:1.6},children:D})]},t))}),i.ip_source==="custom"&&e.jsxs("div",{style:{marginTop:8,maxWidth:380},children:[e.jsx(l.Text,{type:"tertiary",size:"small",children:s("setIpHeaderLabel")}),e.jsx(j,{value:i.ip_source_header||"",placeholder:s("setIpHeaderPh"),onChange:t=>a("ip_source_header",t)})]}),e.jsxs(k,{style:{marginTop:12},children:[e.jsx(h,{theme:"solid",size:"small",loading:A,onClick:ee,children:s("save")}),e.jsx(h,{size:"small",loading:Q,onClick:Z,children:s("setIpRun")}),e.jsx(l.Text,{type:"tertiary",size:"small",children:s("setIpRunHint")})]}),U!==""&&e.jsx("div",{style:{marginTop:10},children:e.jsx(R,{type:"danger",description:s("setIpFail")+U,closable:!1})}),n&&e.jsxs("div",{style:{marginTop:12},children:[e.jsx(B,{margin:"0 0 8px"}),e.jsx(l.Text,{type:"tertiary",size:"small",children:s("setIpCand")}),e.jsx("div",{style:{marginTop:6,border:"1px solid var(--semi-color-border, #e5e6eb)",borderRadius:6,overflow:"hidden"},children:(n.candidates||[]).map(t=>e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"150px 1fr 110px",gap:8,padding:"6px 10px",fontSize:12.5,alignItems:"center",background:t.current?"rgba(0,100,250,0.06)":"transparent"},children:[e.jsx("span",{style:{fontFamily:w,wordBreak:"break-all"},children:t.label}),e.jsx("span",{style:{fontFamily:w,wordBreak:"break-all",color:t.ok?"#1d2129":"#c9cdd4"},children:t.value||s("setIpNoHeader")}),e.jsx("span",{style:{textAlign:"right"},children:t.current?e.jsxs("span",{style:{color:"#00b42a",fontWeight:600},children:["✓ ",s("setIpCurrent")]}):t.key==="custom"&&!t.header?null:e.jsx(h,{size:"small",theme:"borderless",loading:A,onClick:()=>se(t.key),children:s("setIpUse")})})]},t.key))}),e.jsx("div",{style:{marginTop:6,fontSize:12,color:"#86909c",lineHeight:1.7},children:s("setIpCandHint")}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"10px 20px",marginTop:12},children:[e.jsxs("div",{children:[e.jsx(l.Text,{type:"tertiary",size:"small",children:s("setIpRemote")}),e.jsx("div",{style:{fontFamily:w,fontSize:13,marginTop:2,wordBreak:"break-all"},children:(n.remote||"-")+(n.remote_cdn?" ("+n.remote_cdn+")":"")})]}),e.jsxs("div",{children:[e.jsx(l.Text,{type:"tertiary",size:"small",children:s("setIpApplied")}),e.jsx("div",{style:{fontFamily:w,fontSize:13,marginTop:2,wordBreak:"break-all"},children:(n.ip||"-")+" ← "+(n.source||"-")})]}),e.jsxs("div",{children:[e.jsx(l.Text,{type:"tertiary",size:"small",children:s("setIpGeo")}),e.jsxs("div",{style:{fontSize:13,marginTop:2},children:[n.geo_ok?[n.geo&&n.geo.country,n.geo&&n.geo.province,n.geo&&n.geo.city].filter(Boolean).join(" / "):s("setIpNone"),n.ip?e.jsx("span",{style:{marginLeft:6,fontSize:12,color:"#86909c"},children:n.is_ipv6?"IPv6":"IPv4"}):null]})]})]}),(n.advice||[]).length>0&&e.jsxs("div",{style:{marginTop:12},children:[e.jsx(B,{margin:"0 0 8px"}),e.jsx(l.Text,{type:"tertiary",size:"small",children:s("setIpAdvice")}),e.jsx("ul",{style:{margin:"6px 0 0",paddingLeft:20,fontSize:13,lineHeight:1.8,color:"#4e5969"},children:(n.advice||[]).map((t,m)=>e.jsx("li",{children:t},String(m)))})]})]})]}),e.jsxs(T,{title:s("setMailTitle"),children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"14px 20px"},children:[e.jsxs("div",{children:[e.jsx(l.Text,{type:"tertiary",size:"small",children:s("setSmtpHost")}),e.jsx(j,{value:i.smtp_host,onChange:t=>a("smtp_host",t),placeholder:"smtp.example.com",style:{marginTop:4}})]}),e.jsxs("div",{children:[e.jsx(l.Text,{type:"tertiary",size:"small",children:s("setSmtpPort")}),e.jsx(K,{value:Number(i.smtp_port)||465,onChange:t=>a("smtp_port",String(t??465)),min:1,max:65535,style:{width:"100%",marginTop:4}})]}),e.jsxs("div",{children:[e.jsx(l.Text,{type:"tertiary",size:"small",children:s("setSmtpSecure")}),e.jsx(he,{value:i.smtp_secure||"ssl",onChange:t=>a("smtp_secure",t),style:{width:"100%",marginTop:4},optionList:[{value:"ssl",label:"SSL(465)"},{value:"tls",label:"STARTTLS(587)"},{value:"none",label:s("setSecureNone")}]})]}),e.jsxs("div",{children:[e.jsx(l.Text,{type:"tertiary",size:"small",children:s("setSmtpUser")}),e.jsx(j,{value:i.smtp_username,onChange:t=>a("smtp_username",t),style:{marginTop:4}})]}),e.jsxs("div",{children:[e.jsx(l.Text,{type:"tertiary",size:"small",children:s("setSmtpPass")}),e.jsx(j,{mode:"password",value:i.smtp_password,onChange:t=>a("smtp_password",t),placeholder:s("setSmtpPassHint"),style:{marginTop:4}})]}),e.jsxs("div",{children:[e.jsx(l.Text,{type:"tertiary",size:"small",children:s("setFromName")}),e.jsx(j,{value:i.smtp_from_name,onChange:t=>a("smtp_from_name",t),style:{marginTop:4}})]}),e.jsxs("div",{style:{gridColumn:"1 / -1"},children:[e.jsx(l.Text,{type:"tertiary",size:"small",children:s("setFromEmail")}),e.jsx(j,{value:i.smtp_from_email,onChange:t=>a("smtp_from_email",t),placeholder:"[email protected]",style:{marginTop:4}})]})]}),e.jsx(B,{margin:16}),e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:12,flexWrap:"wrap"},children:[e.jsx(l.Text,{type:"tertiary",size:"small",children:s("setMailHint")}),e.jsxs(k,{children:[e.jsx(j,{value:H,onChange:q,placeholder:s("setTestTo"),style:{width:240},size:"small"}),e.jsx(h,{size:"small",loading:f,onClick:te,children:s("setTestBtn")}),e.jsx(h,{theme:"solid",size:"small",loading:x,onClick:F,children:s("save")})]})]})]}),e.jsxs(T,{title:s("setVerTitle"),style:{marginTop:16},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:12,flexWrap:"wrap"},children:[e.jsxs("div",{style:{minWidth:240},children:[e.jsxs("div",{style:{fontWeight:600,marginBottom:2},children:[s("setVerCur"),":v",r&&r.version||"…"]}),e.jsx("div",{style:{fontSize:13,color:"#86909c",lineHeight:1.6},children:r?r.latest?`${s("setVerLatest")}:v${r.latest} · ${r.has_update?s("setVerNew"):s("setVerUpToDate")}`:r.msg||s("setVerFail"):s("setVerDesc")}),r&&r.has_update&&r.released_at?e.jsxs("div",{style:{fontSize:12,color:"#86909c",marginTop:2},children:[s("setVerReleased"),":",r.released_at]}):null]}),e.jsxs(k,{children:[r&&r.has_update&&r.can_auto?e.jsx(h,{type:"warning",theme:"solid",size:"small",loading:J,onClick:le,children:s("setVerUpgrade")}):null,r&&r.has_update&&!r.can_auto&&r.full_url?e.jsx("a",{href:r.full_url,target:"_blank",rel:"noreferrer",style:{fontSize:13,lineHeight:"28px"},children:s("setVerDownloadFull")}):null,e.jsx(h,{size:"small",loading:Y,onClick:re,children:s("setVerCheck")})]})]}),r&&r.has_update&&r.reason?e.jsx("div",{style:{marginTop:12},children:e.jsx(R,{type:r.can_auto?"info":"warning",description:r.reason})}):null,r&&r.changelog&&r.changelog.length?e.jsxs("div",{style:{marginTop:14},children:[e.jsx("div",{style:{fontWeight:600,marginBottom:6,fontSize:13},children:s("setVerChanges")}),e.jsx("ul",{style:{margin:0,paddingLeft:20,fontSize:13,color:"#4e5969",lineHeight:1.8},children:r.changelog.map((t,m)=>e.jsx("li",{children:t},m))})]}):null,r&&r.notes?e.jsx("div",{style:{marginTop:8,fontSize:13,color:"#86909c"},children:r.notes}):null,e.jsx(B,{margin:14}),e.jsxs("div",{style:{display:"flex",gap:18,flexWrap:"wrap",fontSize:12,color:"#86909c"},children:[e.jsxs("span",{children:[s("setVerLayout"),":",r&&r.layout?r.layout:"—"]}),e.jsxs("span",{children:[s("setVerBackups"),":",r&&r.backups&&r.backups.length?r.backups.map(t=>t.name).join("、"):s("setVerNoBackup")]}),r&&r.update_enabled===!1?e.jsx("span",{children:s("setVerOff")}):null]})]})]}):null]})}export{Oe as default};