@@ -8,23 +8,12 @@ import { evaluateAnswer } from "@/app/server/services/ai/evaluateAnswer";
88import { validateEvaluateAnswerAPIFormData } from "@/app/server/validators/asp-ai.validators" ;
99import { getAuthenticatedUser } from "@/app/server/utils/getAuthUserDetails" ;
1010import { User } from "@prisma/client" ;
11- import { Duration , Ratelimit } from "@upstash/ratelimit" ;
12- import { Redis } from "@upstash/redis" ;
1311import { ErrorCodes } from "@/app/lib/constants" ;
12+ import RatelimitService from "@/app/server/services/integrations/rateLimitig.service" ;
1413
15- const redis = new Redis ( {
16- url : process . env . UPSTASH_REDIS_URL ,
17- token : process . env . UPSTASH_REDIS_TOKEN ,
18- } ) ;
19- const ratelimit = new Ratelimit ( {
20- redis : redis ,
21- limiter : Ratelimit . fixedWindow (
22- parseInt ( process . env . DEFAULT_API_TOKENS ! ) ,
23- process . env . DEFAULT_API_TOKEN_FILLED_AFTER ! as Duration ,
24- ) ,
25- } ) ;
26- const s3 = new S3Service ( process . env . AWS_S3_BUCKET_NAME ! ) ;
27- const textExtract = new TextractService ( process . env . AWS_S3_BUCKET_NAME ! ) ;
14+ const s3 = S3Service . getInstance ( process . env . AWS_S3_BUCKET_NAME ! ) ;
15+ const textExtract = TextractService . getInstance ( process . env . AWS_S3_BUCKET_NAME ! ) ;
16+ const rl = RatelimitService . getInstance ( ) . getRatelimit ( )
2817
2918export const maxDuration = 60 ;
3019
@@ -41,7 +30,7 @@ export async function POST(req: Request) {
4130
4231 // Rate limiting
4332 //apiPath:keyPerfix:key
44- const rateLimitCheck = await ratelimit . limit (
33+ const rateLimitCheck = await rl . limit (
4534 `/asp-ai/evaluate-answer:userId:${ user . id } ` ,
4635 ) ;
4736
0 commit comments