From f3a3df99241f450fc9cecb6b2f4cea8d0b49ee81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kim=20=E9=87=91=E5=8F=AF=E6=98=8E?= Date: Sat, 9 Sep 2023 19:19:28 +0200 Subject: [PATCH] feat: use seconds() throttler helper function --- test/app/controllers/app.controller.ts | 4 ++-- test/app/controllers/cluster-controller.module.ts | 4 ++-- test/app/controllers/controller.module.ts | 4 ++-- test/app/controllers/limit.controller.ts | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/test/app/controllers/app.controller.ts b/test/app/controllers/app.controller.ts index 89ee110c..2cf09679 100644 --- a/test/app/controllers/app.controller.ts +++ b/test/app/controllers/app.controller.ts @@ -1,9 +1,9 @@ import { Controller, Get } from '@nestjs/common'; -import { SkipThrottle, Throttle } from '@nestjs/throttler'; +import { SkipThrottle, Throttle, seconds } from '@nestjs/throttler'; import { AppService } from '../app.service'; @Controller() -@Throttle({ default: { limit: 2, ttl: 10000 } }) +@Throttle({ default: { limit: 2, ttl: seconds(10) } }) export class AppController { constructor(private readonly appService: AppService) {} diff --git a/test/app/controllers/cluster-controller.module.ts b/test/app/controllers/cluster-controller.module.ts index 7f730060..347b0028 100644 --- a/test/app/controllers/cluster-controller.module.ts +++ b/test/app/controllers/cluster-controller.module.ts @@ -1,5 +1,5 @@ import { Module } from '@nestjs/common'; -import { ThrottlerModule } from '@nestjs/throttler'; +import { ThrottlerModule, seconds } from '@nestjs/throttler'; import { ThrottlerStorageRedisService } from '../../../src'; import { cluster } from '../../utility/redis-cluster'; import { AppService } from '../app.service'; @@ -10,7 +10,7 @@ import { LimitController } from './limit.controller'; @Module({ imports: [ ThrottlerModule.forRoot({ - throttlers: [{ limit: 5, ttl: 60000 }], + throttlers: [{ limit: 5, ttl: seconds(60) }], ignoreUserAgents: [/throttler-test/g], storage: new ThrottlerStorageRedisService(cluster), }), diff --git a/test/app/controllers/controller.module.ts b/test/app/controllers/controller.module.ts index 50595c80..fd7c0e45 100644 --- a/test/app/controllers/controller.module.ts +++ b/test/app/controllers/controller.module.ts @@ -1,5 +1,5 @@ import { Module } from '@nestjs/common'; -import { ThrottlerModule } from '@nestjs/throttler'; +import { ThrottlerModule, seconds } from '@nestjs/throttler'; import { ThrottlerStorageRedisService } from '../../../src'; import { redis } from '../../utility/redis'; import { AppService } from '../app.service'; @@ -10,7 +10,7 @@ import { LimitController } from './limit.controller'; @Module({ imports: [ ThrottlerModule.forRoot({ - throttlers: [{ limit: 5, ttl: 60000 }], + throttlers: [{ limit: 5, ttl: seconds(60) }], ignoreUserAgents: [/throttler-test/g], storage: new ThrottlerStorageRedisService(redis), }), diff --git a/test/app/controllers/limit.controller.ts b/test/app/controllers/limit.controller.ts index ad56873f..9be11b23 100644 --- a/test/app/controllers/limit.controller.ts +++ b/test/app/controllers/limit.controller.ts @@ -1,8 +1,8 @@ import { Controller, Get } from '@nestjs/common'; -import { Throttle } from '@nestjs/throttler'; +import { Throttle, seconds } from '@nestjs/throttler'; import { AppService } from '../app.service'; -@Throttle({ default: { limit: 2, ttl: 10000 } }) +@Throttle({ default: { limit: 2, ttl: seconds(10) } }) @Controller('limit') export class LimitController { constructor(private readonly appService: AppService) {} @@ -11,13 +11,13 @@ export class LimitController { return this.appService.success(); } - @Throttle({ default: { limit: 5, ttl: 10000 } }) + @Throttle({ default: { limit: 5, ttl: seconds(10) } }) @Get('higher') getHigher() { return this.appService.success(); } - @Throttle({ default: { limit: 3, ttl: 10000 } }) + @Throttle({ default: { limit: 3, ttl: seconds(10) } }) @Get('flooded') getFlooded() { return this.appService.success();