fix: remove ws guard

Signed-off-by: Innei <i@innei.in>
This commit is contained in:
Innei
2024-02-22 17:33:31 +08:00
parent 7cb6eea287
commit 147441c2c9
2 changed files with 20 additions and 23 deletions

View File

@@ -1,9 +1,8 @@
import type { ExecutionContext } from '@nestjs/common'
import type { ThrottlerOptions } from '@nestjs/throttler'
import type { FastifyBizRequest } from '~/transformers/get-req.transformer'
import { Injectable } from '@nestjs/common'
import { ThrottlerException, ThrottlerGuard } from '@nestjs/throttler'
import { ThrottlerGuard } from '@nestjs/throttler'
import { getNestExecutionContextRequest } from '~/transformers/get-req.transformer'
import { getIp } from '~/utils'
@@ -24,23 +23,23 @@ export class ExtendThrottlerGuard extends ThrottlerGuard {
}
}
@Injectable()
export class WsExtendThrottlerGuard extends ExtendThrottlerGuard {
async handleRequest(
context: ExecutionContext,
limit: number,
ttl: number,
throttler: ThrottlerOptions,
): Promise<boolean> {
const client = context.switchToWs().getClient()
const ip = client._socket.remoteAddress
const key = this.generateKey(context, ip, throttler.name || 'ws-default')
const { totalHits } = await this.storageService.increment(key, ttl)
// @Injectable()
// export class WsExtendThrottlerGuard extends ExtendThrottlerGuard {
// async handleRequest(
// context: ExecutionContext,
// limit: number,
// ttl: number,
// throttler: ThrottlerOptions,
// ): Promise<boolean> {
// const client = context.switchToWs().getClient()
// const ip = client._socket.remoteAddress
// const key = this.generateKey(context, ip, throttler.name || 'ws-default')
// const { totalHits } = await this.storageService.increment(key, ttl)
if (totalHits > limit) {
throw new ThrottlerException()
}
// if (totalHits > limit) {
// throw new ThrottlerException()
// }
return true
}
}
// return true
// }
// }

View File

@@ -14,7 +14,6 @@ import type {
import type { SocketType } from '../gateway.service'
import type { EventGatewayHooks } from './hook.interface'
import { UseGuards } from '@nestjs/common'
import {
ConnectedSocket,
MessageBody,
@@ -23,7 +22,6 @@ import {
WebSocketServer,
} from '@nestjs/websockets'
import { WsExtendThrottlerGuard } from '~/common/guards/throttler.guard'
import { BusinessEvents } from '~/constants/business-event.constant'
import { RedisKeys } from '~/constants/cache.constant'
import { CacheService } from '~/processors/redis/cache.service'
@@ -45,7 +43,7 @@ declare module '~/types/socket-meta' {
const namespace = 'web'
@UseGuards(WsExtendThrottlerGuard)
// @UseGuards(WsExtendThrottlerGuard)
@WebSocketGateway<GatewayMetadata>({
namespace,
})