mirror of
https://git.mirrors.martin98.com/https://github.com/mendableai/firecrawl
synced 2025-08-04 19:50:37 +08:00
fix(v1/crawl-cancel): avoid double authing
This commit is contained in:
parent
86744f6deb
commit
3e661a2087
@ -1,26 +1,16 @@
|
|||||||
import { Request, Response } from "express";
|
import { Response } from "express";
|
||||||
import { authenticateUser } from "../auth";
|
|
||||||
import { RateLimiterMode } from "../../types";
|
|
||||||
import { supabase_service } from "../../services/supabase";
|
import { supabase_service } from "../../services/supabase";
|
||||||
import { Logger } from "../../lib/logger";
|
import { Logger } from "../../lib/logger";
|
||||||
import { getCrawl, saveCrawl } from "../../lib/crawl-redis";
|
import { getCrawl, saveCrawl } from "../../lib/crawl-redis";
|
||||||
import * as Sentry from "@sentry/node";
|
import * as Sentry from "@sentry/node";
|
||||||
import { configDotenv } from "dotenv";
|
import { configDotenv } from "dotenv";
|
||||||
|
import { RequestWithAuth } from "./types";
|
||||||
configDotenv();
|
configDotenv();
|
||||||
|
|
||||||
export async function crawlCancelController(req: Request, res: Response) {
|
export async function crawlCancelController(req: RequestWithAuth<{ jobId: string }>, res: Response) {
|
||||||
try {
|
try {
|
||||||
const useDbAuthentication = process.env.USE_DB_AUTHENTICATION === 'true';
|
const useDbAuthentication = process.env.USE_DB_AUTHENTICATION === 'true';
|
||||||
|
|
||||||
const { success, team_id, error, status } = await authenticateUser(
|
|
||||||
req,
|
|
||||||
res,
|
|
||||||
RateLimiterMode.CrawlStatus
|
|
||||||
);
|
|
||||||
if (!success) {
|
|
||||||
return res.status(status).json({ error });
|
|
||||||
}
|
|
||||||
|
|
||||||
const sc = await getCrawl(req.params.jobId);
|
const sc = await getCrawl(req.params.jobId);
|
||||||
if (!sc) {
|
if (!sc) {
|
||||||
return res.status(404).json({ error: "Job not found" });
|
return res.status(404).json({ error: "Job not found" });
|
||||||
@ -32,7 +22,7 @@ export async function crawlCancelController(req: Request, res: Response) {
|
|||||||
.from("bulljobs_teams")
|
.from("bulljobs_teams")
|
||||||
.select("*")
|
.select("*")
|
||||||
.eq("job_id", req.params.jobId)
|
.eq("job_id", req.params.jobId)
|
||||||
.eq("team_id", team_id);
|
.eq("team_id", req.auth.team_id);
|
||||||
if (supaError) {
|
if (supaError) {
|
||||||
return res.status(500).json({ error: supaError.message });
|
return res.status(500).json({ error: supaError.message });
|
||||||
}
|
}
|
||||||
|
@ -148,7 +148,7 @@ v1Router.ws(
|
|||||||
|
|
||||||
v1Router.delete(
|
v1Router.delete(
|
||||||
"/crawl/:jobId",
|
"/crawl/:jobId",
|
||||||
authMiddleware(RateLimiterMode.Crawl),
|
authMiddleware(RateLimiterMode.CrawlStatus),
|
||||||
crawlCancelController
|
crawlCancelController
|
||||||
);
|
);
|
||||||
// v1Router.get("/checkJobStatus/:jobId", crawlJobStatusPreviewController);
|
// v1Router.get("/checkJobStatus/:jobId", crawlJobStatusPreviewController);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user