Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

fix(api/v2/crawl-cancel): base it off NuQ not redis

mogery2852fe364f51
diff --git a/apps/api/src/controllers/v2/crawl-cancel.ts b/apps/api/src/controllers/v2/crawl-cancel.ts
index 267904011..57566d567 100644
--- a/apps/api/src/controllers/v2/crawl-cancel.ts
+++ b/apps/api/src/controllers/v2/crawl-cancel.ts
@@ -1,9 +1,14 @@
import { Response } from "express";
import { logger } from "../../lib/logger";
-import { getCrawl, getCrawlJobs, saveCrawl } from "../../lib/crawl-redis";
+import {
+ getCrawl,
+ getCrawlJobs,
+ saveCrawl,
+ StoredCrawl,
+} from "../../lib/crawl-redis";
import * as Sentry from "@sentry/node";
import { configDotenv } from "dotenv";
-import { RequestWithAuth } from "./types";
+import { RequestWithAuth, scrapeOptions } from "./types";
import { crawlGroup } from "../../services/worker/nuq";
import { removeConcurrencyLimitedJobs } from "../../lib/concurrency-limit";
configDotenv();
@@ -13,18 +18,12 @@ export async function crawlCancelController(
res: Response,
) {
try {
- const sc = await getCrawl(req.params.jobId);
- if (!sc) {
+ const group = await crawlGroup.getGroup(req.params.jobId);
+ if (!group) {
return res.status(404).json({ error: "Job not found" });
}
- // check if the job belongs to the team
- if (sc.team_id !== req.auth.team_id) {
- return res.status(403).json({ error: "Unauthorized" });
- }
-
- const group = await crawlGroup.getGroup(req.params.jobId);
- if (!group) {
+ if (group.ownerId !== req.auth.team_id) {
return res.status(404).json({ error: "Job not found" });
}
@@ -32,6 +31,16 @@ export async function crawlCancelController(
return res.status(409).json({ error: "Crawl is already completed" });
}
+ const sc: StoredCrawl = (await getCrawl(req.params.jobId)) ?? {
+ team_id: group.ownerId,
+ createdAt: Date.now(),
+ crawlerOptions: null,
+ scrapeOptions: scrapeOptions.parse({}),
+ internalOptions: {
+ teamId: group.ownerId,
+ },
+ };
+
try {
sc.cancelled = true;
await saveCrawl(req.params.jobId, sc);