(id: string, duration: number, limit: number, message: string)
| 92 | } |
| 93 | |
| 94 | public async addRateLimiter(id: string, duration: number, limit: number, message: string): Promise<void> { |
| 95 | const release = await this.rateLimiterMutex.acquire() |
| 96 | try { |
| 97 | if (process.env.MODE === MODE.QUEUE) { |
| 98 | this.rateLimiters.set( |
| 99 | id, |
| 100 | rateLimit({ |
| 101 | windowMs: duration * 1000, |
| 102 | max: limit, |
| 103 | standardHeaders: true, |
| 104 | legacyHeaders: false, |
| 105 | message, |
| 106 | store: new RedisStore({ |
| 107 | prefix: `rl:${id}`, |
| 108 | // @ts-expect-error - Known issue: the `call` function is not present in @types/ioredis |
| 109 | sendCommand: (...args: string[]) => this.redisClient.call(...args) |
| 110 | }) |
| 111 | }) |
| 112 | ) |
| 113 | } else { |
| 114 | this.rateLimiters.set( |
| 115 | id, |
| 116 | rateLimit({ |
| 117 | windowMs: duration * 1000, |
| 118 | max: limit, |
| 119 | message |
| 120 | }) |
| 121 | ) |
| 122 | } |
| 123 | } finally { |
| 124 | release() |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | public removeRateLimiter(id: string): void { |
| 129 | this.rateLimiters.delete(id) |
no test coverage detected