add wifilocation flags

This commit is contained in:
2025-01-06 21:47:13 +01:00
parent f6db27a225
commit df9c84e9df
10 changed files with 65 additions and 214 deletions

View File

@ -1,4 +1,7 @@
import memoizee from "memoizee";
interface WigleApiResonse {
response?: WifiLocationResponse,
status_code: number,
}
interface WifiLocationResponse {
success: boolean;
@ -43,7 +46,7 @@ interface Result {
export const getLocationForWifi = async (
mac: string
): Promise<WifiLocationResponse | undefined> => {
): Promise<WigleApiResonse | undefined> => {
try {
const url = `${process.env.WIGLE_BASE_URL!}${process.env
.WIGLE_NETWORK_SEARCH!}?netid=${encodeURIComponent(mac)}`;
@ -57,17 +60,12 @@ export const getLocationForWifi = async (
});
if (response.ok) {
return await response.json();
return { status_code: response.status, response: await response.json() };
}
console.log(response.status);
return undefined;
return { status_code: response.status };
} catch (error) {
console.error("Error during call of API wigle.net:", error);
return undefined;
}
};
export const getLocationForWifiMemoized = memoizee(getLocationForWifi, {
maxAge: Number(process.env.GET_LOCATION_WIFI_MAX_AGE),
max: Number(process.env.GET_LOCATION_WIFI_MAX),
primitive: process.env.GET_LOCATION_WIFI_PRIMITIVE === "true",
});