Files
firecrawl/apps/api/src/controllers/v1/extract-status.ts
T

43 lines
1.2 KiB
TypeScript
Raw Normal View History

2025-01-03 20:44:27 -03:00
import { Response } from "express";
2025-01-07 12:13:12 -03:00
import { supabaseGetJobsById } from "../../lib/supabase-jobs";
2025-01-03 20:44:27 -03:00
import { RequestWithAuth } from "./types";
2025-01-07 16:16:01 -03:00
import { getExtract, getExtractExpiry } from "../../lib/extract/extract-redis";
2025-01-03 20:44:27 -03:00
export async function extractStatusController(
req: RequestWithAuth<{ jobId: string }, any, any>,
res: Response,
) {
2025-01-07 16:16:01 -03:00
const extract = await getExtract(req.params.jobId);
if (!extract) {
2025-01-07 12:13:12 -03:00
return res.status(404).json({
success: false,
2025-01-07 16:16:01 -03:00
error: "Extract job not found",
2025-01-03 20:44:27 -03:00
});
}
2025-01-07 12:13:12 -03:00
2025-01-07 16:16:01 -03:00
let data: any[] = [];
if (extract.status === "completed") {
const jobData = await supabaseGetJobsById([req.params.jobId]);
if (!jobData || jobData.length === 0) {
return res.status(404).json({
success: false,
error: "Job not found",
});
}
data = jobData[0].docs;
}
2025-01-07 12:13:12 -03:00
return res.status(200).json({
success: extract.status === "failed" ? false : true,
2025-01-07 16:16:01 -03:00
data: data,
status: extract.status,
error: extract?.error ?? undefined,
2025-01-07 16:16:01 -03:00
expiresAt: (await getExtractExpiry(req.params.jobId)).toISOString(),
2025-01-14 01:45:50 -03:00
steps: extract.showSteps ? extract.steps : undefined,
llmUsage: extract.showLLMUsage ? extract.llmUsage : undefined,
2025-01-07 12:13:12 -03:00
});
2025-01-03 20:44:27 -03:00
}