This commit is contained in:
lelo 2025-12-15 07:38:36 +00:00
parent 79fa989a6d
commit cba6b94508
3 changed files with 34 additions and 17 deletions

View File

@ -191,15 +191,20 @@ def log_file_access(rel_path, filesize, mime, ip_address, user_agent, device_id,
folder_yesterday.append({'date_str': yesterday_str, 'rel_path': folder_path})
# Finally, insert the new access at the top of the temp log
# Keep existing columns stable; append raw geo data for map use.
file_access_temp.insert(0, [
iso_ts,
rel_path,
filesize,
mime,
f"{city}, {country}",
user_agent,
device_id,
cached
iso_ts, # 0 timestamp
rel_path, # 1 path
filesize, # 2 size
mime, # 3 mime
f"{city}, {country}", # 4 location label
user_agent, # 5 UA
device_id, # 6 device
cached, # 7 cached flag
city, # 8 city
country, # 9 country
lat, # 10 latitude
lon # 11 longitude
])
return True
@ -814,4 +819,4 @@ if __name__ == "__main__":
search="2025-06-13 Freitag 16 Uhr",
replacement="2025-06-13 Eröffnungsgottesdienst Freitag 16 Uhr",
dry_run=True
)
)

19
app.py
View File

@ -703,17 +703,22 @@ def handle_request_initial_data():
@socketio.on('request_map_data')
def handle_request_map_data():
"""Send initial map data with geographic coordinates"""
rows = a.return_file_access_with_geo()
"""Send initial map data from in-memory log to avoid hitting the DB."""
rows = a.return_file_access()
connections = []
for row in rows:
if row[8] and row[9]: # lat and lon exist
# lat/lon are appended at indexes 10/11 in analytics.log_file_access
lat = row[10] if len(row) > 10 else None
lon = row[11] if len(row) > 11 else None
city = row[8] if len(row) > 8 else None
country = row[9] if len(row) > 9 else None
if lat and lon:
connections.append({
'timestamp': row[0],
'city': row[4],
'country': row[5],
'lat': row[8],
'lon': row[9]
'city': city,
'country': country,
'lat': lat,
'lon': lon
})
emit('map_initial_data', {'connections': connections})

View File

@ -18,6 +18,7 @@
display: flex;
flex-direction: column;
min-width: 0;
min-height: 0;
}
.table-section {
flex: 1;
@ -27,7 +28,9 @@
}
#map {
width: 100%;
height: 100%;
flex: 1;
height: auto;
min-height: 320px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.2);
}
@ -155,6 +158,10 @@
<script>
// Initialize the map centered on Europe
const map = L.map('map').setView([50.0, 10.0], 5);
const refreshMapSize = () => setTimeout(() => map.invalidateSize(), 150);
refreshMapSize();
window.addEventListener('resize', refreshMapSize);
window.addEventListener('orientationchange', refreshMapSize);
// Add OpenStreetMap tile layer
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {