mirror of
https://git.mirrors.martin98.com/https://github.com/mendableai/firecrawl
synced 2025-08-19 20:59:07 +08:00
feat(scrape-status): adapt
This commit is contained in:
parent
2849ce2f13
commit
29c1f126ab
@ -3,40 +3,30 @@ import { supabaseGetJobByIdOnlyData } from "../../lib/supabase-jobs";
|
|||||||
import { scrapeStatusRateLimiter } from "../../services/rate-limiter";
|
import { scrapeStatusRateLimiter } from "../../services/rate-limiter";
|
||||||
|
|
||||||
export async function scrapeStatusController(req: any, res: any) {
|
export async function scrapeStatusController(req: any, res: any) {
|
||||||
try {
|
const allowedTeams = [
|
||||||
const rateLimiter = scrapeStatusRateLimiter;
|
"41bdbfe1-0579-4d9b-b6d5-809f16be12f5",
|
||||||
const incomingIP = (req.headers["x-forwarded-for"] ||
|
"511544f2-2fce-4183-9c59-6c29b02c69b5",
|
||||||
req.socket.remoteAddress) as string;
|
"1ec9a0b3-6e7d-49a9-ad6c-9c598ba824c8",
|
||||||
const iptoken = incomingIP;
|
];
|
||||||
await rateLimiter.consume(iptoken);
|
|
||||||
|
|
||||||
const job = await supabaseGetJobByIdOnlyData(req.params.jobId);
|
if (!allowedTeams.includes(req.auth.team_id)) {
|
||||||
const allowedTeams = [
|
return res.status(403).json({
|
||||||
"41bdbfe1-0579-4d9b-b6d5-809f16be12f5",
|
success: false,
|
||||||
"511544f2-2fce-4183-9c59-6c29b02c69b5",
|
error: "Forbidden",
|
||||||
];
|
|
||||||
|
|
||||||
if (!allowedTeams.includes(job?.team_id)) {
|
|
||||||
return res.status(403).json({
|
|
||||||
success: false,
|
|
||||||
error: "You are not allowed to access this resource.",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return res.status(200).json({
|
|
||||||
success: true,
|
|
||||||
data: job?.docs[0],
|
|
||||||
});
|
});
|
||||||
} 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.",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const job = await supabaseGetJobByIdOnlyData(req.params.jobId);
|
||||||
|
|
||||||
|
if (!allowedTeams.includes(job?.team_id) || job?.team_id !== req.auth.team_id) {
|
||||||
|
return res.status(403).json({
|
||||||
|
success: false,
|
||||||
|
error: "You are not allowed to access this resource.",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.status(200).json({
|
||||||
|
success: true,
|
||||||
|
data: job?.docs[0],
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
@ -192,7 +192,10 @@ v1Router.get(
|
|||||||
wrap((req: any, res): any => crawlStatusController(req, res, true)),
|
wrap((req: any, res): any => crawlStatusController(req, res, true)),
|
||||||
);
|
);
|
||||||
|
|
||||||
v1Router.get("/scrape/:jobId", wrap(scrapeStatusController));
|
v1Router.get("/scrape/:jobId",
|
||||||
|
authMiddleware(RateLimiterMode.CrawlStatus),
|
||||||
|
wrap(scrapeStatusController),
|
||||||
|
);
|
||||||
|
|
||||||
v1Router.get(
|
v1Router.get(
|
||||||
"/concurrency-check",
|
"/concurrency-check",
|
||||||
|
@ -755,6 +755,7 @@ async function processJob(job: Job & { id: string }, token: string) {
|
|||||||
{
|
{
|
||||||
content: doc,
|
content: doc,
|
||||||
source: doc?.metadata?.sourceURL ?? doc?.metadata?.url ?? "",
|
source: doc?.metadata?.sourceURL ?? doc?.metadata?.url ?? "",
|
||||||
|
id: job.id,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user