File tree Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -12,9 +12,14 @@ export default class TextCompletePlugin extends AdminForthPlugin {
1212
1313 adminforth ! : IAdminForth ;
1414
15+ rateLimiter ?: RateLimiter ;
16+
1517 constructor ( options : PluginOptions ) {
1618 super ( options , import . meta. url ) ;
1719 this . options = options ;
20+ if ( options . rateLimit ?. limit ) {
21+ this . rateLimiter = new RateLimiter ( options . rateLimit ?. limit ) ;
22+ }
1823 }
1924
2025 instanceUniqueRepresentation ( pluginOptions : any ) : string {
@@ -78,15 +83,14 @@ export default class TextCompletePlugin extends AdminForthPlugin {
7883 method : 'POST' ,
7984 path : `/plugin/${ this . pluginInstanceId } /doComplete` ,
8085 handler : async ( { body, headers } ) => {
81- if ( this . options . rateLimit ?. limit ) {
86+ if ( this . rateLimiter ) {
8287 // rate limit
8388 // const { error } = RateLimiter.checkRateLimit(
8489 // this.pluginInstanceId,
8590 // this.options.rateLimit?.limit,
8691 // this.adminforth.auth.getClientIp(headers),
8792 // );
88- const rateLimiter = new RateLimiter ( this . options . rateLimit ?. limit ) ;
89- if ( ! rateLimiter . consume ( `${ this . pluginInstanceId } -${ this . adminforth . auth . getClientIp ( headers ) } ` ) ) {
93+ if ( ! await this . rateLimiter . consume ( `${ this . pluginInstanceId } -${ this . adminforth . auth . getClientIp ( headers ) } ` ) ) {
9094 return {
9195 completion : [ ] ,
9296 }
You can’t perform that action at this time.
0 commit comments