8d467c8ca7
* feat: use strictNullChecking * feat: switch logger to Winston * feat(scrapeURL): first batch * fix(scrapeURL): error swallow * fix(scrapeURL): add timeout to EngineResultsTracker * fix(scrapeURL): report unexpected error to sentry * chore: remove unused modules * feat(transfomers/coerce): warn when a format's response is missing * feat(scrapeURL): feature flag priorities, engine quality sorting, PDF and DOCX support * (add note) * feat(scrapeURL): wip readme * feat(scrapeURL): LLM extract * feat(scrapeURL): better warnings * fix(scrapeURL/engines/fire-engine;playwright): fix screenshot * feat(scrapeURL): add forceEngine internal option * feat(scrapeURL/engines): scrapingbee * feat(scrapeURL/transformars): uploadScreenshot * feat(scrapeURL): more intense tests * bunch of stuff * get rid of WebScraper (mostly) * adapt batch scrape * add staging deploy workflow * fix yaml * fix logger issues * fix v1 test schema * feat(scrapeURL/fire-engine/chrome-cdp): remove wait inserts on actions * scrapeURL: v0 backwards compat * logger fixes * feat(scrapeurl): v0 returnOnlyUrls support * fix(scrapeURL/v0): URL leniency * fix(batch-scrape): ts non-nullable * fix(scrapeURL/fire-engine/chromecdp): fix wait action * fix(logger): remove error debug key * feat(requests.http): use dotenv expression * fix(scrapeURL/extractMetadata): extract custom metadata * fix crawl option conversion * feat(scrapeURL): Add retry logic to robustFetch * fix(scrapeURL): crawl stuff * fix(scrapeURL): LLM extract * fix(scrapeURL/v0): search fix * fix(tests/v0): grant larger response size to v0 crawl status * feat(scrapeURL): basic fetch engine * feat(scrapeURL): playwright engine * feat(scrapeURL): add url-specific parameters * Update readme and examples * added e2e tests for most parameters. Still a few actions, location and iframes to be done. * fixed type * Nick: * Update scrape.ts * Update index.ts * added actions and base64 check * Nick: skipTls feature flag? * 403 * todo * todo * fixes * yeet headers from url specific params * add warning when final engine has feature deficit * expose engine results tracker for ScrapeEvents implementation * ingest scrape events * fixed some tests * comment * Update index.test.ts * fixed rawHtml * Update index.test.ts * update comments * move geolocation to global f-e option, fix removeBase64Images * Nick: * trim url-specific params * Update index.ts --------- Co-authored-by: Eric Ciarla <ericciarla@yahoo.com> Co-authored-by: rafaelmmiller <8574157+rafaelmmiller@users.noreply.github.com> Co-authored-by: Nicolas <nicolascamara29@gmail.com>
44 lines
1.6 KiB
TypeScript
44 lines
1.6 KiB
TypeScript
import { Request, Response } from "express";
|
|
import { logger } from "../../../src/lib/logger";
|
|
import { getCrawl, getCrawlJobs } from "../../../src/lib/crawl-redis";
|
|
import { getJobs } from "./crawl-status";
|
|
import * as Sentry from "@sentry/node";
|
|
|
|
export async function crawlJobStatusPreviewController(req: Request, res: Response) {
|
|
try {
|
|
const sc = await getCrawl(req.params.jobId);
|
|
if (!sc) {
|
|
return res.status(404).json({ error: "Job not found" });
|
|
}
|
|
|
|
const jobIDs = await getCrawlJobs(req.params.jobId);
|
|
|
|
// let data = job.returnvalue;
|
|
// if (process.env.USE_DB_AUTHENTICATION === "true") {
|
|
// const supabaseData = await supabaseGetJobById(req.params.jobId);
|
|
|
|
// if (supabaseData) {
|
|
// data = supabaseData.docs;
|
|
// }
|
|
// }
|
|
|
|
const jobs = (await getJobs(req.params.jobId, jobIDs)).sort((a, b) => a.timestamp - b.timestamp);
|
|
const jobStatuses = await Promise.all(jobs.map(x => x.getState()));
|
|
const jobStatus = sc.cancelled ? "failed" : jobStatuses.every(x => x === "completed") ? "completed" : jobStatuses.some(x => x === "failed") ? "failed" : "active";
|
|
|
|
const data = jobs.map(x => Array.isArray(x.returnvalue) ? x.returnvalue[0] : x.returnvalue);
|
|
|
|
res.json({
|
|
status: jobStatus,
|
|
current: jobStatuses.filter(x => x === "completed" || x === "failed").length,
|
|
total: jobs.length,
|
|
data: jobStatus === "completed" ? data : null,
|
|
partial_data: jobStatus === "completed" ? [] : data.filter(x => x !== null),
|
|
});
|
|
} catch (error) {
|
|
Sentry.captureException(error);
|
|
logger.error(error);
|
|
return res.status(500).json({ error: error.message });
|
|
}
|
|
}
|