firecrawl/apps/api/src/controllers/v1/crawl-status.ts

69 lines
1.7 KiB
TypeScript
Raw Normal View History

import { Response } from "express";
2024-08-06 15:24:45 -03:00
import { v4 as uuidv4 } from "uuid";
import { RequestWithAuth } from "./types";
2024-08-06 15:24:45 -03:00
export async function crawlStatusController(req: RequestWithAuth, res: Response) {
// const job = await getWebScraperQueue().getJob(req.params.jobId);
// if (!job) {
// return res.status(404).json({ error: "Job not found" });
// }
2024-08-06 15:24:45 -03:00
// const { current, current_url, total, current_step, partialDocs } = await job.progress();
2024-08-06 15:24:45 -03:00
// let data = job.returnvalue;
// if (process.env.USE_DB_AUTHENTICATION === "true") {
// const supabaseData = await supabaseGetJobById(req.params.jobId);
2024-08-06 15:24:45 -03:00
// if (supabaseData) {
// data = supabaseData.docs;
// }
// }
2024-08-06 15:24:45 -03:00
// const jobStatus = await job.getState();
2024-08-06 15:24:45 -03:00
// mock:
const id = uuidv4();
const result = {
totalCount: 100,
creditsUsed: 2,
expiresAt: new Date(Date.now() + 24 * 60 * 60 * 1000).getTime(),
status: "scraping", // scraping, completed, failed
next: `${req.protocol}://${req.get("host")}/v1/crawl/${id}`,
data: [{
markdown: "test",
content: "test",
html: "test",
rawHtml: "test",
linksOnPage: ["test1", "test2"],
screenshot: "test",
metadata: {
title: "test",
description: "test",
language: "test",
sourceURL: "test",
statusCode: 200,
error: "test"
}
},
{
markdown: "test",
content: "test",
html: "test",
rawHtml: "test",
linksOnPage: ["test1", "test2"],
screenshot: "test",
metadata: {
title: "test",
description: "test",
language: "test",
sourceURL: "test",
statusCode: 200,
error: "test"
}
}]
2024-08-06 15:24:45 -03:00
}
res.status(200).json(result);
2024-08-06 15:24:45 -03:00
}