Update index.ts
This commit is contained in:
parent
26e8bfc23a
commit
90a807c547
@ -78,16 +78,16 @@ export interface ScrapeResponse {
|
|||||||
error?: string;
|
error?: string;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Response interface for searching operations.
|
* Response interface for searching operations.
|
||||||
*/
|
*/
|
||||||
export interface SearchResponse {
|
export interface SearchResponse {
|
||||||
success: boolean;
|
success: boolean;
|
||||||
data?: FirecrawlDocument[];
|
data?: FirecrawlDocument[];
|
||||||
error?: string;
|
error?: string;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Response interface for crawling operations.
|
* Response interface for crawling operations.
|
||||||
*/
|
*/
|
||||||
export interface CrawlResponse {
|
export interface CrawlResponse {
|
||||||
success: boolean;
|
success: boolean;
|
||||||
jobId?: string;
|
jobId?: string;
|
||||||
@ -95,8 +95,8 @@ export interface CrawlResponse {
|
|||||||
error?: string;
|
error?: string;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Response interface for job status checks.
|
* Response interface for job status checks.
|
||||||
*/
|
*/
|
||||||
export interface JobStatusResponse {
|
export interface JobStatusResponse {
|
||||||
success: boolean;
|
success: boolean;
|
||||||
status: string;
|
status: string;
|
||||||
@ -129,7 +129,7 @@ export default class FirecrawlApp {
|
|||||||
*/
|
*/
|
||||||
constructor({ apiKey = null, apiUrl = null }: FirecrawlAppConfig) {
|
constructor({ apiKey = null, apiUrl = null }: FirecrawlAppConfig) {
|
||||||
this.apiKey = apiKey || "";
|
this.apiKey = apiKey || "";
|
||||||
this.apiUrl = apiUrl || "https://api.firecrawl.dev"
|
this.apiUrl = apiUrl || "https://api.firecrawl.dev";
|
||||||
if (!this.apiKey) {
|
if (!this.apiKey) {
|
||||||
throw new Error("No API key provided");
|
throw new Error("No API key provided");
|
||||||
}
|
}
|
||||||
@ -169,7 +169,7 @@ export default class FirecrawlApp {
|
|||||||
const response: AxiosResponse = await axios.post(
|
const response: AxiosResponse = await axios.post(
|
||||||
this.apiUrl + "/v0/scrape",
|
this.apiUrl + "/v0/scrape",
|
||||||
jsonData,
|
jsonData,
|
||||||
{ headers },
|
{ headers }
|
||||||
);
|
);
|
||||||
if (response.status === 200) {
|
if (response.status === 200) {
|
||||||
const responseData = response.data;
|
const responseData = response.data;
|
||||||
@ -288,7 +288,9 @@ export default class FirecrawlApp {
|
|||||||
success: true,
|
success: true,
|
||||||
status: response.data.status,
|
status: response.data.status,
|
||||||
data: response.data.data,
|
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 {
|
} else {
|
||||||
this.handleError(response, "check crawl status");
|
this.handleError(response, "check crawl status");
|
||||||
@ -309,10 +311,10 @@ export default class FirecrawlApp {
|
|||||||
*/
|
*/
|
||||||
prepareHeaders(idempotencyKey?: string): AxiosRequestHeaders {
|
prepareHeaders(idempotencyKey?: string): AxiosRequestHeaders {
|
||||||
return {
|
return {
|
||||||
'Content-Type': 'application/json',
|
"Content-Type": "application/json",
|
||||||
'Authorization': `Bearer ${this.apiKey}`,
|
Authorization: `Bearer ${this.apiKey}`,
|
||||||
...(idempotencyKey ? { 'x-idempotency-key': idempotencyKey } : {}),
|
...(idempotencyKey ? { "x-idempotency-key": idempotencyKey } : {}),
|
||||||
} as AxiosRequestHeaders & { 'x-idempotency-key'?: string };
|
} as AxiosRequestHeaders & { "x-idempotency-key"?: string };
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -374,7 +376,9 @@ export default class FirecrawlApp {
|
|||||||
if (checkInterval < 2) {
|
if (checkInterval < 2) {
|
||||||
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 {
|
} else {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Crawl job failed or was stopped. Status: ${statusData.status}`
|
`Crawl job failed or was stopped. Status: ${statusData.status}`
|
||||||
|
Loading…
Reference in New Issue
Block a user