From 6ceb7ff50a9c73888a49da2bd0dee70ead23579b Mon Sep 17 00:00:00 2001 From: Nicolas Date: Thu, 30 May 2024 14:46:55 -0700 Subject: [PATCH] Nick: --- apps/api/src/controllers/auth.ts | 3 ++- apps/api/src/controllers/scrape.ts | 12 ++++++++---- apps/api/src/types.ts | 1 + 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/apps/api/src/controllers/auth.ts b/apps/api/src/controllers/auth.ts index 2154504..bd246d7 100644 --- a/apps/api/src/controllers/auth.ts +++ b/apps/api/src/controllers/auth.ts @@ -29,6 +29,7 @@ export async function supaAuthenticateUser( team_id?: string; error?: string; status?: number; + plan?: string; }> { const authHeader = req.headers.authorization; if (!authHeader) { @@ -173,7 +174,7 @@ export async function supaAuthenticateUser( subscriptionData = data[0]; } - return { success: true, team_id: subscriptionData.team_id }; + return { success: true, team_id: subscriptionData.team_id, plan: subscriptionData.plan ?? ""}; } function getPlanByPriceId(price_id: string) { diff --git a/apps/api/src/controllers/scrape.ts b/apps/api/src/controllers/scrape.ts index 2049900..8314e49 100644 --- a/apps/api/src/controllers/scrape.ts +++ b/apps/api/src/controllers/scrape.ts @@ -15,7 +15,8 @@ export async function scrapeHelper( crawlerOptions: any, pageOptions: PageOptions, extractorOptions: ExtractorOptions, - timeout: number + timeout: number, + plan?: string ): Promise<{ success: boolean; error?: string; @@ -64,7 +65,9 @@ export async function scrapeHelper( } let creditsToBeBilled = filteredDocs.length; - const creditsPerLLMExtract = 50; + const creditsPerLLMExtract = plan === "starter" ? 5 : 50; + + if (extractorOptions.mode === "llm-extraction") { creditsToBeBilled = creditsToBeBilled + (creditsPerLLMExtract * filteredDocs.length); @@ -93,7 +96,7 @@ export async function scrapeHelper( export async function scrapeController(req: Request, res: Response) { try { // make sure to authenticate user first, Bearer - const { success, team_id, error, status } = await authenticateUser( + const { success, team_id, error, status, plan } = await authenticateUser( req, res, RateLimiterMode.Scrape @@ -129,7 +132,8 @@ export async function scrapeController(req: Request, res: Response) { crawlerOptions, pageOptions, extractorOptions, - timeout + timeout, + plan ); const endTime = new Date().getTime(); const timeTakenInSeconds = (endTime - startTime) / 1000; diff --git a/apps/api/src/types.ts b/apps/api/src/types.ts index b9b5463..d6a737e 100644 --- a/apps/api/src/types.ts +++ b/apps/api/src/types.ts @@ -57,6 +57,7 @@ export interface AuthResponse { team_id?: string; error?: string; status?: number; + plan?: string; }