From 12a823b65cbe9d3fc2a42092cf1888b042c4ac05 Mon Sep 17 00:00:00 2001 From: Wouter Koch Date: Tue, 17 Mar 2026 21:56:48 +0100 Subject: [PATCH] Attempt to improve IP based geolocation --- services/geolocation.js | 5 +++-- services/identification.js | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/services/geolocation.js b/services/geolocation.js index 6201f96..c356609 100644 --- a/services/geolocation.js +++ b/services/geolocation.js @@ -32,8 +32,9 @@ const getClientIP = (req) => { } let cleanIP = realIP.replace(/^::ffff:/, "").trim(); - if (cleanIP.includes(".") && !cleanIP.includes(":")) { - cleanIP = cleanIP.replace(/:\d+$/, ""); + const ipv4PortMatch = cleanIP.match(/^(\d+\.\d+\.\d+\.\d+):\d+$/); + if (ipv4PortMatch) { + cleanIP = ipv4PortMatch[1]; } return cleanIP; diff --git a/services/identification.js b/services/identification.js index 18dfc0a..b430516 100644 --- a/services/identification.js +++ b/services/identification.js @@ -206,7 +206,8 @@ const getId = async (req) => { recognition.data.modelInfo = { model: modelUsed, country: country || 'Unknown', - locationSource: locationSource + locationSource: locationSource, + detectedIP: detectedIP }; const metadata = {