Skip to content

Commit

Permalink
remove limiterService as we only use limiter from a limiter middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianboros committed Sep 26, 2024
1 parent 0fd372b commit aec4c9f
Showing 1 changed file with 0 additions and 31 deletions.
31 changes: 0 additions & 31 deletions packages/wallet/backend/src/rateLimit/service.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
import Redis from 'ioredis'
import {
RateLimiterRes,
RateLimiterRedis,
IRateLimiterRedisOptions
} from 'rate-limiter-flexible'

import type { Env } from '@/config/env'
import { TooManyRequests } from '@shared/backend'

interface getLimiterlArgs {
key: string
maxWrongAttempts: number
wrongAttemptsPause: number
}
interface IRateLimitService {
buildLimiter(args: getLimiterlArgs): Promise<RateLimiterRedis>
}
interface IRateLimiterRedisHelper {
checkAttempts(inputKey: string): Promise<void>
useAttempt(inputKey: string): Promise<void>
Expand Down Expand Up @@ -66,24 +56,3 @@ export class RateLimiterRedisHelper
}
}
}
export class RateLimitService implements IRateLimitService {
private redisClient: Redis
constructor(private env: Env) {
const redis_url = this.env.REDIS_URL
this.redisClient = new Redis(redis_url)
}

public async buildLimiter({
key,
maxWrongAttempts,
wrongAttemptsPause
}: getLimiterlArgs) {
return new RateLimiterRedisHelper({
storeClient: this.redisClient,
keyPrefix: key,
points: maxWrongAttempts,
duration: 60 * 60 * 24,
blockDuration: 60 * wrongAttemptsPause
})
}
}

0 comments on commit aec4c9f

Please sign in to comment.