Skip to content

Commit 52247ad

Browse files
Rework rate-limiter
1 parent 5e6b0ef commit 52247ad

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

index.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,13 @@ export default class TextCompletePlugin extends AdminForthPlugin {
8080
handler: async ({ body, headers }) => {
8181
if (this.options.rateLimit?.limit) {
8282
// rate limit
83-
const { error } = RateLimiter.checkRateLimit(
84-
this.pluginInstanceId,
85-
this.options.rateLimit?.limit,
86-
this.adminforth.auth.getClientIp(headers),
87-
);
88-
if (error) {
83+
// const { error } = RateLimiter.checkRateLimit(
84+
// this.pluginInstanceId,
85+
// this.options.rateLimit?.limit,
86+
// this.adminforth.auth.getClientIp(headers),
87+
// );
88+
const rateLimiter = new RateLimiter(this.options.rateLimit?.limit);
89+
if (!rateLimiter.consume(`${this.pluginInstanceId}-${this.adminforth.auth.getClientIp(headers)}`)) {
8990
return {
9091
completion: [],
9192
}

0 commit comments

Comments
 (0)