mirror of
https://github.com/GitSquared/edex-ui.git
synced 2024-09-21 10:37:29 +00:00
👽 Revert geoip api to ipinfo.now.sh
and optimize number of requests
This commit is contained in:
parent
cb597e3b76
commit
0bbced5ca1
@ -82,14 +82,14 @@ class LocationGlobe {
|
||||
// Connections
|
||||
this.conns = [];
|
||||
this.addConn = ip => {
|
||||
require("https").get({host: "freegeoip.app", port: 443, path: "/json/"+ip, localAddress: window.mods.netstat.internalIPv4, agent: false}, res => {
|
||||
require("https").get({host: "ipinfo.now.sh", port: 443, path: "/"+ip, localAddress: window.mods.netstat.internalIPv4, agent: false}, res => {
|
||||
let rawData = "";
|
||||
res.on("data", chunk => {
|
||||
rawData += chunk;
|
||||
});
|
||||
res.on("end", () => {
|
||||
this.parseResponse(rawData, ip).catch(e => {
|
||||
window.mods.netstat.failedAttempts[e] = (window.mods.netstat.failedAttemps[e] || 0) + 1;
|
||||
window.mods.netstat.failedAttempts[e] = (window.mods.netstat.failedAttempts[e] || 0) + 1;
|
||||
if (window.mods.netstat.failedAttempts[e] > 2) return false;
|
||||
let electron = require("electron");
|
||||
electron.ipcRenderer.send("log", "note", "LocationGlobe: Error parsing data from ipinfo.now.sh");
|
||||
@ -137,9 +137,9 @@ class LocationGlobe {
|
||||
|
||||
async parseResponse(rawData, ip) {
|
||||
const json = JSON.parse(rawData);
|
||||
if (json.latitude && json.longitude) {
|
||||
const lat = Number(json.latitude);
|
||||
const lon = Number(json.longitude);
|
||||
if (json.geo !== null && json.geo.latitude && json.geo.longitude) {
|
||||
const lat = Number(json.geo.latitude);
|
||||
const lon = Number(json.geo.longitude);
|
||||
|
||||
window.mods.globe.conns.push({
|
||||
ip,
|
||||
@ -155,7 +155,7 @@ class LocationGlobe {
|
||||
this.globe.addMarker(randomLat - 20, randomLong + 150, '', true);
|
||||
}
|
||||
addTemporaryConnectedMarker(ip) {
|
||||
require("https").get({host: "freegeoip.app", port: 443, path: "/json/"+ip, localAddress: window.mods.netstat.internalIPv4, agent: false}, res => {
|
||||
require("https").get({host: "ipinfo.now.sh", port: 443, path: "/"+ip, localAddress: window.mods.netstat.internalIPv4, agent: false}, res => {
|
||||
let rawData = "";
|
||||
res.on("data", chunk => {
|
||||
rawData += chunk;
|
||||
@ -167,9 +167,9 @@ class LocationGlobe {
|
||||
} catch(e) {
|
||||
return;
|
||||
}
|
||||
if (json.latitude && json.longitude) {
|
||||
const lat = Number(json.latitude);
|
||||
const lon = Number(json.longitude);
|
||||
if (json.geo.latitude && json.geo.longitude) {
|
||||
const lat = Number(json.geo.latitude);
|
||||
const lon = Number(json.geo.longitude);
|
||||
|
||||
window.mods.globe.conns.push({
|
||||
ip,
|
||||
|
@ -28,6 +28,7 @@ class Netstat {
|
||||
this.lastconn = {finished: true};
|
||||
this.iface = null;
|
||||
this.failedAttempts = {};
|
||||
this.runsBeforeGeoIPUpdate = 0;
|
||||
|
||||
this._httpsAgent = new require("https").Agent({
|
||||
keepAlive: false,
|
||||
@ -79,6 +80,8 @@ class Netstat {
|
||||
}
|
||||
}
|
||||
|
||||
if (net.ip4 !== this.internalIPv4) this.runsBeforeGeoIPUpdate = 0;
|
||||
|
||||
this.iface = net.iface;
|
||||
this.internalIPv4 = net.ip4;
|
||||
document.getElementById("mod_netstat_iname").innerText = "Interface: "+net.iface;
|
||||
@ -86,8 +89,8 @@ class Netstat {
|
||||
if (net.ip4 === "127.0.0.1") {
|
||||
offline = true;
|
||||
} else {
|
||||
if (this.lastconn.finished) {
|
||||
this.lastconn = require("https").get({host: "freegeoip.app", port: 443, path: "/json/", localAddress: net.ip4, agent: this._httpsAgent}, res => {
|
||||
if (this.runsBeforeGeoIPUpdate === 0 && this.lastconn.finished) {
|
||||
this.lastconn = require("https").get({host: "ipinfo.now.sh", port: 443, path: "/", localAddress: net.ip4, agent: this._httpsAgent}, res => {
|
||||
let rawData = "";
|
||||
res.on("data", chunk => {
|
||||
rawData += chunk;
|
||||
@ -97,20 +100,15 @@ class Netstat {
|
||||
let data = JSON.parse(rawData);
|
||||
this.ipinfo = {
|
||||
ip: data.ip,
|
||||
geo: {
|
||||
latitude: data.latitude,
|
||||
longitude: data.longitude,
|
||||
metro_code: data.zip_code,
|
||||
time_zone: data.time_zone
|
||||
}
|
||||
geo: data.geo
|
||||
};
|
||||
|
||||
// if (!this.ipinfo.api_version.startsWith("3")) console.warn("Warning: ipinfo API version might not be compatible");
|
||||
if (!data.api_version.startsWith("4")) console.warn("Warning: ipinfo API version might not be compatible");
|
||||
|
||||
// delete this.ipinfo.api_version;
|
||||
// delete this.ipinfo.time;
|
||||
let ip = this.ipinfo.ip;
|
||||
document.querySelector("#mod_netstat_innercontainer > div:nth-child(2) > h2").innerHTML = window._escapeHtml(ip);
|
||||
|
||||
this.runsBeforeGeoIPUpdate = 10;
|
||||
} catch(e) {
|
||||
this.failedAttempts[e] = (this.failedAttempts[e] || 0) + 1;
|
||||
if (this.failedAttempts[e] > 2) return false;
|
||||
@ -124,6 +122,8 @@ class Netstat {
|
||||
}).on("error", e => {
|
||||
// Drop it
|
||||
});
|
||||
} else if (this.runsBeforeGeoIPUpdate !== 0) {
|
||||
this.runsBeforeGeoIPUpdate = this.runsBeforeGeoIPUpdate - 1;
|
||||
}
|
||||
|
||||
let p = await this.ping(window.settings.pingAddr || "1.1.1.1", 80, net.ip4).catch(() => { offline = true });
|
||||
|
Loading…
Reference in New Issue
Block a user