Update index.ts
This commit is contained in:
parent
26e8bfc23a
commit
90a807c547
@ -78,16 +78,16 @@ export interface ScrapeResponse {
|
||||
error?: string;
|
||||
}
|
||||
/**
|
||||
* Response interface for searching operations.
|
||||
*/
|
||||
* Response interface for searching operations.
|
||||
*/
|
||||
export interface SearchResponse {
|
||||
success: boolean;
|
||||
data?: FirecrawlDocument[];
|
||||
error?: string;
|
||||
}
|
||||
/**
|
||||
* Response interface for crawling operations.
|
||||
*/
|
||||
* Response interface for crawling operations.
|
||||
*/
|
||||
export interface CrawlResponse {
|
||||
success: boolean;
|
||||
jobId?: string;
|
||||
@ -95,8 +95,8 @@ export interface CrawlResponse {
|
||||
error?: string;
|
||||
}
|
||||
/**
|
||||
* Response interface for job status checks.
|
||||
*/
|
||||
* Response interface for job status checks.
|
||||
*/
|
||||
export interface JobStatusResponse {
|
||||
success: boolean;
|
||||
status: string;
|
||||
@ -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}`
|
||||
|
Loading…
Reference in New Issue
Block a user