LocationHub/server/src/proxy/wigle.ts

72 lines
1.5 KiB
TypeScript

interface WigleApiResonse {
response?: WifiLocationResponse,
status_code: number,
}
interface WifiLocationResponse {
success: boolean;
totalResults: number;
first: number;
last: number;
resultCount: number;
results: Result[];
searchAfter: string;
search_after: number;
}
interface Result {
trilat: number;
trilong: number;
ssid: string;
qos: number;
transid: string;
firsttime: string;
lasttime: string;
lastupdt: string;
netid: string;
name?: string;
type: string;
comment?: string;
wep: string;
bcninterval: number;
freenet: string;
dhcp: string;
paynet: string;
userfound: boolean;
channel: number;
rcois: string;
encryption: string;
country: string;
region: string;
road: string;
city?: string;
housenumber?: string;
postalcode: string;
}
export const getLocationForWifi = async (
mac: string
): Promise<WigleApiResonse | undefined> => {
try {
const url = `${process.env.WIGLE_BASE_URL!}${process.env
.WIGLE_NETWORK_SEARCH!}?netid=${encodeURIComponent(mac)}`;
const response = await fetch(url, {
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: `Basic ${process.env.WIGLE_TOKEN}`,
},
});
if (response.ok) {
return { status_code: response.status, response: await response.json() };
}
console.log(response.status);
return { status_code: response.status };
} catch (error) {
console.error("Error during call of API wigle.net:", error);
return undefined;
}
};