feat: add throttle

This commit is contained in:
Innei
2022-05-22 16:26:46 +08:00
parent 110d9ca010
commit 59c50a4670
4 changed files with 38 additions and 0 deletions

View File

@@ -10,7 +10,9 @@ import {
Query,
Req,
Res,
UseGuards,
} from '@nestjs/common'
import { Throttle, ThrottlerGuard } from '@nestjs/throttler'
import { Auth } from '~/common/decorator/auth.decorator'
import { HTTPDecorators } from '~/common/decorator/http.decorator'
@@ -45,6 +47,8 @@ export class FileController {
}
@Get('/:type/:name')
@UseGuards(ThrottlerGuard)
@Throttle(10, 60)
@HTTPDecorators.Bypass
async get(@Param() params: FileQueryDto, @Res() reply: FastifyReply) {
const { type, name } = params

View File

@@ -1,6 +1,7 @@
import { Global, Module, Provider, forwardRef } from '@nestjs/common'
import { EventEmitterModule } from '@nestjs/event-emitter'
import { ScheduleModule } from '@nestjs/schedule'
import { ThrottlerModule } from '@nestjs/throttler'
import { AggregateModule } from '~/modules/aggregate/aggregate.module'
import { BackupModule } from '~/modules/backup/backup.module'
@@ -36,6 +37,7 @@ const providers: Provider<any>[] = [
@Module({
imports: [
ScheduleModule.forRoot(),
ThrottlerModule.forRoot({}),
EventEmitterModule.forRoot({
wildcard: false,
// the delimiter used to segment namespaces