This commit is contained in:
Nicolas 2025-01-07 17:49:21 -03:00
parent a185c05a5c
commit b98e289f03
4 changed files with 47 additions and 2 deletions

View File

@ -8,7 +8,28 @@ import {
import { getExtractQueue } from "../../services/queue-service"; import { getExtractQueue } from "../../services/queue-service";
import * as Sentry from "@sentry/node"; import * as Sentry from "@sentry/node";
import { saveExtract } from "../../lib/extract/extract-redis"; import { saveExtract } from "../../lib/extract/extract-redis";
import { getTeamIdSyncB } from "../../lib/extract/team-id-sync";
import { performExtraction } from "../../lib/extract/extraction-service";
export async function oldExtract(req: RequestWithAuth<{}, ExtractResponse, ExtractRequest>, res: Response<ExtractResponse>, extractId: string){
// Means that are in the non-queue system
// TODO: Remove this once all teams have transitioned to the new system
try {
const result = await performExtraction(extractId, {
request: req.body,
teamId: req.auth.team_id,
plan: req.auth.plan ?? "free",
subId: req.acuc?.sub_id ?? undefined,
});
return res.status(200).json(result);
} catch (error) {
return res.status(500).json({
success: false,
error: "Internal server error",
});
}
}
/** /**
* Extracts data from the provided URLs based on the request parameters. * Extracts data from the provided URLs based on the request parameters.
* Currently in beta. * Currently in beta.
@ -32,6 +53,10 @@ export async function extractController(
extractId, extractId,
}; };
if(await getTeamIdSyncB(req.auth.team_id) && req.body.origin !== "api-sdk") {
return await oldExtract(req, res, extractId);
}
await saveExtract(extractId, { await saveExtract(extractId, {
id: extractId, id: extractId,
team_id: req.auth.team_id, team_id: req.auth.team_id,

View File

@ -0,0 +1,19 @@
import { supabase_service } from "../../services/supabase";
import { logger } from "../logger";
export async function getTeamIdSyncB(teamId: string) {
try {
const { data, error } = await supabase_service
.from("eb-sync")
.select("team_id")
.eq("team_id", teamId)
.limit(1);
if (error) {
throw new Error("Error getting team id (sync b)");
}
return data[0] ?? null;
} catch (error) {
logger.error("Error getting team id (sync b)", error);
return null;
}
}

View File

@ -884,7 +884,7 @@ export default class FirecrawlApp {
try { try {
const response: AxiosResponse = await this.postRequest( const response: AxiosResponse = await this.postRequest(
this.apiUrl + `/v1/extract`, this.apiUrl + `/v1/extract`,
{ ...jsonData, schema: jsonSchema }, { ...jsonData, schema: jsonSchema, origin: "api-sdk" },
headers headers
); );

View File

@ -538,7 +538,8 @@ class FirecrawlApp:
request_data = { request_data = {
**jsonData, **jsonData,
'allowExternalLinks': params.get('allow_external_links', False), 'allowExternalLinks': params.get('allow_external_links', False),
'schema': schema 'schema': schema,
'origin': 'api-sdk'
} }
try: try: