Skip to content

下线旧 notify token,推送统一改用 API Key(POST /api/notify) - #112

Merged
todosdev[bot] merged 1 commit into
mainfrom
tds/conv-01a14986-1575-7d9f-b292-fb3cf62435dc
Oct 17, 2026
Merged

todosdev[bot] merged 1 commit into
mainfrom
tds/conv-01a14986-1575-7d9f-b292-fb3cf62435dc

Conversation

@todosdev

@todosdev todosdev Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • 下线旧的 notify token 推送机制(token 明文出现在 URL 中),统一改用 API Key 调用 POST /api/notify。
  • 旧路由 POST /api/notify/:token 及 token 管理接口 POST/DELETE /api/me/notifications/token(/:token) 现在一律返回 410 Gone,不再读 KV、不查库、不发推送,也不生成/删除任何 token。
  • POST /api/notify(API Key / cookie)行为与 30 次/分钟限流保持不变。

Changes

worker/src/routes/notify.ts

  • POST /api/notify/:token 改为静态返回 410 Gone,提示改用 POST /api/notify + Authorization: Bearer enk_...。
  • 移除 /:token 上的 rateLimit 中间件(其本身会读写 KV,与「不碰 KV」冲突)。
  • 将仅剩一个调用方的 notifyByUserId 内联进 POST /,并删除不再使用的 findUserById、Context 导入。

worker/src/routes/me.ts

  • POST /api/me/notifications/token 与 DELETE /api/me/notifications/token/:token 改为返回 410 Gone,共用 NOTIFY_TOKEN_DEPRECATED 常量,不再生成或删除 token。

README.md / README.en.md

  • 删除「老 token 路由 /api/notify/:token 与新路由共享 30 次/分钟限流」的说明,改为补一句 token 已下线、返回 410、请改用 API Key。

未改动:worker/src/index.ts 的日志脱敏正则(/api/(setup|notify)/...)保留,旧客户端仍会请求 /api/notify/<token>。

已存在的 notify_token:* KV 记录不做专门清理,会在一年 TTL 内自然过期(它们已不再被任何代码路径读取)。

Testing

本地 wrangler dev 实测(注册用户 → 登录拿 cookie → 建 API Key → 配置 webhook 渠道指向 webhook.site):

  • POST /api/notify/sometoken → 410 Gone,报文提示改用 API Key,且 webhook.site 未收到任何推送。
  • POST /api/me/notifications/token(cookie)→ 410 Gone;DELETE /api/me/notifications/token/abc(cookie)→ 410 Gone。
  • POST /api/notify + 无效 key → 401 Unauthorized;+ 有效 enk_... key → 200 且 webhook.site 收到真实推送;+ cookie → 200 且收到真实推送。
  • pnpm typecheck、pnpm build、pnpm format:check 全部通过;pnpm lint 无 error(仅 2 条与本次改动无关的既有 warning)。

仓库不跟踪生成产物:web/dist、worker 无构建产物纳入版本控制,pnpm build 已在本机重新验证通过,无需额外提交产物。

- POST /api/notify/:token now returns 410 Gone and no longer reads the KV
  notify_token record or queries the DB; legacy clients must migrate to
  POST /api/notify with an enk_... bearer key.
- POST/DELETE /api/me/notifications/token(/:token) now return 410 Gone and
  no longer generate or delete any token.
- Inlined the now single-caller notifyByUserId helper into POST /api/notify,
  removed the unused findUserById import, and dropped the :token rate
  limiter since the deprecated route no longer touches KV.
- Log redaction for /api/notify/<token> (index.ts) is unchanged; README (zh/en)
  updated to document the retirement and the API-key migration path.

Existing notify_token:* KV records are left to expire within their one-year
TTL; no migration cleanup is needed.

Checkpoint: 2IOucMQCOPHQph6u7Ww6n
@todosdev
todosdev Bot merged commit bbb0999 into main Oct 17, 2026
1 check passed
@mapxn
mapxn deleted the tds/conv-01a14986-1575-7d9f-b292-fb3cf62435dc branch October 18, 2026 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants