修复地区查询错误的BUG
This commit is contained in:
@@ -617,22 +617,17 @@ app.get('/api/metrics/overview', async (req, res) => {
|
||||
|
||||
// --- Add Geo Information to Servers ---
|
||||
const geoServers = await Promise.all(overview.servers.map(async (server) => {
|
||||
const realInstance = prometheusService.resolveToken(server.instance);
|
||||
// Use originalInstance if available for correct location lookup
|
||||
const realInstance = server.originalInstance || prometheusService.resolveToken(server.instance);
|
||||
const cleanIp = realInstance.split(':')[0];
|
||||
|
||||
let geoData = null;
|
||||
|
||||
// Try to get from DB cache only (fast)
|
||||
try {
|
||||
const [rows] = await db.query('SELECT * FROM server_locations WHERE ip = ?', [cleanIp]);
|
||||
if (rows.length > 0) {
|
||||
const location = rows[0];
|
||||
return {
|
||||
...server,
|
||||
country: location.country,
|
||||
countryName: location.country_name,
|
||||
city: location.city,
|
||||
lat: location.latitude,
|
||||
lng: location.longitude
|
||||
};
|
||||
geoData = rows[0];
|
||||
} else {
|
||||
// Trigger background resolution for future requests
|
||||
geoService.getLocation(cleanIp).catch(() => {});
|
||||
@@ -640,7 +635,21 @@ app.get('/api/metrics/overview', async (req, res) => {
|
||||
} catch (e) {
|
||||
// DB error, skip geo for now
|
||||
}
|
||||
return server;
|
||||
|
||||
// Prepare the server object without sensitive originalInstance
|
||||
const { originalInstance, ...safeServer } = server;
|
||||
|
||||
if (geoData) {
|
||||
return {
|
||||
...safeServer,
|
||||
country: geoData.country,
|
||||
countryName: geoData.country_name,
|
||||
city: geoData.city,
|
||||
lat: geoData.latitude,
|
||||
lng: geoData.longitude
|
||||
};
|
||||
}
|
||||
return safeServer;
|
||||
}));
|
||||
|
||||
overview.servers = geoServers;
|
||||
|
||||
Reference in New Issue
Block a user