mirror of
https://git.mirrors.martin98.com/https://github.com/mendableai/firecrawl
synced 2025-08-12 21:58:59 +08:00
Nick: wip
This commit is contained in:
parent
bb27594443
commit
86e34d7c6c
@ -1,53 +1,21 @@
|
|||||||
import { Response } from "express";
|
import { Response } from "express";
|
||||||
import {
|
import { supabaseGetJobsById } from "../../lib/supabase-jobs";
|
||||||
supabaseGetJobByIdOnlyData,
|
|
||||||
supabaseGetJobsById,
|
|
||||||
} from "../../lib/supabase-jobs";
|
|
||||||
import { scrapeStatusRateLimiter } from "../../services/rate-limiter";
|
|
||||||
import { RequestWithAuth } from "./types";
|
import { RequestWithAuth } from "./types";
|
||||||
|
|
||||||
export async function extractStatusController(
|
export async function extractStatusController(
|
||||||
req: RequestWithAuth<{ jobId: string }, any, any>,
|
req: RequestWithAuth<{ jobId: string }, any, any>,
|
||||||
res: Response,
|
res: Response,
|
||||||
) {
|
) {
|
||||||
try {
|
const jobData = await supabaseGetJobsById([req.params.jobId]);
|
||||||
const rateLimiter = scrapeStatusRateLimiter;
|
if (!jobData || jobData.length === 0) {
|
||||||
const incomingIP = (req.headers["x-forwarded-for"] ||
|
return res.status(404).json({
|
||||||
req.socket.remoteAddress) as string;
|
success: false,
|
||||||
const iptoken = incomingIP;
|
error: "Job not found",
|
||||||
await rateLimiter.consume(iptoken);
|
|
||||||
|
|
||||||
const job = await supabaseGetJobByIdOnlyData(req.params.jobId);
|
|
||||||
if (!job || 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 supabaseGetJobsById([req.params.jobId]);
|
|
||||||
if (!jobData || jobData.length === 0) {
|
|
||||||
return res.status(404).json({
|
|
||||||
success: false,
|
|
||||||
error: "Job not found",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return res.status(200).json({
|
|
||||||
success: true,
|
|
||||||
data: jobData[0].docs,
|
|
||||||
});
|
});
|
||||||
} catch (error) {
|
|
||||||
if (error instanceof Error && error.message == "Too Many Requests") {
|
|
||||||
return res.status(429).json({
|
|
||||||
success: false,
|
|
||||||
error: "Rate limit exceeded. Please try again later.",
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
return res.status(500).json({
|
|
||||||
success: false,
|
|
||||||
error: "An unexpected error occurred.",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return res.status(200).json({
|
||||||
|
success: true,
|
||||||
|
data: jobData[0].docs,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
@ -351,7 +351,7 @@ const processExtractJobInternal = async (token: string, job: Job & { id: string
|
|||||||
|
|
||||||
// Move job to failed state in Redis
|
// Move job to failed state in Redis
|
||||||
await job.moveToFailed(error, token, false);
|
await job.moveToFailed(error, token, false);
|
||||||
throw error;
|
// throw error;
|
||||||
} finally {
|
} finally {
|
||||||
clearInterval(extendLockInterval);
|
clearInterval(extendLockInterval);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user