From a722788cc922aa1e7383c74c87a4bb3aa795ea12 Mon Sep 17 00:00:00 2001 From: anghunk Date: Mon, 19 Jan 2026 20:55:19 +0800 Subject: [PATCH] =?UTF-8?q?refactor(email):=20=E9=87=8D=E6=9E=84=E9=82=AE?= =?UTF-8?q?=E4=BB=B6=E9=80=9A=E7=9F=A5=E9=80=BB=E8=BE=91=E5=B9=B6=E6=94=B9?= =?UTF-8?q?=E8=BF=9B=E9=82=AE=E4=BB=B6=E6=A8=A1=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除对 EMAIL_ADDRESS 环境变量的依赖,统一从数据库获取管理员邮箱 - 重构邮件通知逻辑,增加管理员回复的验证 - 改进邮件模板的样式和内容 - 将 getAdminNotifyEmail 函数导出以供其他模块使用 --- .../src/api/admin/getAdminEmail.ts | 4 +- .../src/api/public/postComment.ts | 79 ++++++++----- cwd-comments-api/src/bindings.ts | 3 +- cwd-comments-api/src/utils/email.ts | 110 ++++++++++++------ 4 files changed, 124 insertions(+), 72 deletions(-) diff --git a/cwd-comments-api/src/api/admin/getAdminEmail.ts b/cwd-comments-api/src/api/admin/getAdminEmail.ts index 97be819..8782cca 100644 --- a/cwd-comments-api/src/api/admin/getAdminEmail.ts +++ b/cwd-comments-api/src/api/admin/getAdminEmail.ts @@ -9,8 +9,8 @@ export const getAdminEmail = async (c: Context<{ Bindings: Bindings }>) => { const row = await c.env.CWD_DB.prepare('SELECT value FROM Settings WHERE key = ?') .bind('admin_notify_email') .first<{ value: string }>(); - const email = row?.value || c.env.EMAIL_ADDRESS || null; - return c.json({ email: email }); + const email = row?.value || null; + return c.json({ email }); } catch (e: any) { return c.json({ message: e.message }, 500); } diff --git a/cwd-comments-api/src/api/public/postComment.ts b/cwd-comments-api/src/api/public/postComment.ts index 9de7f0d..6d03515 100644 --- a/cwd-comments-api/src/api/public/postComment.ts +++ b/cwd-comments-api/src/api/public/postComment.ts @@ -1,7 +1,7 @@ import { Context } from 'hono'; import { UAParser } from 'ua-parser-js'; import { Bindings } from '../../bindings'; -import { sendCommentNotification, sendCommentReplyNotification, isValidEmail } from '../../utils/email'; +import { sendCommentNotification, sendCommentReplyNotification, isValidEmail, getAdminNotifyEmail } from '../../utils/email'; // 检查内容,将