mirror of
https://github.com/dreamhunter2333/cloudflare_temp_email.git
synced 2026-05-19 12:19:33 +08:00
feat: requset_send_mail_access default 1 balance (#143)
* feat: requset_send_mail_access default 1 balance * feat: send_mail RATE_LIMITER for ip
This commit is contained in:
@@ -9,7 +9,7 @@ api.post('/api/requset_send_mail_access', async (c) => {
|
||||
}
|
||||
try {
|
||||
const { success } = await c.env.DB.prepare(
|
||||
`INSERT INTO address_sender (address, enabled) VALUES (?, 1)`
|
||||
`INSERT INTO address_sender (address, balance, enabled) VALUES (?, 1, 1)`
|
||||
).bind(address).run();
|
||||
if (!success) {
|
||||
return c.text("Failed to request send mail access", 500)
|
||||
|
||||
@@ -20,12 +20,14 @@ app.use('/api/*', async (c, next) => {
|
||||
return c.text("Need Password", 401)
|
||||
}
|
||||
}
|
||||
if (c.req.path.startsWith("/api/new_address")) {
|
||||
if (c.req.path.startsWith("/api/new_address") || c.req.path.startsWith("/api/send_mail")) {
|
||||
const reqIp = c.req.raw.headers.get("cf-connecting-ip")
|
||||
if (reqIp && c.env.RATE_LIMITER) {
|
||||
const { success } = await c.env.RATE_LIMITER.limit({ key: reqIp })
|
||||
const { success } = await c.env.RATE_LIMITER.limit(
|
||||
{ key: `${c.req.path}|${reqIp}` }
|
||||
)
|
||||
if (!success) {
|
||||
return c.text(`IP=${reqIp} Rate limit exceeded for /api/new_address`, 429)
|
||||
return c.text(`IP=${reqIp} Rate limit exceeded for ${c.req.path}`, 429)
|
||||
}
|
||||
}
|
||||
await next();
|
||||
|
||||
Reference in New Issue
Block a user