Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
RunOnFluxBot committed Nov 21, 2023
1 parent a36c211 commit e09924c
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions services/geolocationService.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,26 @@ async function setNodeGeolocation() {
if (!storedGeolocation || myIP !== storedIp || execution % 4 === 0) {
log.info(`Checking geolocation of ${myIP}`);
storedIp = myIP;
const statsApiUrl = `https://stats.runonflux.io/fluxlocation/${myIP.split(':')[0]}`;
const statsRes = await serviceHelper.axiosGet(statsApiUrl);
if (statsRes.data.status === 'success' && statsRes.data.data) {
storedGeolocation = {
ip: statsRes.data.data.ip,
continent: statsRes.data.data.continent,
continentCode: statsRes.data.data.continentCode,
country: statsRes.data.data.country,
countryCode: statsRes.data.data.countryCode,
region: statsRes.data.data.region,
regionName: statsRes.data.data.regionName,
lat: statsRes.data.data.lat,
lon: statsRes.data.data.lon,
org: statsRes.data.data.org,
};
} else {
throw new Error(`Geolocation of IP ${myIP} is unavailable`);
}
// consider another service failover or stats db
const ipApiUrl = `http://ip-api.com/json/${myIP.split(':')[0]}?fields=status,continent,continentCode,country,countryCode,region,regionName,lat,lon,query,org,isp`;
/* const ipApiUrl = `http://ip-api.com/json/${myIP.split(':')[0]}?fields=status,continent,continentCode,country,countryCode,region,regionName,lat,lon,query,org,isp`;
const ipRes = await serviceHelper.axiosGet(ipApiUrl);
if (ipRes.data.status === 'success' && ipRes.data.query !== '') {
storedGeolocation = {
Expand Down Expand Up @@ -55,7 +73,7 @@ async function setNodeGeolocation() {
} else {
throw new Error(`Geolocation of IP ${myIP} is unavailable`);
}
}
} */
}
log.info(`Geolocation of ${myIP} is ${JSON.stringify(storedGeolocation)}`);
for (let i = 0; i < staticIpOrgs.length; i += 1) {
Expand Down

0 comments on commit e09924c

Please sign in to comment.