@@ -70,12 +70,12 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
70
70
private async analyze_image ( jobId : string , recordId : string , adminUser : any , headers : Record < string , string | string [ ] | undefined > ) {
71
71
const selectedId = recordId ;
72
72
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
+ // }
79
79
// Fetch the record using the provided ID
80
80
const primaryKeyColumn = this . resourceConfig . columns . find ( ( col ) => col . primaryKey ) ;
81
81
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 {
121
121
jobs . set ( jobId , { status : 'completed' , result } ) ;
122
122
return { ok : true } ;
123
123
}
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
+
125
129
}
126
130
127
131
private async analyzeNoImages ( jobId : string , recordId : string , adminUser : any , headers : Record < string , string | string [ ] | undefined > ) {
128
132
const selectedId = recordId ;
129
133
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
+ // }
136
140
if ( STUB_MODE ) {
137
141
await new Promise ( ( resolve ) => setTimeout ( resolve , Math . floor ( Math . random ( ) * 20000 ) + 1000 ) ) ;
138
142
jobs . set ( jobId , { status : 'completed' , result : { } } ) ;
@@ -173,12 +177,12 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
173
177
private async initialImageGenerate ( jobId : string , recordId : string , adminUser : any , headers : Record < string , string | string [ ] | undefined > ) {
174
178
const selectedId = recordId ;
175
179
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
+ // }
182
186
const start = + new Date ( ) ;
183
187
const record = await this . adminforth . resource ( this . resourceConfig . resourceId ) . get ( [ Filters . EQ ( this . resourceConfig . columns . find ( c => c . primaryKey ) ?. name , selectedId ) ] ) ;
184
188
let attachmentFiles
@@ -679,5 +683,31 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
679
683
} ) ;
680
684
681
685
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
+
682
712
}
683
713
}
0 commit comments