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 @@ -24,10 +24,15 @@ export default class RichEditorPlugin extends AdminForthPlugin {
2424 attachmentResource : AdminForthResource = undefined ;
2525
2626 adminforth : IAdminForth ;
27+
28+ rateLimiter : RateLimiter ;
2729
2830 constructor ( options : PluginOptions ) {
2931 super ( options , import . meta. url ) ;
3032 this . options = options ;
33+ if ( this . options . completion . rateLimit ?. limit ) {
34+ this . rateLimiter = new RateLimiter ( this . options . completion . rateLimit ?. limit ) ;
35+ }
3136 }
3237
3338 async modifyResourceConfig ( adminforth : IAdminForth , resourceConfig : AdminForthResource ) {
@@ -271,15 +276,14 @@ export default class RichEditorPlugin extends AdminForthPlugin {
271276 handler : async ( { body, headers } ) => {
272277 const { record } = body ;
273278
274- if ( this . options . completion . rateLimit ?. limit ) {
279+ if ( this . rateLimiter ) {
275280 // rate limit
276281 // const { error } = RateLimiter.checkRateLimit(
277282 // this.pluginInstanceId,
278283 // this.options.completion.rateLimit?.limit,
279284 // this.adminforth.auth.getClientIp(headers),
280285 // );
281- const rateLimiter = new RateLimiter ( this . options . completion . rateLimit ?. limit ) ;
282- if ( ! rateLimiter . consume ( `${ this . pluginInstanceId } -${ this . adminforth . auth . getClientIp ( headers ) } ` ) ) {
286+ if ( ! await this . rateLimiter . consume ( `${ this . pluginInstanceId } -${ this . adminforth . auth . getClientIp ( headers ) } ` ) ) {
283287 return {
284288 completion : [ ] ,
285289 }
You can’t perform that action at this time.
0 commit comments