mirror of
https://github.com/dreamhunter2333/cloudflare_temp_email.git
synced 2026-09-04 23:17:34 +08:00
refactor: simplify user send limiter key
This commit is contained in:
+5
-10
@@ -74,16 +74,11 @@ app.use('/*', async (c, next) => {
|
|||||||
) {
|
) {
|
||||||
const reqIp = c.req.raw.headers.get("cf-connecting-ip")
|
const reqIp = c.req.raw.headers.get("cf-connecting-ip")
|
||||||
if (reqIp && c.env.RATE_LIMITER) {
|
if (reqIp && c.env.RATE_LIMITER) {
|
||||||
const { success } = await c.env.RATE_LIMITER.limit(
|
const { success } = await c.env.RATE_LIMITER.limit({
|
||||||
{
|
key: `${c.req.path.startsWith("/user_api/address/")
|
||||||
key: `${
|
? "/user_api/address/send_mail"
|
||||||
c.req.path.startsWith("/user_api/address/")
|
: c.req.path}|${reqIp}`
|
||||||
&& c.req.path.endsWith("/send_mail")
|
})
|
||||||
? "/user_api/address/:address_id/send_mail"
|
|
||||||
: c.req.path
|
|
||||||
}|${reqIp}`
|
|
||||||
}
|
|
||||||
)
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
return c.text(`IP=${reqIp} Rate limit exceeded for ${c.req.path}`, 429)
|
return c.text(`IP=${reqIp} Rate limit exceeded for ${c.req.path}`, 429)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user