Elffuss BraidHub

kikocis/continue public

main · 1005 BRawPermalink
1import { URL } from "node:url";
2
3import { getHeaders } from "../../../continueServer/stubs/headers";
4import { TRIAL_PROXY_URL } from "../../../control-plane/client";
5import { PageData } from "./DocsCrawler";
6
7export class DefaultCrawler {
8 constructor(
9 private readonly startUrl: URL,
10 private readonly maxRequestsPerCrawl: number,
11 private readonly maxDepth: number,
12 ) {}
13
14 async crawl(): Promise<PageData[]> {
15 const resp = await fetch(new URL("crawl", TRIAL_PROXY_URL).toString(), {
16 method: "POST",
17 headers: {
18 "Content-Type": "application/json",
19 ...(await getHeaders()),
20 },
21 body: JSON.stringify({
22 startUrl: this.startUrl.toString(),
23 maxDepth: this.maxDepth,
24 limit: this.maxRequestsPerCrawl,
25 }),
26 });
27 if (!resp.ok) {
28 const text = await resp.text();
29 throw new Error(`Failed to crawl site (${resp.status}): ${text}`);
30 }
31 const json = (await resp.json()) as PageData[];
32 return json;
33 }
34}