fix: return empty object instead of null when no email

This commit is contained in:
zimk
2026-03-04 15:53:51 +08:00
parent 0d81fbaae0
commit 201e880c36

View File

@@ -61,14 +61,14 @@ export default {
LIMIT 1` LIMIT 1`
).bind(to).first(); ).bind(to).first();
if (!row) return json(null); if (!row) return json({});
if (Date.now() - row.received_at > ONE_DAY_MS) { if (Date.now() - row.received_at > ONE_DAY_MS) {
// 读取时发现过期,立即删除,避免库里长期残留 // 读取时发现过期,立即删除,避免库里长期残留
await env.DB.prepare( await env.DB.prepare(
`DELETE FROM latest_emails WHERE recipient = ? AND received_at = ?` `DELETE FROM latest_emails WHERE recipient = ? AND received_at = ?`
).bind(row.recipient, row.received_at).run(); ).bind(row.recipient, row.received_at).run();
return json(null); return json({});
} }
return json({ return json({