add city to flag hover

This commit is contained in:
Seth Van Niekerk 2026-05-31 10:27:55 -04:00
parent a9b729c3f5
commit 4e5ecc80aa
No known key found for this signature in database
GPG key ID: E86ACA677312A675
3 changed files with 9 additions and 1 deletions

View file

@ -300,6 +300,7 @@ def _perform_ip_lookup():
local_ip = None
country_code = None
country_name = None
city = None
try:
r = requests.get("https://api64.ipify.org?format=json", timeout=5)
@ -323,12 +324,14 @@ def _perform_ip_lookup():
geo = r.json()
country_code = geo.get("country_code")
country_name = geo.get("country_name")
city = geo.get("city")
else:
r = requests.get("http://ip-api.com/json/", timeout=5)
if r.status_code == requests.codes.ok:
geo = r.json()
country_code = geo.get("countryCode")
country_name = geo.get("country")
city = geo.get("city")
except Exception as e:
logger.error(f"Error during geo lookup: {e}")
@ -337,6 +340,7 @@ def _perform_ip_lookup():
"local_ip": local_ip,
"country_code": country_code,
"country_name": country_name,
"city": city,
}, _IP_CACHE_TTL)
cache.delete(_IP_LOCK_KEY)
@ -351,6 +355,7 @@ def environment(request):
local_ip = None
country_code = None
country_name = None
city = None
ip_lookup_pending = False
ip_lookup_env_disabled = not getattr(django_settings, "ENABLE_IP_LOOKUP", True)
@ -364,6 +369,7 @@ def environment(request):
local_ip = cached.get("local_ip")
country_code = cached.get("country_code")
country_name = cached.get("country_name")
city = cached.get("city")
else:
# cache.add() is atomic — only one worker starts the background thread
if cache.add(_IP_LOCK_KEY, True, 30):
@ -380,6 +386,7 @@ def environment(request):
"local_ip": local_ip,
"country_code": country_code,
"country_name": country_name,
"city": city,
"ip_lookup_enabled": ip_lookup_enabled,
"ip_lookup_env_disabled": ip_lookup_env_disabled,
"ip_lookup_pending": ip_lookup_pending,

View file

@ -314,7 +314,7 @@ const Sidebar = ({ collapsed, toggleDrawer, drawerWidth, miniDrawerWidth }) => {
<img
src={`https://flagcdn.com/16x12/${environment.country_code.toLowerCase()}.png`}
alt={environment.country_name || environment.country_code}
title={environment.country_name || environment.country_code}
title={[environment.country_name || environment.country_code, environment.city].filter(Boolean).join(', ')}
style={{ flexShrink: 0 }}
/>
)}

View file

@ -8,6 +8,7 @@ const useSettingsStore = create((set, get) => ({
public_ip: '',
country_code: '',
country_name: '',
city: '',
env_mode: 'aio',
ip_lookup_enabled: true,
ip_lookup_env_disabled: false,