0

Update index.ts

This commit is contained in:
Nicolas 2024-06-18 12:56:13 -04:00
parent 26e8bfc23a
commit 90a807c547

View File

@ -129,7 +129,7 @@ export default class FirecrawlApp {
*/
constructor({ apiKey = null, apiUrl = null }: FirecrawlAppConfig) {
this.apiKey = apiKey || "";
this.apiUrl = apiUrl || "https://api.firecrawl.dev"
this.apiUrl = apiUrl || "https://api.firecrawl.dev";
if (!this.apiKey) {
throw new Error("No API key provided");
}
@ -169,7 +169,7 @@ export default class FirecrawlApp {
const response: AxiosResponse = await axios.post(
this.apiUrl + "/v0/scrape",
jsonData,
{ headers },
{ headers }
);
if (response.status === 200) {
const responseData = response.data;
@ -288,7 +288,9 @@ export default class FirecrawlApp {
success: true,
status: response.data.status,
data: response.data.data,
partial_data: !response.data.data ? response.data.partial_data : undefined,
partial_data: !response.data.data
? response.data.partial_data
: undefined,
};
} else {
this.handleError(response, "check crawl status");
@ -309,10 +311,10 @@ export default class FirecrawlApp {
*/
prepareHeaders(idempotencyKey?: string): AxiosRequestHeaders {
return {
'Content-Type': 'application/json',
'Authorization': `Bearer ${this.apiKey}`,
...(idempotencyKey ? { 'x-idempotency-key': idempotencyKey } : {}),
} as AxiosRequestHeaders & { 'x-idempotency-key'?: string };
"Content-Type": "application/json",
Authorization: `Bearer ${this.apiKey}`,
...(idempotencyKey ? { "x-idempotency-key": idempotencyKey } : {}),
} as AxiosRequestHeaders & { "x-idempotency-key"?: string };
}
/**
@ -374,7 +376,9 @@ export default class FirecrawlApp {
if (checkInterval < 2) {
checkInterval = 2;
}
await new Promise((resolve) => setTimeout(resolve, checkInterval * 1000)); // Wait for the specified timeout before checking again
await new Promise((resolve) =>
setTimeout(resolve, checkInterval * 1000)
); // Wait for the specified timeout before checking again
} else {
throw new Error(
`Crawl job failed or was stopped. Status: ${statusData.status}`