mirror of
https://github.com/mendableai/firecrawl.git
synced 2024-11-16 11:42:24 +08:00
Nick:
This commit is contained in:
parent
1805d901a9
commit
ee3e5dc69c
|
@ -312,12 +312,12 @@ export function legacyScrapeOptions(x: ScrapeOptions): PageOptions {
|
|||
};
|
||||
}
|
||||
|
||||
export function legacyExtractorOptions(x: ExtractOptions): ExtractorOptions {
|
||||
export function legacyExtractorOptions(x?: ExtractOptions): ExtractorOptions {
|
||||
return {
|
||||
mode: x.mode ? "llm-extraction" : "markdown",
|
||||
extractionPrompt: x.prompt ?? "Based on the information on the page, extract the information from the schema.",
|
||||
extractionSchema: x.schema,
|
||||
userPrompt: x.prompt ?? "",
|
||||
mode: x?.mode ? "llm-extraction" : "markdown",
|
||||
extractionPrompt: x?.prompt ?? "Based on the information on the page, extract the information from the schema.",
|
||||
extractionSchema: x?.schema,
|
||||
userPrompt: x?.prompt ?? "",
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -199,27 +199,44 @@ export async function supaCheckTeamCredits(team_id: string, credits: number) {
|
|||
);
|
||||
}
|
||||
|
||||
if(subscriptionError) {
|
||||
Logger.error(`Subscription error: ${subscriptionError}`);
|
||||
throw new Error(`Subscription error: ${subscriptionError}`);
|
||||
}
|
||||
|
||||
|
||||
// Free credits, no coupons
|
||||
if (!subscription) {
|
||||
if (!subscription || subscriptionError) {
|
||||
|
||||
// If there is no active subscription but there are available coupons
|
||||
if (couponCredits >= credits) {
|
||||
return { success: true, message: "Sufficient credits available", remainingCredits: couponCredits };
|
||||
}
|
||||
|
||||
const { data: creditUsages, error: creditUsageError } =
|
||||
await supabase_service
|
||||
let creditUsages;
|
||||
let creditUsageError;
|
||||
let retries = 0;
|
||||
const maxRetries = 3;
|
||||
const retryInterval = 2000; // 2 seconds
|
||||
|
||||
while (retries < maxRetries) {
|
||||
const result = await supabase_service
|
||||
.from("credit_usage")
|
||||
.select("credits_used")
|
||||
.is("subscription_id", null)
|
||||
.eq("team_id", team_id);
|
||||
|
||||
creditUsages = result.data;
|
||||
creditUsageError = result.error;
|
||||
|
||||
if (!creditUsageError) {
|
||||
break;
|
||||
}
|
||||
|
||||
retries++;
|
||||
if (retries < maxRetries) {
|
||||
await new Promise(resolve => setTimeout(resolve, retryInterval));
|
||||
}
|
||||
}
|
||||
|
||||
if (creditUsageError) {
|
||||
Logger.error(`Credit usage error: ${creditUsageError}`);
|
||||
Logger.error(`Credit usage error after ${maxRetries} attempts: ${creditUsageError}`);
|
||||
throw new Error(
|
||||
`Failed to retrieve credit usage for team_id: ${team_id}`
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue
Block a user