From eed83039ab08c7ed88a6bf2c01c3d1f0ad299bdb Mon Sep 17 00:00:00 2001 From: hermes Date: Mon, 26 Oct 2026 10:30:29 +0800 Subject: [PATCH] =?UTF-8?q?fix(qa):=20=E9=82=AE=E4=BB=B6=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E6=9C=AA=E9=85=8D=E7=BD=AE=E6=97=B6=E8=BF=94=E5=9B=9E=E7=A9=BA?= =?UTF-8?q?=E6=94=B6=E4=BB=B6=E4=BA=BA=E6=95=B0=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 未初始化设置时 recipients 为 null,前端严格解析判为无效,导致周报页显示“响应无效”。 后端统一返回空数组,前端同时兼容历史的 null。 --- internal/qawemail/store.go | 5 ++++- web/src/qaWeeklyMail.ts | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/internal/qawemail/store.go b/internal/qawemail/store.go index 805d800..b250a7a 100644 --- a/internal/qawemail/store.go +++ b/internal/qawemail/store.go @@ -217,7 +217,7 @@ func normalize(input SettingsInput) (SettingsInput, error) { } func (s *Store) ReadSettings(ctx context.Context) (Settings, error) { - out := Settings{Port: 465, Weekday: 1, Hour: 9} + out := Settings{Port: 465, Weekday: 1, Hour: 9, Recipients: []string{}} if !s.valid() { return out, ErrUnavailable } @@ -230,6 +230,9 @@ func (s *Store) ReadSettings(ctx context.Context) (Settings, error) { if err != nil { return Settings{}, ErrUnavailable } + if out.Recipients == nil { + out.Recipients = []string{} + } out.HasPassword = len(sealed) > 0 return out, nil } diff --git a/web/src/qaWeeklyMail.ts b/web/src/qaWeeklyMail.ts index b70d757..94653a7 100644 --- a/web/src/qaWeeklyMail.ts +++ b/web/src/qaWeeklyMail.ts @@ -43,7 +43,8 @@ const num = (v: unknown): number => (typeof v === 'number' && Number.isSafeInteg export function parseWeeklyMailSettings(value: unknown): WeeklyMailSettings { const v = obj(value) - if (!Array.isArray(v.recipients) || v.recipients.some((item) => typeof item !== 'string')) return bad() + const recipients = v.recipients === null ? [] : v.recipients + if (!Array.isArray(recipients) || recipients.some((item) => typeof item !== 'string')) return bad() if (typeof v.enabled !== 'boolean' || typeof v.has_password !== 'boolean') return bad() const weekday = num(v.weekday), hour = num(v.hour), @@ -54,7 +55,7 @@ export function parseWeeklyMailSettings(value: unknown): WeeklyMailSettings { port, username: str(v.username), from: str(v.from), - recipients: v.recipients as string[], + recipients: recipients as string[], weekday, hour, enabled: v.enabled,