MCPcopy
hub / github.com/FlowiseAI/Flowise / addRateLimiter

Method addRateLimiter

packages/server/src/utils/rateLimit.ts:94–126  ·  view source on GitHub ↗
(id: string, duration: number, limit: number, message: string)

Source from the content-addressed store, hash-verified

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)

Callers 3

updateRateLimiterMethod · 0.95
configMethod · 0.80

Calls 2

setMethod · 0.80
callMethod · 0.45

Tested by

no test coverage detected