Files
firecrawl/apps/api/src/controllers/v1/scrape-status.ts
T

43 lines
1.3 KiB
TypeScript
Raw Normal View History

2024-08-31 14:23:55 -03:00
import { Response } from "express";
import { supabaseGetJobByIdOnlyData } from "../../lib/supabase-jobs";
import { scrapeStatusRateLimiter } from "../../services/rate-limiter";
export async function scrapeStatusController(req: any, res: any) {
try {
const rateLimiter = scrapeStatusRateLimiter;
const incomingIP = (req.headers["x-forwarded-for"] ||
req.socket.remoteAddress) as string;
const iptoken = incomingIP;
await rateLimiter.consume(iptoken);
const job = await supabaseGetJobByIdOnlyData(req.params.jobId);
2024-11-18 15:02:00 -03:00
const allowedTeams = [
2024-12-11 19:46:11 -03:00
"41bdbfe1-0579-4d9b-b6d5-809f16be12f5",
2024-12-11 19:51:08 -03:00
"511544f2-2fce-4183-9c59-6c29b02c69b5",
2024-11-18 15:02:00 -03:00
];
2024-08-31 14:23:55 -03:00
2024-12-11 19:46:11 -03:00
if (!allowedTeams.includes(job?.team_id)) {
2024-09-01 12:55:02 -03:00
return res.status(403).json({
success: false,
2024-12-11 19:51:08 -03:00
error: "You are not allowed to access this resource.",
2024-09-01 12:55:02 -03:00
});
}
2024-08-31 14:23:55 -03:00
return res.status(200).json({
success: true,
2024-12-11 19:51:08 -03:00
data: job?.docs[0],
2024-08-31 14:23:55 -03:00
});
} catch (error) {
if (error instanceof Error && error.message == "Too Many Requests") {
return res.status(429).json({
success: false,
2024-12-11 19:51:08 -03:00
error: "Rate limit exceeded. Please try again later.",
2024-08-31 14:23:55 -03:00
});
} else {
return res.status(500).json({
success: false,
2024-12-11 19:51:08 -03:00
error: "An unexpected error occurred.",
2024-08-31 14:23:55 -03:00
});
}
}
}