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-04-23 16:45:06 -07:00
|
|
|
|
|
|
|
|
dotenv.config();
|
|
|
|
|
|
2024-08-16 19:33:57 -04:00
|
|
|
export async function fireEngineMap(q: string, options: {
|
2024-04-25 01:35:17 +01:00
|
|
|
tbs?: string;
|
|
|
|
|
filter?: string;
|
|
|
|
|
lang?: string;
|
|
|
|
|
country?: string;
|
|
|
|
|
location?: string;
|
2024-08-16 17:57:11 -03:00
|
|
|
numResults: number;
|
2024-04-25 01:35:17 +01:00
|
|
|
page?: number;
|
|
|
|
|
}): Promise<SearchResult[]> {
|
2024-04-23 16:45:06 -07:00
|
|
|
let data = JSON.stringify({
|
2024-08-16 18:39:13 -03:00
|
|
|
query: q,
|
2024-08-16 17:57:11 -03:00
|
|
|
lang: options.lang,
|
|
|
|
|
country: options.country,
|
2024-04-25 01:35:17 +01:00
|
|
|
location: options.location,
|
|
|
|
|
tbs: options.tbs,
|
2024-08-16 18:39:13 -03:00
|
|
|
numResults: options.numResults,
|
2024-04-25 01:35:17 +01:00
|
|
|
page: options.page ?? 1,
|
2024-04-23 16:45:06 -07:00
|
|
|
});
|
|
|
|
|
|
2024-08-16 17:57:11 -03:00
|
|
|
if (!process.env.FIRE_ENGINE_BETA_URL) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-23 16:45:06 -07:00
|
|
|
let config = {
|
|
|
|
|
method: "POST",
|
2024-08-16 17:57:11 -03:00
|
|
|
url: `${process.env.FIRE_ENGINE_BETA_URL}/search`,
|
2024-04-23 16:45:06 -07:00
|
|
|
headers: {
|
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
|
},
|
|
|
|
|
data: data,
|
|
|
|
|
};
|
|
|
|
|
const response = await axios(config);
|
2024-08-16 18:39:13 -03:00
|
|
|
if (response && response) {
|
2024-08-16 17:57:11 -03:00
|
|
|
return response.data
|
|
|
|
|
} else {
|
2024-04-23 16:45:06 -07:00
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
}
|