//native
type Greip = {
apiKey: string;
};
/**
* Retrieve detailed geolocation information for a visitor’s or user’s IP address
* This API allows you to retrieve detailed geolocation information for a visitor’s or user’s IP address.
By using the IP Geolocation method, you can access data such as the user’s country, city, ISP, and more, enabling you to personalize user experiences, enhance security, and make data-driven decisions based on geographic insights.
*/
export async function main(
auth: Greip,
params: string | undefined,
lang: string | undefined,
format: string | undefined,
userID: string | undefined,
mode: string | undefined,
callback: string | undefined,
) {
const url = new URL(`https://greipapi.com/geoip`);
for (const [k, v] of [
["params", params],
["lang", lang],
["format", format],
["userID", userID],
["mode", mode],
["callback", callback],
]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
Authorization: "Bearer " + auth.apiKey,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.text();
}
Submitted by hugo697 428 days ago