2025-06-04 18:14:23 +02:00
|
|
|
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);
|
|
|
|
|
2025-06-23 16:33:02 +02:00
|
|
|
const crawls = (await Promise.all(ids.map(async id => ({ ...(await getCrawl(id)), id })))).filter((crawl) => crawl !== null && !crawl.cancelled && crawl.crawlerOptions);
|
2025-06-04 18:14:23 +02:00
|
|
|
|
|
|
|
res.status(200).json({
|
|
|
|
success: true,
|
|
|
|
crawls: crawls.map(x => ({
|
|
|
|
id: x.id,
|
|
|
|
teamId: x.team_id!,
|
|
|
|
url: x.originUrl!,
|
2025-06-26 17:58:34 +00:00
|
|
|
created_at: new Date(x.createdAt || Date.now()).toISOString(),
|
2025-06-04 18:14:23 +02:00
|
|
|
options: {
|
|
|
|
...toNewCrawlerOptions(x.crawlerOptions),
|
|
|
|
scrapeOptions: x.scrapeOptions,
|
|
|
|
},
|
|
|
|
})),
|
|
|
|
});
|
|
|
|
}
|