Repository navigation
新增 POST /api/notify:用 enk_ API Key 或登录态直接发推送 - #109
Merged
todosdev[bot] merged 1 commit intoOct 17, 2026
Merged
Conversation
- Add POST /api/notify (exact path, no :token) behind
apiKeyOrCookieAuth so enk_ key holders can trigger pushes directly
with their session's permissions; the handler takes userId from
c.get("userId") without re-validating the already-active user.
- Layer the same 30/min notify_trigger rate limit on the new route,
on top of the per-key 120/min limit inside apiKeyOrCookieAuth.
Both routes share the per-IP quota via the same keyPrefix.
- Extract notifyByUserId (config lookup -> 400 when missing, body
parse, NotifyMessage assembly, sendNotifications) reused by both
routes; the legacy /:token route's behaviour is unchanged.
- Document POST /api/notify in README.md and README.en.md.
Checkpoint: Wc-n6Gb0ko9Esa9rikO37
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
POST /api/notify(exact path, no:token) soenk_API-key holders — or a logged-in cookie session — can trigger push notifications directly, reusing their existing key instead of a separate notify token.notify_triggerrate limit (30/min) on top of the per-key 120/min limit as a second anti-spam gate./:tokenroute is unchanged.Changes
worker/src/routes/notify.tsnotifyRoutes.use("/", apiKeyOrCookieAuth)andnotifyRoutes.use("/", rateLimit({ max: 30, window: 60, keyPrefix: "notify_trigger" }))on the exact root path.POST /handler: readsuserIdfrom context (middleware already guarantees an active user), looks up the notification config (400 when absent), parses{ title?, body?, url? }(title defaults toNotification), sends, and returns{ success: true, results }.notifyByUserId(c, userId)reused by the new and legacy routes; the legacy/:tokenauth and 401 branches are left untouched. Switch to the sharedHonoEnvtype from../types(type-only).README.md/README.en.mdPOST /api/notifyunder the API Key section, noting the defaultNotificationtitle, cookie-session support, and the 30/min per-IP limit shared with the legacy route.Testing
pnpm lint,pnpm format:check,pnpm typecheck,pnpm buildall pass.wrangler devchain verified with a seeded local D1/KV and a public webhook.site sink (real outbound delivery confirmed):enk_key →200{success:true, results:[{channel:"webhook", success:true}]}; webhook.site received the exact payload.401; no auth →401.400{"error":"No notification channels configured"}.200.POST /api/notify/:token→200; invalid token →401.400{"error":"Invalid request body"}via the globalonErrorhandler.