未初始化设置时 recipients 为 null,前端严格解析判为无效,导致周报页显示“响应无效”。 后端统一返回空数组,前端同时兼容历史的 null。
This commit is contained in:
@@ -217,7 +217,7 @@ func normalize(input SettingsInput) (SettingsInput, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Store) ReadSettings(ctx context.Context) (Settings, 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() {
|
if !s.valid() {
|
||||||
return out, ErrUnavailable
|
return out, ErrUnavailable
|
||||||
}
|
}
|
||||||
@@ -230,6 +230,9 @@ func (s *Store) ReadSettings(ctx context.Context) (Settings, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return Settings{}, ErrUnavailable
|
return Settings{}, ErrUnavailable
|
||||||
}
|
}
|
||||||
|
if out.Recipients == nil {
|
||||||
|
out.Recipients = []string{}
|
||||||
|
}
|
||||||
out.HasPassword = len(sealed) > 0
|
out.HasPassword = len(sealed) > 0
|
||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,8 @@ const num = (v: unknown): number => (typeof v === 'number' && Number.isSafeInteg
|
|||||||
|
|
||||||
export function parseWeeklyMailSettings(value: unknown): WeeklyMailSettings {
|
export function parseWeeklyMailSettings(value: unknown): WeeklyMailSettings {
|
||||||
const v = obj(value)
|
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()
|
if (typeof v.enabled !== 'boolean' || typeof v.has_password !== 'boolean') return bad()
|
||||||
const weekday = num(v.weekday),
|
const weekday = num(v.weekday),
|
||||||
hour = num(v.hour),
|
hour = num(v.hour),
|
||||||
@@ -54,7 +55,7 @@ export function parseWeeklyMailSettings(value: unknown): WeeklyMailSettings {
|
|||||||
port,
|
port,
|
||||||
username: str(v.username),
|
username: str(v.username),
|
||||||
from: str(v.from),
|
from: str(v.from),
|
||||||
recipients: v.recipients as string[],
|
recipients: recipients as string[],
|
||||||
weekday,
|
weekday,
|
||||||
hour,
|
hour,
|
||||||
enabled: v.enabled,
|
enabled: v.enabled,
|
||||||
|
|||||||
Reference in New Issue
Block a user