MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / getGeoLocation

Function getGeoLocation

packages/geo/src/geo.ts:69–95  ·  view source on GitHub ↗
(ip?: string)

Source from the content-addressed store, hash-verified

67});
68
69export async function getGeoLocation(ip?: string): Promise<GeoLocation> {
70 if (!ip || ignore.includes(ip)) {
71 return DEFAULT_GEO;
72 }
73
74 const cached = cache.get(ip);
75 if (cached) {
76 return cached;
77 }
78
79 const reader = await getReader();
80
81 try {
82 const response = reader?.city(ip);
83 const res = {
84 city: response?.city?.names.en,
85 country: response?.country?.isoCode,
86 region: response?.subdivisions?.[0]?.names.en,
87 longitude: response?.location?.longitude,
88 latitude: response?.location?.latitude,
89 };
90 cache.set(ip, res);
91 return res;
92 } catch (error) {
93 return DEFAULT_GEO;
94 }
95}

Callers 6

updateProfileFunction · 0.90
buildContextFunction · 0.90
postEventFunction · 0.90
siteCheckerFunction · 0.90
ipLookupFunction · 0.90
getGeoFunction · 0.90

Calls 3

getReaderFunction · 0.85
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected