Skip to content

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

fix: add checkandupdateurl to crawlPreview

Gergő Móricz0c1436672047
diff --git a/apps/api/src/controllers/crawlPreview.ts b/apps/api/src/controllers/crawlPreview.ts
index e66624f51..cc10dc8ea 100644
--- a/apps/api/src/controllers/crawlPreview.ts
+++ b/apps/api/src/controllers/crawlPreview.ts
@@ -6,6 +6,7 @@ import { v4 as uuidv4 } from "uuid";
import { Logger } from "../../src/lib/logger";
import { addCrawlJob, crawlToCrawler, lockURL, saveCrawl, StoredCrawl } from "../../src/lib/crawl-redis";
import { addScrapeJob } from "../../src/services/queue-jobs";
+import { checkAndUpdateURL } from "../../src/lib/validateUrl";
export async function crawlPreviewController(req: Request, res: Response) {
try {
@@ -21,10 +22,17 @@ export async function crawlPreviewController(req: Request, res: Response) {
return res.status(status).json({ error });
}
- const url = req.body.url;
+ let url = req.body.url;
if (!url) {
return res.status(400).json({ error: "Url is required" });
}
+ try {
+ url = checkAndUpdateURL(url).url;
+ } catch (e) {
+ return res
+ .status(e instanceof Error && e.message === "Invalid URL" ? 400 : 500)
+ .json({ error: e.message ?? e });
+ }
if (isUrlBlocked(url)) {
return res