周报页新增自动发送区:管理员配置 SMTP/收件人/发送星期与小时,授权码用主密钥加密保存。 确认绑定当前草稿版本与正文哈希,正文再改则确认失效;worker 每分钟仅在启用、到点、周已结束且未发送过时发一次。 邮件同时提供渲染后的 HTML 与可读纯文本;SMTP 仅允许 TLS,拒绝明文。 迁移 000060 新增设置、确认与发送记录三张表,唯一键防重复发送。
This commit is contained in:
@@ -7,6 +7,7 @@ import { weeklyTransport } from './qaWeeklyDraftAPI'
|
||||
import { buildQAWeeklyCSV, downloadQAWeekly, weeklyQualitySourceLabel } from './qaWeekly'
|
||||
import { QAAnswerMarkdown } from './QAAnswerMarkdown'
|
||||
import { copyRenderedWeeklyReport } from './qaWeeklyClipboard'
|
||||
import { QAWeeklyMail } from './QAWeeklyMail'
|
||||
import { QAPeriodInput } from './QAPeriodInput'
|
||||
import './qaWeeklyEditor.css'
|
||||
type LeaveGuard = (() => Promise<boolean>) | null
|
||||
@@ -175,6 +176,7 @@ export function QAWeekly({ onBeforeLeave }: Props) {
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
<QAWeeklyMail week={state.week} busy={blocked} />
|
||||
<div className="qa-weekly-editor-toolbar">
|
||||
<span role="status" aria-live="polite" className="qa-weekly-editor-status" data-weekly-save-state={status}>
|
||||
自动保存 ·{' '}
|
||||
|
||||
@@ -0,0 +1,253 @@
|
||||
import { useCallback, useEffect, useState } from 'react'
|
||||
import { useOptionalAuth } from './auth'
|
||||
import {
|
||||
confirmWeeklyMail,
|
||||
fetchWeeklyMailConfirmation,
|
||||
fetchWeeklyMailSends,
|
||||
fetchWeeklyMailSettings,
|
||||
saveWeeklyMailSettings,
|
||||
weeklyMailWeekdayLabels,
|
||||
} from './qaWeeklyMail'
|
||||
import type { WeeklyMailConfirmation, WeeklyMailSend, WeeklyMailSettings } from './qaWeeklyMail'
|
||||
import './qaWeeklyMail.css'
|
||||
|
||||
const stamp = (value: string) => (value ? new Date(value).toLocaleString('zh-CN', { hour12: false }) : '—')
|
||||
|
||||
export function QAWeeklyMail({ week, busy }: { week: string; busy: boolean }) {
|
||||
const auth = useOptionalAuth()
|
||||
const admin = auth?.identity?.role === 'admin'
|
||||
const [confirmation, setConfirmation] = useState<WeeklyMailConfirmation | null>(null)
|
||||
const [settings, setSettings] = useState<WeeklyMailSettings | null>(null)
|
||||
const [sends, setSends] = useState<WeeklyMailSend[]>([])
|
||||
const [error, setError] = useState('')
|
||||
const [notice, setNotice] = useState('')
|
||||
const [working, setWorking] = useState(false)
|
||||
const [editing, setEditing] = useState(false)
|
||||
|
||||
const reload = useCallback(async () => {
|
||||
setError('')
|
||||
try {
|
||||
const [nextConfirmation, nextSends, nextSettings] = await Promise.all([
|
||||
fetchWeeklyMailConfirmation(week),
|
||||
fetchWeeklyMailSends(week),
|
||||
admin ? fetchWeeklyMailSettings() : Promise.resolve(null),
|
||||
])
|
||||
setConfirmation(nextConfirmation)
|
||||
setSends(nextSends)
|
||||
if (nextSettings) setSettings(nextSettings)
|
||||
} catch (reason) {
|
||||
setError(reason instanceof Error ? reason.message : '周报邮件状态读取失败')
|
||||
}
|
||||
}, [week, admin])
|
||||
|
||||
useEffect(() => {
|
||||
void reload()
|
||||
}, [reload])
|
||||
|
||||
const toggleConfirm = async (confirm: boolean) => {
|
||||
if (working) return
|
||||
setWorking(true)
|
||||
setError('')
|
||||
setNotice('')
|
||||
try {
|
||||
const next = await confirmWeeklyMail(week, confirm)
|
||||
setConfirmation(next)
|
||||
setNotice(confirm ? '已确认本周周报;到设定时间会自动发送,正文改动后需重新确认' : '已取消确认,不会自动发送')
|
||||
setSends(await fetchWeeklyMailSends(week))
|
||||
} catch (reason) {
|
||||
setError(reason instanceof Error ? reason.message : '确认失败')
|
||||
} finally {
|
||||
setWorking(false)
|
||||
}
|
||||
}
|
||||
|
||||
const stale = confirmation !== null && !confirmation.current
|
||||
return (
|
||||
<section className="qa-weekly-mail" aria-label="周报自动发送">
|
||||
<header>
|
||||
<h4>自动发送</h4>
|
||||
<span className="qa-weekly-mail-state" data-state={!confirmation ? 'none' : stale ? 'stale' : 'confirmed'}>
|
||||
{!confirmation
|
||||
? '未确认'
|
||||
: stale
|
||||
? `已过期(确认于第${confirmation.draft_revision}版,正文已改,需重新确认)`
|
||||
: `已确认 · 第${confirmation.draft_revision}版 · ${stamp(confirmation.confirmed_at)} · ${confirmation.confirmed_by}`}
|
||||
</span>
|
||||
<div className="qa-weekly-mail-actions">
|
||||
{confirmation ? (
|
||||
<button type="button" disabled={working || busy} onClick={() => void toggleConfirm(false)}>
|
||||
取消确认
|
||||
</button>
|
||||
) : (
|
||||
<button type="button" disabled={working || busy} onClick={() => void toggleConfirm(true)}>
|
||||
确认本周周报
|
||||
</button>
|
||||
)}
|
||||
{admin ? (
|
||||
<button type="button" disabled={working} onClick={() => setEditing(!editing)}>
|
||||
{editing ? '收起发送设置' : '发送设置'}
|
||||
</button>
|
||||
) : null}
|
||||
</div>
|
||||
</header>
|
||||
{error ? (
|
||||
<p role="alert" className="error-banner">
|
||||
{error}
|
||||
</p>
|
||||
) : null}
|
||||
{notice ? <p role="status">{notice}</p> : null}
|
||||
{settings ? (
|
||||
<p className="qa-weekly-mail-summary">
|
||||
{settings.enabled ? '自动发送已启用' : '自动发送未启用'} ·{' '}
|
||||
{settings.host ? `${settings.host}:${settings.port}` : '未配置邮件服务器'} ·{' '}
|
||||
{settings.recipients.length ? `${settings.recipients.length} 位收件人` : '未配置收件人'} ·{' '}
|
||||
{weeklyMailWeekdayLabels[settings.weekday - 1] ?? '—'} {String(settings.hour).padStart(2, '0')}:00(北京时间)
|
||||
{settings.has_password ? '' : ' · 未保存授权码'}
|
||||
</p>
|
||||
) : null}
|
||||
{editing && settings ? (
|
||||
<SettingsForm
|
||||
settings={settings}
|
||||
onSaved={(next) => {
|
||||
setSettings(next)
|
||||
setEditing(false)
|
||||
setNotice('发送设置已保存')
|
||||
}}
|
||||
/>
|
||||
) : null}
|
||||
{sends.length ? (
|
||||
<ul className="qa-weekly-mail-sends">
|
||||
{sends.map((send) => (
|
||||
<li key={send.week + ':' + send.draft_revision} data-status={send.status}>
|
||||
{send.week} · 第{send.draft_revision}版 ·{' '}
|
||||
{{ sending: '发送中', sent: '已发送', failed: '发送失败' }[send.status]} · {stamp(send.updated_at)}
|
||||
{send.last_error ? ` · ${send.last_error}` : ''}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
) : null}
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
function SettingsForm({
|
||||
settings,
|
||||
onSaved,
|
||||
}: {
|
||||
settings: WeeklyMailSettings
|
||||
onSaved: (next: WeeklyMailSettings) => void
|
||||
}) {
|
||||
const [host, setHost] = useState(settings.host)
|
||||
const [port, setPort] = useState(String(settings.port))
|
||||
const [username, setUsername] = useState(settings.username)
|
||||
const [password, setPassword] = useState('')
|
||||
const [clearPassword, setClearPassword] = useState(false)
|
||||
const [from, setFrom] = useState(settings.from)
|
||||
const [recipients, setRecipients] = useState(settings.recipients.join('\n'))
|
||||
const [weekday, setWeekday] = useState(settings.weekday)
|
||||
const [hour, setHour] = useState(String(settings.hour))
|
||||
const [enabled, setEnabled] = useState(settings.enabled)
|
||||
const [error, setError] = useState('')
|
||||
const [saving, setSaving] = useState(false)
|
||||
|
||||
const submit = async () => {
|
||||
setSaving(true)
|
||||
setError('')
|
||||
try {
|
||||
const next = await saveWeeklyMailSettings(settings.revision, {
|
||||
host: host.trim(),
|
||||
port: Number(port),
|
||||
username: username.trim(),
|
||||
password,
|
||||
clear_password: clearPassword,
|
||||
from: from.trim(),
|
||||
recipients: recipients
|
||||
.split(/[\n,,;;]/)
|
||||
.map((item) => item.trim())
|
||||
.filter(Boolean),
|
||||
weekday,
|
||||
hour: Number(hour),
|
||||
enabled,
|
||||
})
|
||||
setPassword('')
|
||||
onSaved(next)
|
||||
} catch (reason) {
|
||||
setError(reason instanceof Error ? reason.message : '保存失败')
|
||||
} finally {
|
||||
setSaving(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="qa-weekly-mail-form">
|
||||
<label>
|
||||
邮件服务器
|
||||
<input value={host} onChange={(e) => setHost(e.target.value)} placeholder="smtp.example.com" />
|
||||
</label>
|
||||
<label>
|
||||
端口
|
||||
<input value={port} onChange={(e) => setPort(e.target.value)} inputMode="numeric" placeholder="465" />
|
||||
</label>
|
||||
<label>
|
||||
账号
|
||||
<input value={username} onChange={(e) => setUsername(e.target.value)} placeholder="kb@example.com" />
|
||||
</label>
|
||||
<label>
|
||||
授权码
|
||||
<input
|
||||
type="password"
|
||||
value={password}
|
||||
onChange={(e) => {
|
||||
setPassword(e.target.value)
|
||||
setClearPassword(false)
|
||||
}}
|
||||
placeholder={settings.has_password ? '已保存,留空保持不变' : '首次配置需填写'}
|
||||
autoComplete="new-password"
|
||||
/>
|
||||
</label>
|
||||
{settings.has_password ? (
|
||||
<label className="qa-weekly-mail-inline">
|
||||
<input type="checkbox" checked={clearPassword} onChange={(e) => setClearPassword(e.target.checked)} />
|
||||
清除已保存授权码
|
||||
</label>
|
||||
) : null}
|
||||
<label>
|
||||
发件地址
|
||||
<input value={from} onChange={(e) => setFrom(e.target.value)} placeholder="kb@example.com" />
|
||||
</label>
|
||||
<label className="qa-weekly-mail-wide">
|
||||
收件人(每行一个)
|
||||
<textarea rows={3} value={recipients} onChange={(e) => setRecipients(e.target.value)} />
|
||||
</label>
|
||||
<label>
|
||||
发送日
|
||||
<select value={weekday} onChange={(e) => setWeekday(Number(e.target.value))}>
|
||||
{weeklyMailWeekdayLabels.map((label, index) => (
|
||||
<option key={label} value={index + 1}>
|
||||
{label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<label>
|
||||
发送小时(北京时间)
|
||||
<input value={hour} onChange={(e) => setHour(e.target.value)} inputMode="numeric" />
|
||||
</label>
|
||||
<label className="qa-weekly-mail-inline">
|
||||
<input type="checkbox" checked={enabled} onChange={(e) => setEnabled(e.target.checked)} />
|
||||
启用自动发送
|
||||
</label>
|
||||
<div className="qa-weekly-mail-submit">
|
||||
<button type="button" disabled={saving} onClick={() => void submit()}>
|
||||
{saving ? '保存中…' : '保存发送设置'}
|
||||
</button>
|
||||
<small>只在已确认、且该周已结束后发送一次;正文改动后确认失效。</small>
|
||||
</div>
|
||||
{error ? (
|
||||
<p role="alert" className="error-banner">
|
||||
{error}
|
||||
</p>
|
||||
) : null}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
.qa-weekly-mail {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
padding: 12px 14px;
|
||||
border: 1px solid #dce4ed;
|
||||
border-radius: 10px;
|
||||
background: #f8fafc;
|
||||
}
|
||||
.qa-weekly-mail > header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 14px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.qa-weekly-mail h4 {
|
||||
margin: 0;
|
||||
font-size: 15px;
|
||||
color: #17324d;
|
||||
}
|
||||
.qa-weekly-mail-state {
|
||||
font-size: 13px;
|
||||
color: #64748b;
|
||||
}
|
||||
.qa-weekly-mail-state[data-state='confirmed'] {
|
||||
color: #2d704d;
|
||||
}
|
||||
.qa-weekly-mail-state[data-state='stale'] {
|
||||
color: #b42318;
|
||||
}
|
||||
.qa-weekly-mail-actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
margin-left: auto;
|
||||
}
|
||||
.qa-weekly-mail-summary {
|
||||
margin: 0;
|
||||
font-size: 12px;
|
||||
color: #64748b;
|
||||
}
|
||||
.qa-weekly-mail-sends {
|
||||
margin: 0;
|
||||
padding-left: 18px;
|
||||
font-size: 12px;
|
||||
color: #475569;
|
||||
}
|
||||
.qa-weekly-mail-sends li[data-status='failed'] {
|
||||
color: #b42318;
|
||||
}
|
||||
.qa-weekly-mail-sends li[data-status='sent'] {
|
||||
color: #2d704d;
|
||||
}
|
||||
.qa-weekly-mail-form {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
|
||||
gap: 10px;
|
||||
padding-top: 8px;
|
||||
border-top: 1px solid #e3e9f0;
|
||||
}
|
||||
.qa-weekly-mail-form label {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
font-size: 12px;
|
||||
color: #475569;
|
||||
}
|
||||
.qa-weekly-mail-form input,
|
||||
.qa-weekly-mail-form select,
|
||||
.qa-weekly-mail-form textarea {
|
||||
padding: 6px 8px;
|
||||
border: 1px solid #cbd5e1;
|
||||
border-radius: 6px;
|
||||
font-size: 13px;
|
||||
background: #fff;
|
||||
}
|
||||
.qa-weekly-mail-form .qa-weekly-mail-wide,
|
||||
.qa-weekly-mail-form .qa-weekly-mail-submit {
|
||||
grid-column: 1 / -1;
|
||||
}
|
||||
.qa-weekly-mail-form .qa-weekly-mail-inline {
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
.qa-weekly-mail-submit {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.qa-weekly-mail-submit small {
|
||||
color: #64748b;
|
||||
}
|
||||
@media (max-width: 760px) {
|
||||
.qa-weekly-mail-actions {
|
||||
margin-left: 0;
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
import { renderToStaticMarkup } from 'react-dom/server'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { parseWeeklyMailConfirmation, parseWeeklyMailSends, parseWeeklyMailSettings } from './qaWeeklyMail'
|
||||
import { QAWeeklyMail } from './QAWeeklyMail'
|
||||
|
||||
const settings = {
|
||||
host: 'smtp.example.com',
|
||||
port: 465,
|
||||
username: 'kb@example.com',
|
||||
from: 'kb@example.com',
|
||||
recipients: ['a@example.com'],
|
||||
weekday: 1,
|
||||
hour: 9,
|
||||
enabled: true,
|
||||
has_password: true,
|
||||
revision: 3,
|
||||
updated_by: 'admin',
|
||||
updated_at: '2026-10-25T07:00:00Z',
|
||||
}
|
||||
|
||||
describe('weekly mail settings contract', () => {
|
||||
it('accepts a complete settings payload and rejects impossible slots', () => {
|
||||
expect(parseWeeklyMailSettings(settings)).toMatchObject({ port: 465, weekday: 1, hour: 9, enabled: true })
|
||||
expect(() => parseWeeklyMailSettings({ ...settings, weekday: 0 })).toThrow()
|
||||
expect(() => parseWeeklyMailSettings({ ...settings, weekday: 8 })).toThrow()
|
||||
expect(() => parseWeeklyMailSettings({ ...settings, hour: 24 })).toThrow()
|
||||
expect(() => parseWeeklyMailSettings({ ...settings, port: 0 })).toThrow()
|
||||
expect(() => parseWeeklyMailSettings({ ...settings, recipients: [42] })).toThrow()
|
||||
})
|
||||
it('distinguishes a missing confirmation from an expired one', () => {
|
||||
expect(parseWeeklyMailConfirmation(null, '2026-W43')).toBeNull()
|
||||
const live = parseWeeklyMailConfirmation(
|
||||
{
|
||||
week: '2026-W43',
|
||||
draft_revision: 2,
|
||||
body_sha256: 'a',
|
||||
confirmed_by: 'admin',
|
||||
confirmed_at: '2026-10-25T07:00:00Z',
|
||||
current: false,
|
||||
},
|
||||
'2026-W43'
|
||||
)
|
||||
expect(live?.current).toBe(false)
|
||||
expect(() => parseWeeklyMailConfirmation({ week: '2026-W42', current: true }, '2026-W43')).toThrow()
|
||||
})
|
||||
it('rejects unknown delivery states instead of mislabelling them as sent', () => {
|
||||
expect(
|
||||
parseWeeklyMailSends([
|
||||
{
|
||||
week: '2026-W43',
|
||||
draft_revision: 1,
|
||||
status: 'sent',
|
||||
attempts: 1,
|
||||
last_error: '',
|
||||
updated_at: '2026-10-25T07:00:00Z',
|
||||
},
|
||||
])
|
||||
).toHaveLength(1)
|
||||
expect(() =>
|
||||
parseWeeklyMailSends([
|
||||
{ week: '2026-W43', draft_revision: 1, status: 'delivered', attempts: 1, last_error: '', updated_at: '' },
|
||||
])
|
||||
).toThrow()
|
||||
})
|
||||
})
|
||||
|
||||
it('shows the confirmation gate before any automatic send controls', () => {
|
||||
const html = renderToStaticMarkup(<QAWeeklyMail week="2026-W43" busy={false} />)
|
||||
expect(html).toContain('自动发送')
|
||||
expect(html).toContain('未确认')
|
||||
expect(html).toContain('确认本周周报')
|
||||
expect(html).not.toContain('立即发送')
|
||||
expect(html).not.toContain('发送设置')
|
||||
})
|
||||
@@ -0,0 +1,151 @@
|
||||
import { getPayload } from './qaOps'
|
||||
|
||||
export interface WeeklyMailSettings {
|
||||
host: string
|
||||
port: number
|
||||
username: string
|
||||
from: string
|
||||
recipients: string[]
|
||||
weekday: number
|
||||
hour: number
|
||||
enabled: boolean
|
||||
has_password: boolean
|
||||
revision: number
|
||||
updated_by: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
export interface WeeklyMailConfirmation {
|
||||
week: string
|
||||
draft_revision: number
|
||||
body_sha256: string
|
||||
confirmed_by: string
|
||||
confirmed_at: string
|
||||
current: boolean
|
||||
}
|
||||
|
||||
export interface WeeklyMailSend {
|
||||
week: string
|
||||
draft_revision: number
|
||||
status: 'sending' | 'sent' | 'failed'
|
||||
attempts: number
|
||||
last_error: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
const bad = (): never => {
|
||||
throw new Error('周报邮件响应无效,未显示或未标记为已保存')
|
||||
}
|
||||
const obj = (v: unknown): Record<string, unknown> =>
|
||||
v && typeof v === 'object' && !Array.isArray(v) ? (v as Record<string, unknown>) : bad()
|
||||
const str = (v: unknown): string => (typeof v === 'string' ? v : bad())
|
||||
const num = (v: unknown): number => (typeof v === 'number' && Number.isSafeInteger(v) && v >= 0 ? v : bad())
|
||||
|
||||
export function parseWeeklyMailSettings(value: unknown): WeeklyMailSettings {
|
||||
const v = obj(value)
|
||||
if (!Array.isArray(v.recipients) || v.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),
|
||||
port = num(v.port)
|
||||
if (weekday < 1 || weekday > 7 || hour > 23 || port < 1 || port > 65535) return bad()
|
||||
return {
|
||||
host: str(v.host),
|
||||
port,
|
||||
username: str(v.username),
|
||||
from: str(v.from),
|
||||
recipients: v.recipients as string[],
|
||||
weekday,
|
||||
hour,
|
||||
enabled: v.enabled,
|
||||
has_password: v.has_password,
|
||||
revision: num(v.revision),
|
||||
updated_by: str(v.updated_by),
|
||||
updated_at: v.updated_at === null ? '' : str(v.updated_at),
|
||||
}
|
||||
}
|
||||
|
||||
export function parseWeeklyMailConfirmation(value: unknown, week: string): WeeklyMailConfirmation | null {
|
||||
if (value === null) return null
|
||||
const v = obj(value)
|
||||
if (v.week !== week || typeof v.current !== 'boolean') return bad()
|
||||
return {
|
||||
week,
|
||||
draft_revision: num(v.draft_revision),
|
||||
body_sha256: str(v.body_sha256),
|
||||
confirmed_by: str(v.confirmed_by),
|
||||
confirmed_at: str(v.confirmed_at),
|
||||
current: v.current,
|
||||
}
|
||||
}
|
||||
|
||||
export function parseWeeklyMailSends(value: unknown): WeeklyMailSend[] {
|
||||
if (!Array.isArray(value)) return bad()
|
||||
return value.map((raw) => {
|
||||
const v = obj(raw)
|
||||
if (!['sending', 'sent', 'failed'].includes(str(v.status))) return bad()
|
||||
return {
|
||||
week: str(v.week),
|
||||
draft_revision: num(v.draft_revision),
|
||||
status: v.status as WeeklyMailSend['status'],
|
||||
attempts: num(v.attempts),
|
||||
last_error: str(v.last_error),
|
||||
updated_at: str(v.updated_at),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const endpoint = (path: string, week?: string) =>
|
||||
`/api/v1/qa-ops/master/weekly-mail/${path}${week ? '/' + encodeURIComponent(week) : ''}`
|
||||
const headers = { 'Content-Type': 'application/json', 'X-Governance-Action': 'qa-weekly-mail' }
|
||||
|
||||
export async function fetchWeeklyMailSettings(): Promise<WeeklyMailSettings> {
|
||||
return parseWeeklyMailSettings(((await getPayload(endpoint('settings'))) as { data: unknown }).data)
|
||||
}
|
||||
|
||||
export async function saveWeeklyMailSettings(
|
||||
base: number,
|
||||
form: Omit<WeeklyMailSettings, 'has_password' | 'revision' | 'updated_by' | 'updated_at'> & {
|
||||
password: string
|
||||
clear_password: boolean
|
||||
}
|
||||
): Promise<WeeklyMailSettings> {
|
||||
const payload = await getPayload(endpoint('settings'), undefined, {
|
||||
method: 'POST',
|
||||
headers,
|
||||
body: JSON.stringify({
|
||||
base_revision: base,
|
||||
host: form.host,
|
||||
port: form.port,
|
||||
username: form.username,
|
||||
password: form.password,
|
||||
clear_password: form.clear_password,
|
||||
from: form.from,
|
||||
recipients: form.recipients,
|
||||
weekday: form.weekday,
|
||||
hour: form.hour,
|
||||
enabled: form.enabled,
|
||||
}),
|
||||
})
|
||||
return parseWeeklyMailSettings((payload as { data: unknown }).data)
|
||||
}
|
||||
|
||||
export async function fetchWeeklyMailConfirmation(week: string): Promise<WeeklyMailConfirmation | null> {
|
||||
const payload = await getPayload(endpoint('confirmations', week))
|
||||
return parseWeeklyMailConfirmation((payload as { data: { confirmation: unknown } }).data.confirmation, week)
|
||||
}
|
||||
|
||||
export async function confirmWeeklyMail(week: string, confirm: boolean): Promise<WeeklyMailConfirmation | null> {
|
||||
const payload = await getPayload(endpoint('confirmations', week), undefined, {
|
||||
method: confirm ? 'POST' : 'DELETE',
|
||||
headers,
|
||||
})
|
||||
return parseWeeklyMailConfirmation((payload as { data: { confirmation: unknown } }).data.confirmation, week)
|
||||
}
|
||||
|
||||
export async function fetchWeeklyMailSends(week: string): Promise<WeeklyMailSend[]> {
|
||||
const payload = await getPayload(endpoint('sends') + '?' + new URLSearchParams({ week }).toString())
|
||||
return parseWeeklyMailSends((payload as { data: { sends: unknown } }).data.sends)
|
||||
}
|
||||
|
||||
export const weeklyMailWeekdayLabels = ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
|
||||
Reference in New Issue
Block a user