From cff2db0ef65932ebbe575262dd9100accbf3b3c0 Mon Sep 17 00:00:00 2001 From: dreamhunter2333 Date: Sun, 23 Aug 2026 22:44:40 +0800 Subject: [PATCH] refactor: inline user send rate limit path --- worker/src/worker.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/worker/src/worker.ts b/worker/src/worker.ts index b1e9fab..5979b74 100644 --- a/worker/src/worker.ts +++ b/worker/src/worker.ts @@ -74,12 +74,15 @@ app.use('/*', async (c, next) => { ) { const reqIp = c.req.raw.headers.get("cf-connecting-ip") if (reqIp && c.env.RATE_LIMITER) { - const rateLimitPath = c.req.path.startsWith("/user_api/address/") - && c.req.path.endsWith("/send_mail") - ? "/user_api/address/:address_id/send_mail" - : c.req.path; const { success } = await c.env.RATE_LIMITER.limit( - { key: `${rateLimitPath}|${reqIp}` } + { + key: `${ + c.req.path.startsWith("/user_api/address/") + && c.req.path.endsWith("/send_mail") + ? "/user_api/address/:address_id/send_mail" + : c.req.path + }|${reqIp}` + } ) if (!success) { return c.text(`IP=${reqIp} Rate limit exceeded for ${c.req.path}`, 429)