@@ -70,12 +70,12 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
7070 private async analyze_image ( jobId : string , recordId : string , adminUser : any , headers : Record < string , string | string [ ] | undefined > ) {
7171 const selectedId = recordId ;
7272 let isError = false ;
73- if ( typeof ( this . options . rateLimits ?. fillFieldsFromImages ) === 'string' ) {
74- if ( this . checkRateLimit ( "fillFieldsFromImages" , this . options . rateLimits . fillFieldsFromImages , headers ) ) {
75- jobs . set ( jobId , { status : 'failed' , error : "Rate limit exceeded" } ) ;
76- return { error : "Rate limit exceeded" } ;
77- }
78- }
73+ // if (typeof(this.options.rateLimits?.fillFieldsFromImages) === 'string'){
74+ // if (this.checkRateLimit("fillFieldsFromImages" ,this.options.rateLimits.fillFieldsFromImages, headers)) {
75+ // jobs.set(jobId, { status: 'failed', error: "Rate limit exceeded" });
76+ // return { error: "Rate limit exceeded" };
77+ // }
78+ // }
7979 // Fetch the record using the provided ID
8080 const primaryKeyColumn = this . resourceConfig . columns . find ( ( col ) => col . primaryKey ) ;
8181 const record = await this . adminforth . resource ( this . resourceConfig . resourceId ) . get ( [ Filters . EQ ( primaryKeyColumn . name , selectedId ) ] ) ;
@@ -121,18 +121,22 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
121121 jobs . set ( jobId , { status : 'completed' , result } ) ;
122122 return { ok : true } ;
123123 }
124- } ;
124+ } else {
125+ jobs . set ( jobId , { status : 'failed' , error : "No attachment files found" } ) ;
126+ return { ok : false , error : "No attachment files found" } ;
127+ }
128+
125129 }
126130
127131 private async analyzeNoImages ( jobId : string , recordId : string , adminUser : any , headers : Record < string , string | string [ ] | undefined > ) {
128132 const selectedId = recordId ;
129133 let isError = false ;
130- if ( typeof ( this . options . rateLimits ?. fillPlainFields ) === 'string' ) {
131- if ( this . checkRateLimit ( "fillPlainFields" , this . options . rateLimits . fillPlainFields , headers ) ) {
132- jobs . set ( jobId , { status : 'failed' , error : "Rate limit exceeded" } ) ;
133- return { error : "Rate limit exceeded" } ;
134- }
135- }
134+ // if (typeof(this.options.rateLimits?.fillPlainFields) === 'string'){
135+ // if (this.checkRateLimit("fillPlainFields", this.options.rateLimits.fillPlainFields, headers)) {
136+ // jobs.set(jobId, { status: 'failed', error: "Rate limit exceeded" });
137+ // return { error: "Rate limit exceeded" };
138+ // }
139+ // }
136140 if ( STUB_MODE ) {
137141 await new Promise ( ( resolve ) => setTimeout ( resolve , Math . floor ( Math . random ( ) * 20000 ) + 1000 ) ) ;
138142 jobs . set ( jobId , { status : 'completed' , result : { } } ) ;
@@ -173,12 +177,12 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
173177 private async initialImageGenerate ( jobId : string , recordId : string , adminUser : any , headers : Record < string , string | string [ ] | undefined > ) {
174178 const selectedId = recordId ;
175179 let isError = false ;
176- if ( typeof ( this . options . rateLimits ?. generateImages ) === 'string' ) {
177- if ( this . checkRateLimit ( "generateImages" , this . options . rateLimits . generateImages , headers ) ) {
178- jobs . set ( jobId , { status : 'failed' , error : "Rate limit exceeded" } ) ;
179- return { error : "Rate limit exceeded" } ;
180- }
181- }
180+ // if (typeof(this.options.rateLimits?.generateImages) === 'string'){
181+ // if (this.checkRateLimit("generateImages", this.options.rateLimits.generateImages, headers)) {
182+ // jobs.set(jobId, { status: 'failed', error: "Rate limit exceeded" });
183+ // return { error: "Rate limit exceeded" };
184+ // }
185+ // }
182186 const start = + new Date ( ) ;
183187 const record = await this . adminforth . resource ( this . resourceConfig . resourceId ) . get ( [ Filters . EQ ( this . resourceConfig . columns . find ( c => c . primaryKey ) ?. name , selectedId ) ] ) ;
184188 let attachmentFiles
@@ -679,5 +683,31 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
679683 } ) ;
680684
681685
686+ server . endpoint ( {
687+ method : 'POST' ,
688+ path : `/plugin/${ this . pluginInstanceId } /update-rate-limits` ,
689+ handler : async ( { body, adminUser, headers } ) => {
690+ const actionType = body . actionType ;
691+ if ( actionType === 'analyze' && this . options . rateLimits ?. fillFieldsFromImages ) {
692+ if ( this . checkRateLimit ( "fillFieldsFromImages" , this . options . rateLimits . fillFieldsFromImages , headers ) ) {
693+ return { ok : false , error : "Rate limit exceeded for image analyze" } ;
694+ }
695+ }
696+ if ( actionType === 'analyze_no_images' && this . options . rateLimits ?. fillPlainFields ) {
697+ if ( this . checkRateLimit ( "fillPlainFields" , this . options . rateLimits . fillPlainFields , headers ) ) {
698+ return { ok : false , error : "Rate limit exceeded for plain field analyze" } ;
699+ }
700+ }
701+ if ( actionType === 'generate_images' && this . options . rateLimits ?. generateImages ) {
702+ if ( this . checkRateLimit ( "generateImages" , this . options . rateLimits . generateImages , headers ) ) {
703+ return { ok : false , error : "Rate limit exceeded for image generation" } ;
704+ }
705+ }
706+
707+ return { ok : true } ;
708+ }
709+ } ) ;
710+
711+
682712 }
683713}
0 commit comments