Spaces:
Sleeping
Sleeping
File size: 1,815 Bytes
097eaf0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | import { supabaseGetScrapeByIdOnlyData } from "../../lib/supabase-jobs";
import { getJob } from "./crawl-status";
import { logger as _logger } from "../../lib/logger";
import { getScrapeZDR } from "../../lib/zdr-helpers";
export async function scrapeStatusController(req: any, res: any) {
const uuidReg =
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
if (!req.params.jobId || !uuidReg.test(req.params.jobId)) {
return res.status(400).json({
success: false,
error: "Invalid crawl ID",
});
}
const logger = _logger.child({
module: "scrape-status",
method: "scrapeStatusController",
teamId: req.auth.team_id,
jobId: req.params.jobId,
scrapeId: req.params.jobId,
zeroDataRetention: getScrapeZDR(req.acuc?.flags) === "forced",
});
if (getScrapeZDR(req.acuc?.flags) === "forced") {
return res.status(400).json({
success: false,
error:
"Your team has zero data retention enabled. This is not supported on scrape status. Please contact support@firecrawl.com to unblock this feature.",
});
}
const job = await supabaseGetScrapeByIdOnlyData(req.params.jobId, logger);
if (!job) {
return res.status(404).json({
success: false,
error: "Job not found.",
});
}
if (job?.team_id !== req.auth.team_id) {
return res.status(403).json({
success: false,
error: "You are not allowed to access this resource.",
});
}
const jobData = await getJob(req.params.jobId, logger);
const data = Array.isArray(jobData?.returnvalue)
? jobData?.returnvalue[0]
: jobData?.returnvalue;
if (!data) {
return res.status(404).json({
success: false,
error: "Job not found.",
});
}
return res.status(200).json({
success: true,
data,
});
}
|