Files
firecrawl/apps/api/src/search/fireEngine.ts
T

61 lines
1.3 KiB
TypeScript
Raw Normal View History

2024-04-23 16:45:06 -07:00
import axios from "axios";
import dotenv from "dotenv";
2024-04-24 10:11:01 -07:00
import { SearchResult } from "../../src/lib/entities";
2024-09-19 12:49:33 -04:00
import * as Sentry from "@sentry/node";
import { Logger } from "../lib/logger";
2024-04-23 16:45:06 -07:00
dotenv.config();
2024-10-12 17:59:50 -03:00
2024-09-19 12:49:33 -04:00
export async function fireEngineMap(
q: string,
options: {
tbs?: string;
filter?: string;
lang?: string;
country?: string;
location?: string;
2024-08-16 17:57:11 -03:00
numResults: number;
page?: number;
2024-08-16 17:57:11 -03:00
}
2024-09-19 12:49:33 -04:00
): Promise<SearchResult[]> {
try {
let data = JSON.stringify({
query: q,
lang: options.lang,
country: options.country,
location: options.location,
tbs: options.tbs,
numResults: options.numResults,
page: options.page ?? 1,
});
if (!process.env.FIRE_ENGINE_BETA_URL) {
console.warn(
"(v1/map Beta) Results might differ from cloud offering currently."
);
return [];
}
2024-08-16 17:57:11 -03:00
2024-09-19 12:49:33 -04:00
let config = {
method: "POST",
url: `${process.env.FIRE_ENGINE_BETA_URL}/search`,
headers: {
"Content-Type": "application/json",
2024-10-12 18:18:38 -03:00
"X-Disable-Cache": "true"
2024-09-19 12:49:33 -04:00
},
data: data,
};
const response = await axios(config);
2024-10-12 18:18:38 -03:00
if (response && response.data) {
2024-09-19 12:49:33 -04:00
return response.data;
} else {
return [];
}
} catch (error) {
Logger.error(error);
Sentry.captureException(error);
2024-04-23 16:45:06 -07:00
return [];
}
}