feat: 添加短信发送限流、忽略爬虫、调整默认限流规则

This commit is contained in:
2025-12-18 11:48:40 +08:00
parent 2df5027c0f
commit d6bf4d3cb3
2 changed files with 7 additions and 3 deletions

View File

@@ -30,9 +30,10 @@ import { SmsModule } from './sms/sms.module';
synchronize: process.env.NODE_ENV !== 'production', // Set to false in production synchronize: process.env.NODE_ENV !== 'production', // Set to false in production
}), }),
ThrottlerModule.forRoot({ ThrottlerModule.forRoot({
ignoreUserAgents: [/googlebot/i, /bingbot/i],
throttlers: [ throttlers: [
{ {
limit: 1000, limit: 100,
ttl: 60000, // 1 minute ttl: 60000, // 1 minute
}, },
], ],

View File

@@ -1,6 +1,7 @@
import { Body, Controller, Post } from '@nestjs/common'; import { Body, Controller, Post, UseGuards } from '@nestjs/common';
import { SendLoginSmsDto } from './dto/send-login-sms.dto'; import { SendLoginSmsDto } from './dto/send-login-sms.dto';
import { SmsService } from './sms.service'; import { SmsService } from './sms.service';
import { Throttle, ThrottlerGuard } from '@nestjs/throttler';
@Controller('sms') @Controller('sms')
export class SmsController { export class SmsController {
@@ -8,6 +9,8 @@ export class SmsController {
constructor(private readonly smsService: SmsService) { } constructor(private readonly smsService: SmsService) { }
@Post('send/login') @Post('send/login')
@UseGuards(ThrottlerGuard)
@Throttle({ sms_login: { limit: 10, ttl: 60000 } })
async sendLoginSms(@Body() dto: SendLoginSmsDto) { async sendLoginSms(@Body() dto: SendLoginSmsDto) {
await this.smsService.sendSms(dto.phone, 'login'); await this.smsService.sendSms(dto.phone, 'login');
return null; return null;