feat: added cache version for api call

This commit is contained in:
2025-01-01 19:31:51 +01:00
parent 82296d0f2d
commit d8ec609baf
3 changed files with 178 additions and 3 deletions

View File

@ -1,3 +1,5 @@
import memoizee from "memoizee";
interface WifiLocationResponse {
success: boolean;
totalResults: number;
@ -43,7 +45,6 @@ export const getLocationForWifi = async (
mac: string
): Promise<WifiLocationResponse | undefined> => {
try {
console.log(process.env.WIGLE_BASE_URL);
const url = `${process.env.WIGLE_BASE_URL!}${process.env
.WIGLE_NETWORK_SEARCH!}?netid=${encodeURIComponent(mac)}`;
const response = await fetch(url, {
@ -53,9 +54,14 @@ export const getLocationForWifi = async (
Cookie: `auth=${process.env.WIGLE_TOKEN}`,
},
});
return await response.json();
} catch (error) {
console.error("Fehler beim Aufruf des Services:", error);
}
};
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",
});