fix(qa): 邮件设置未配置时返回空收件人数组
build / build (push) Successful in 1m14s

未初始化设置时 recipients 为 null,前端严格解析判为无效,导致周报页显示“响应无效”。
后端统一返回空数组,前端同时兼容历史的 null。
This commit is contained in:
hermes
2026-10-26 10:30:29 +08:00
parent 43b1e423fe
commit eed83039ab
2 changed files with 7 additions and 3 deletions
+4 -1
View File
@@ -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
}
+3 -2
View File
@@ -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,