feat: upgrade throttle

This commit is contained in:
Innei
2023-09-05 21:46:49 +08:00
parent 15b92dedc4
commit a981f14053
5 changed files with 37 additions and 15 deletions

View File

@@ -53,7 +53,7 @@
"@babel/plugin-transform-modules-commonjs": "7.22.15",
"@babel/plugin-transform-typescript": "7.22.15",
"@babel/types": "^7.22.15",
"@fastify/cookie": "8.3.0",
"@fastify/cookie": "9.0.4",
"@fastify/multipart": "7.7.3",
"@fastify/static": "6.11.0",
"@innei/next-async": "0.3.0",
@@ -65,7 +65,7 @@
"@nestjs/platform-fastify": "10.2.4",
"@nestjs/platform-socket.io": "10.2.4",
"@nestjs/schedule": "3.0.3",
"@nestjs/throttler": "4.2.1",
"@nestjs/throttler": "5.0.0",
"@nestjs/websockets": "10.2.4",
"@socket.io/redis-adapter": "7.2.0",
"@socket.io/redis-emitter": "4.1.1",

View File

@@ -38,7 +38,12 @@ export class FileController {
}
@Get('/:type/:name')
@Throttle(60, 60)
@Throttle({
default: {
limit: 60,
ttl: 60_000,
},
})
@HTTPDecorators.Bypass
async get(@Param() params: FileQueryDto, @Res() reply: FastifyReply) {
const { type, name } = params

View File

@@ -49,7 +49,12 @@ export class ServerlessController {
}
}
@All('/:reference/:name/*')
@Throttle(100, 5)
@Throttle({
default: {
limit: 1000,
ttl: 5000,
},
})
@HTTPDecorators.Bypass
async runServerlessFunctionWildcard(
@Param() param: ServerlessReferenceDto,
@@ -62,7 +67,12 @@ export class ServerlessController {
}
@All('/:reference/:name')
@Throttle(100, 5)
@Throttle({
default: {
limit: 100,
ttl: 5000,
},
})
@HTTPDecorators.Bypass
async runServerlessFunction(
@Param() param: ServerlessReferenceDto,

View File

@@ -45,7 +45,12 @@ const providers: Provider<any>[] = [
@Module({
imports: [
ScheduleModule.forRoot(),
ThrottlerModule.forRoot({}),
ThrottlerModule.forRoot([
{
ttl: 60_000,
limit: 50,
},
]),
EventEmitterModule.forRoot({
wildcard: false,
// the delimiter used to segment namespaces

20
pnpm-lock.yaml generated
View File

@@ -86,8 +86,8 @@ importers:
specifier: ^7.22.15
version: 7.22.15
'@fastify/cookie':
specifier: 8.3.0
version: 8.3.0
specifier: 9.0.4
version: 9.0.4
'@fastify/multipart':
specifier: 7.7.3
version: 7.7.3
@@ -122,8 +122,8 @@ importers:
specifier: 3.0.3
version: 3.0.3(@nestjs/common@10.2.4)(@nestjs/core@10.2.4)(reflect-metadata@0.1.13)
'@nestjs/throttler':
specifier: 4.2.1
version: 4.2.1(@nestjs/common@10.2.4)(@nestjs/core@10.2.4)(reflect-metadata@0.1.13)
specifier: 5.0.0
version: 5.0.0(@nestjs/common@10.2.4)(@nestjs/core@10.2.4)(reflect-metadata@0.1.13)
'@nestjs/websockets':
specifier: 10.2.4
version: 10.2.4(@nestjs/common@10.2.4)(@nestjs/core@10.2.4)(@nestjs/platform-socket.io@10.2.4)(reflect-metadata@0.1.13)(rxjs@7.8.1)
@@ -1964,11 +1964,11 @@ packages:
text-decoding: 1.0.0
dev: false
/@fastify/cookie@8.3.0:
resolution: {integrity: sha512-P9hY9GO11L20TnZ33XN3i0bt+3x0zaT7S0ohAzWO950E9PB2xnNhLYzPFJIGFi5AVN0yr5+/iZhWxeYvR6KCzg==}
/@fastify/cookie@9.0.4:
resolution: {integrity: sha512-behLOTH2u7fSZ6+TWeW8XUCmpEstwl8ysxzyb4QRxnKyt80O2S4yVfNbBZQcG9rktjeZXfR7LLl9xXKL4vdjlQ==}
dependencies:
cookie: 0.5.0
fastify-plugin: 4.5.0
fastify-plugin: 4.5.1
dev: false
/@fastify/cors@8.3.0:
@@ -2485,8 +2485,8 @@ packages:
tslib: 2.6.2
dev: true
/@nestjs/throttler@4.2.1(@nestjs/common@10.2.4)(@nestjs/core@10.2.4)(reflect-metadata@0.1.13):
resolution: {integrity: sha512-wVPMuIyr0KdrK1RVVQceWVNesogCm9IgYC1V5EkaTZ+usIE4qxEyzdwU5IqQLgOO/Loiq98MLwReDxazX7i9Uw==}
/@nestjs/throttler@5.0.0(@nestjs/common@10.2.4)(@nestjs/core@10.2.4)(reflect-metadata@0.1.13):
resolution: {integrity: sha512-TKf+bpjYpRnSOu8dqi0TmQAPxyvLoO6jFldTq3ToevYDfLtAxBXDTJs8qRRfmHv3wORaJhIbVDtW1dDQuP5wCQ==}
peerDependencies:
'@nestjs/common': ^7.0.0 || ^8.0.0 || ^9.0.0 || ^10.0.0
'@nestjs/core': ^7.0.0 || ^8.0.0 || ^9.0.0 || ^10.0.0
@@ -7577,6 +7577,7 @@ packages:
/minipass@6.0.2:
resolution: {integrity: sha512-MzWSV5nYVT7mVyWCwn2o7JH13w2TBRmmSqSRCKzTw+lmft9X4z+3wjvs06Tzijo5z4W/kahUCDpRXTF+ZrmF/w==}
engines: {node: '>=16 || 14 >=14.17'}
requiresBuild: true
/minipass@7.0.3:
resolution: {integrity: sha512-LhbbwCfz3vsb12j/WkWQPZfKTsgqIe1Nf/ti1pKjYESGLHIVjWU96G9/ljLH4F9mWNVhlQOm0VySdAWzf05dpg==}
@@ -8236,6 +8237,7 @@ packages:
/path-scurry@1.9.2:
resolution: {integrity: sha512-qSDLy2aGFPm8i4rsbHd4MNyTcrzHFsLQykrtbuGRknZZCBBVXSv2tSCDN2Cg6Rt/GFRw8GoW9y9Ecw5rIPG1sg==}
engines: {node: '>=16 || 14 >=14.17'}
requiresBuild: true
dependencies:
lru-cache: 9.1.2
minipass: 6.0.2