From e12a51cd19b16ea985dbb6e998eb5a78a184f9e5 Mon Sep 17 00:00:00 2001 From: npmrun <1549469775@qq.com> Date: Mon, 20 Apr 2026 21:17:12 +0800 Subject: [PATCH] fix(config): keep smtp password readiness after masking Made-with: Cursor --- app/pages/me/admin/config/index.vue | 12 ++++++++++-- server/api/config/global.get.ts | 13 ++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/app/pages/me/admin/config/index.vue b/app/pages/me/admin/config/index.vue index 6e2a64c..d619a5b 100644 --- a/app/pages/me/admin/config/index.vue +++ b/app/pages/me/admin/config/index.vue @@ -16,6 +16,7 @@ type GlobalConfigPayload = { commentSmtpSecure: boolean commentSmtpUser: string commentSmtpPass: string + commentSmtpPassConfigured?: boolean } } @@ -38,18 +39,20 @@ const commentSmtpPort = ref(465) const commentSmtpSecure = ref(true) const commentSmtpUser = ref('') const commentSmtpPass = ref('') +const commentSmtpPassConfigured = ref(false) const commentEmailConfigReady = computed(() => { const from = commentMailFromEmail.value.trim() const host = commentSmtpHost.value.trim() const user = commentSmtpUser.value.trim() const pass = commentSmtpPass.value.trim() + const hasPass = pass.length > 0 || commentSmtpPassConfigured.value const port = Number(commentSmtpPort.value) return ( from.length > 0 && host.length > 0 && user.length > 0 - && pass.length > 0 + && hasPass && Number.isFinite(port) && port >= 1 && port <= 65535 @@ -77,7 +80,10 @@ async function load() { commentSmtpPort.value = cfg.commentSmtpPort commentSmtpSecure.value = cfg.commentSmtpSecure commentSmtpUser.value = cfg.commentSmtpUser - commentSmtpPass.value = cfg.commentSmtpPass + commentSmtpPass.value = '' + commentSmtpPassConfigured.value = typeof cfg.commentSmtpPassConfigured === 'boolean' + ? cfg.commentSmtpPassConfigured + : false } finally { loading.value = false } @@ -111,6 +117,8 @@ async function save() { const nextCommentSmtpPass = commentSmtpPass.value.trim() if (nextCommentSmtpPass.length > 0) { await putKey('commentSmtpPass', nextCommentSmtpPass) + commentSmtpPassConfigured.value = true + commentSmtpPass.value = '' } await load() await refreshGlobalConfig() diff --git a/server/api/config/global.get.ts b/server/api/config/global.get.ts index c97bad2..41e04f5 100644 --- a/server/api/config/global.get.ts +++ b/server/api/config/global.get.ts @@ -20,7 +20,18 @@ export default defineWrappedResponseHandler(async (event) => { }), ); + const config = Object.fromEntries(entries); + if (!isAdmin) { + return R.success({ config }); + } + + const smtpPassRaw = await event.context.config.getGlobal("commentSmtpPass"); + const commentSmtpPassConfigured = typeof smtpPassRaw === "string" && smtpPassRaw.trim().length > 0; + return R.success({ - config: Object.fromEntries(entries), + config: { + ...config, + commentSmtpPassConfigured, + }, }); });