From b2c37b8fe362e1d104841e21c7ad79dc319fe863 Mon Sep 17 00:00:00 2001 From: CN-JS-HuiBai Date: Sun, 5 Apr 2026 17:35:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9C=B0=E5=8C=BA=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E9=94=99=E8=AF=AF=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/index.js | 31 ++++++++++++++++++++----------- server/prometheus-service.js | 7 ++----- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/server/index.js b/server/index.js index 21bedf4..576f57a 100644 --- a/server/index.js +++ b/server/index.js @@ -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; diff --git a/server/prometheus-service.js b/server/prometheus-service.js index 9835787..124ad9c 100644 --- a/server/prometheus-service.js +++ b/server/prometheus-service.js @@ -10,7 +10,7 @@ const httpAgent = new http.Agent({ keepAlive: true }); const httpsAgent = new https.Agent({ keepAlive: true, rejectUnauthorized: false }); const serverIdMap = new Map(); // token -> { instance, job, source } -const SECRET = crypto.randomBytes(16).toString('hex'); +const SECRET = process.env.APP_SECRET || 'prom-data-panel-stable-secret-key-123'; function getServerToken(instance, job, source) { const hash = crypto.createHmac('sha256', SECRET) @@ -363,10 +363,7 @@ async function getOverviewMetrics(url, sourceName) { tx: totalTraffic24hTx, total: totalTraffic24hRx + totalTraffic24hTx }, - servers: allInstancesList.map(s => { - const { originalInstance, ...rest } = s; - return rest; - }) + servers: allInstancesList }; }