2024-04-23 16:45:06 -07:00
|
|
|
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";
|
2024-11-07 20:57:33 +01:00
|
|
|
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: {
|
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;
|
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-11-14 17:31:23 -05:00
|
|
|
const response = await fetch(`${process.env.FIRE_ENGINE_BETA_URL}/search`, {
|
2024-09-19 12:49:33 -04:00
|
|
|
method: "POST",
|
|
|
|
|
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
|
|
|
},
|
2024-11-14 17:31:23 -05:00
|
|
|
body: data
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (response.ok) {
|
|
|
|
|
const responseData = await response.json();
|
|
|
|
|
return responseData;
|
2024-09-19 12:49:33 -04:00
|
|
|
} else {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
2024-11-07 20:57:33 +01:00
|
|
|
logger.error(error);
|
2024-09-19 12:49:33 -04:00
|
|
|
Sentry.captureException(error);
|
2024-04-23 16:45:06 -07:00
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
}
|