Nick: wip

This commit is contained in:
Nicolas 2025-01-07 12:13:12 -03:00
parent bb27594443
commit 86e34d7c6c
2 changed files with 12 additions and 44 deletions

View File

@ -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,
});
} }

View File

@ -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);
} }