mirror of
https://git.mirrors.martin98.com/https://github.com/mendableai/firecrawl
synced 2025-08-14 19:35:55 +08:00
Nick: fixed the sdks
This commit is contained in:
parent
dd14744850
commit
9ec08d7020
@ -69,7 +69,7 @@ export async function extractController(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return res.status(202).json({
|
return res.status(200).json({
|
||||||
success: true,
|
success: true,
|
||||||
id: extractId,
|
id: extractId,
|
||||||
urlTrace: [],
|
urlTrace: [],
|
||||||
|
@ -887,18 +887,32 @@ export default class FirecrawlApp {
|
|||||||
{ ...jsonData, schema: jsonSchema },
|
{ ...jsonData, schema: jsonSchema },
|
||||||
headers
|
headers
|
||||||
);
|
);
|
||||||
|
|
||||||
if (response.status === 200) {
|
if (response.status === 200) {
|
||||||
const responseData = response.data as ExtractResponse<T>;
|
const jobId = response.data.id;
|
||||||
if (responseData.success) {
|
let extractStatus;
|
||||||
return {
|
do {
|
||||||
success: true,
|
const statusResponse: AxiosResponse = await this.getRequest(
|
||||||
data: responseData.data,
|
`${this.apiUrl}/v1/extract/${jobId}`,
|
||||||
warning: responseData.warning,
|
headers
|
||||||
error: responseData.error
|
);
|
||||||
};
|
extractStatus = statusResponse.data;
|
||||||
} else {
|
if (extractStatus.status === "completed") {
|
||||||
throw new FirecrawlError(`Failed to scrape URL. Error: ${responseData.error}`, response.status);
|
if (extractStatus.success) {
|
||||||
}
|
return {
|
||||||
|
success: true,
|
||||||
|
data: extractStatus.data,
|
||||||
|
warning: extractStatus.warning,
|
||||||
|
error: extractStatus.error
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
throw new FirecrawlError(`Failed to extract data. Error: ${extractStatus.error}`, statusResponse.status);
|
||||||
|
}
|
||||||
|
} else if (extractStatus.status === "failed" || extractStatus.status === "cancelled") {
|
||||||
|
throw new FirecrawlError(`Extract job ${extractStatus.status}. Error: ${extractStatus.error}`, statusResponse.status);
|
||||||
|
}
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 1000)); // Polling interval
|
||||||
|
} while (extractStatus.status !== "completed");
|
||||||
} else {
|
} else {
|
||||||
this.handleError(response, "extract");
|
this.handleError(response, "extract");
|
||||||
}
|
}
|
||||||
|
@ -542,6 +542,7 @@ class FirecrawlApp:
|
|||||||
}
|
}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
# Send the initial extract request
|
||||||
response = self._post_request(
|
response = self._post_request(
|
||||||
f'{self.api_url}/v1/extract',
|
f'{self.api_url}/v1/extract',
|
||||||
request_data,
|
request_data,
|
||||||
@ -550,7 +551,29 @@ class FirecrawlApp:
|
|||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
data = response.json()
|
data = response.json()
|
||||||
if data['success']:
|
if data['success']:
|
||||||
return data
|
job_id = data.get('id')
|
||||||
|
if not job_id:
|
||||||
|
raise Exception('Job ID not returned from extract request.')
|
||||||
|
|
||||||
|
# Poll for the extract status
|
||||||
|
while True:
|
||||||
|
status_response = self._get_request(
|
||||||
|
f'{self.api_url}/v1/extract/{job_id}',
|
||||||
|
headers
|
||||||
|
)
|
||||||
|
if status_response.status_code == 200:
|
||||||
|
status_data = status_response.json()
|
||||||
|
if status_data['status'] == 'completed':
|
||||||
|
if status_data['success']:
|
||||||
|
return status_data
|
||||||
|
else:
|
||||||
|
raise Exception(f'Failed to extract. Error: {status_data["error"]}')
|
||||||
|
elif status_data['status'] in ['failed', 'cancelled']:
|
||||||
|
raise Exception(f'Extract job {status_data["status"]}. Error: {status_data["error"]}')
|
||||||
|
else:
|
||||||
|
self._handle_error(status_response, "extract-status")
|
||||||
|
|
||||||
|
time.sleep(2) # Polling interval
|
||||||
else:
|
else:
|
||||||
raise Exception(f'Failed to extract. Error: {data["error"]}')
|
raise Exception(f'Failed to extract. Error: {data["error"]}')
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user