Skip to content

Commit 79b03ce

Browse files
fix: rate-limiter
1 parent 796e46b commit 79b03ce

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
5555
return this.compileTemplates(this.options.generateImages, record, v => String(v.prompt));
5656
}
5757

58-
private checkRateLimit(field: string, fieldNameRateLimit: string | undefined, headers: Record<string, string | string[] | undefined>): { error?: string } | void {
58+
private async checkRateLimit(field: string, fieldNameRateLimit: string | undefined, headers: Record<string, string | string[] | undefined>): Promise<void | { error?: string; }> {
5959
if (fieldNameRateLimit) {
6060
// rate limit
6161
// const { error } = RateLimiter.checkRateLimit(
@@ -274,7 +274,7 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
274274
private async regenerateImage(jobId: string, recordId: string, fieldName: string, prompt: string, adminUser: any, headers: Record<string, string | string[] | undefined>) {
275275
const Id = recordId;
276276
let isError = false;
277-
if (this.checkRateLimit(fieldName, this.options.generateImages[fieldName].rateLimit, headers)) {
277+
if (await this.checkRateLimit(fieldName, this.options.generateImages[fieldName].rateLimit, headers)) {
278278
jobs.set(jobId, { status: 'failed', error: "Rate limit exceeded" });
279279
return { error: "Rate limit exceeded" };
280280
}
@@ -742,17 +742,17 @@ export default class BulkAiFlowPlugin extends AdminForthPlugin {
742742
handler: async ({ body, adminUser, headers }) => {
743743
const actionType = body.actionType;
744744
if (actionType === 'analyze' && this.options.rateLimits?.fillFieldsFromImages) {
745-
if (this.checkRateLimit("fillFieldsFromImages" ,this.options.rateLimits.fillFieldsFromImages, headers)) {
745+
if (await this.checkRateLimit("fillFieldsFromImages" ,this.options.rateLimits.fillFieldsFromImages, headers)) {
746746
return {ok: false, error: "Rate limit exceeded for image analyze" };
747747
}
748748
}
749749
if (actionType === 'analyze_no_images' && this.options.rateLimits?.fillPlainFields) {
750-
if (this.checkRateLimit("fillPlainFields" ,this.options.rateLimits.fillPlainFields, headers)) {
750+
if (await this.checkRateLimit("fillPlainFields" ,this.options.rateLimits.fillPlainFields, headers)) {
751751
return {ok: false, error: "Rate limit exceeded for plain field analyze" };
752752
}
753753
}
754754
if (actionType === 'generate_images' && this.options.rateLimits?.generateImages) {
755-
if (this.checkRateLimit("generateImages" ,this.options.rateLimits.generateImages, headers)) {
755+
if (await this.checkRateLimit("generateImages" ,this.options.rateLimits.generateImages, headers)) {
756756
return {ok: false, error: "Rate limit exceeded for image generation" };
757757
}
758758
}

0 commit comments

Comments
 (0)