2023-08-23 11:03:10 +03:00
|
|
|
import { AxiosInstance } from "axios";
|
|
|
|
import { UUID } from "crypto";
|
|
|
|
|
|
|
|
import { ToastData } from "@/lib/components/ui/Toast/domain/types";
|
|
|
|
|
|
|
|
export type CrawlInputProps = {
|
|
|
|
brainId: UUID;
|
2023-09-07 18:23:31 +03:00
|
|
|
chat_id?: UUID;
|
2023-08-23 11:03:10 +03:00
|
|
|
config: {
|
|
|
|
url: string;
|
|
|
|
js: boolean;
|
|
|
|
depth: number;
|
|
|
|
max_pages: number;
|
|
|
|
max_time: number;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export type CrawlResponse = {
|
|
|
|
data: { type: ToastData["variant"]; message: ToastData["text"] };
|
|
|
|
};
|
|
|
|
|
|
|
|
export const crawlWebsiteUrl = async (
|
|
|
|
props: CrawlInputProps,
|
|
|
|
axiosInstance: AxiosInstance
|
|
|
|
): Promise<CrawlResponse> =>
|
2023-09-07 18:23:31 +03:00
|
|
|
axiosInstance.post(
|
|
|
|
`/crawl?brain_id=${props.brainId}&chat_id=${props.chat_id ?? ""}`,
|
|
|
|
props.config
|
|
|
|
);
|