mirror of
https://github.com/mendableai/firecrawl.git
synced 2025-06-27 00:41:33 +00:00

- Updated OngoingCrawlsResponse type to include created_at field - Modified ongoingCrawlsController to return ISO timestamp from createdAt - Added comprehensive tests for created_at field validation - Updated requests.http with test endpoint for /crawl/active - Tested endpoint manually and confirmed working correctly Co-Authored-By: rafael@sideguide.dev <rafael@sideguide.dev>
36 lines
988 B
TypeScript
36 lines
988 B
TypeScript
import { Response } from "express";
|
|
import {
|
|
OngoingCrawlsResponse,
|
|
RequestWithAuth,
|
|
toNewCrawlerOptions,
|
|
} from "./types";
|
|
import {
|
|
getCrawl,
|
|
getCrawlsByTeamId,
|
|
} from "../../lib/crawl-redis";
|
|
import { configDotenv } from "dotenv";
|
|
configDotenv();
|
|
|
|
export async function ongoingCrawlsController(
|
|
req: RequestWithAuth<{}, undefined, OngoingCrawlsResponse>,
|
|
res: Response<OngoingCrawlsResponse>,
|
|
) {
|
|
const ids = await getCrawlsByTeamId(req.auth.team_id);
|
|
|
|
const crawls = (await Promise.all(ids.map(async id => ({ ...(await getCrawl(id)), id })))).filter((crawl) => crawl !== null && !crawl.cancelled && crawl.crawlerOptions);
|
|
|
|
res.status(200).json({
|
|
success: true,
|
|
crawls: crawls.map(x => ({
|
|
id: x.id,
|
|
teamId: x.team_id!,
|
|
url: x.originUrl!,
|
|
created_at: new Date(x.createdAt || Date.now()).toISOString(),
|
|
options: {
|
|
...toNewCrawlerOptions(x.crawlerOptions),
|
|
scrapeOptions: x.scrapeOptions,
|
|
},
|
|
})),
|
|
});
|
|
}
|