From a5e5fceab5de7993deacb65c62699a74d5113140 Mon Sep 17 00:00:00 2001 From: Dream Hunter Date: Mon, 2 Mar 2026 00:27:24 +0800 Subject: [PATCH] fix: prevent account_settings KV.put on empty fromBlockList (#847) * fix: avoid KV.put when fromBlockList is empty * docs: update English changelog for account_settings fix --- CHANGELOG.md | 1 + CHANGELOG_EN.md | 1 + worker/src/admin_api/index.ts | 4 ++-- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f891919..ab92dcad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ ### Bug Fixes +- fix: |Admin API| 修复 `/admin/account_settings` 在未配置 KV 且 `fromBlockList` 为空时触发 `Cannot read properties of undefined (reading 'put')` 的问题 - fix: |文档| 修复 User Mail API 文档中错误使用 `x-admin-auth` 的问题,改为正确的 `x-user-token` - docs: |文档| 新增 Admin 删除邮件、删除邮箱地址、清空收件箱、清空发件箱 API 文档 diff --git a/CHANGELOG_EN.md b/CHANGELOG_EN.md index e47f0d7b..8e65ec0a 100644 --- a/CHANGELOG_EN.md +++ b/CHANGELOG_EN.md @@ -14,6 +14,7 @@ ### Bug Fixes +- fix: |Admin API| Fix `/admin/account_settings` throwing `Cannot read properties of undefined (reading 'put')` when KV is not configured and `fromBlockList` is empty - fix: |Docs| Fix User Mail API documentation incorrectly using `x-admin-auth`, changed to correct `x-user-token` - docs: |Docs| Add Admin API documentation for delete mail, delete address, clear inbox, and clear sent items diff --git a/worker/src/admin_api/index.ts b/worker/src/admin_api/index.ts index c5829842..7ca8394f 100644 --- a/worker/src/admin_api/index.ts +++ b/worker/src/admin_api/index.ts @@ -322,8 +322,8 @@ api.post('/admin/account_settings', async (c) => { if (fromBlockList?.length > 0 && !c.env.KV) { return c.text(msgs.EnableKVMsg, 400) } - if (fromBlockList) { - await c.env.KV.put(CONSTANTS.EMAIL_KV_BLACK_LIST, JSON.stringify(fromBlockList || [])) + if (fromBlockList?.length > 0 && c.env.KV) { + await c.env.KV.put(CONSTANTS.EMAIL_KV_BLACK_LIST, JSON.stringify(fromBlockList)) } await saveSetting( c, CONSTANTS.NO_LIMIT_SEND_ADDRESS_LIST_KEY,