From 311fd89a549eef01cb685ab31af4ae7b360d1d3c Mon Sep 17 00:00:00 2001 From: lelo Date: Thu, 25 Dec 2025 20:59:59 +0000 Subject: [PATCH] only audio for recent 10 minute log --- analytics.py | 35 ++++++++++++++++++++++++----------- templates/connections.html | 3 ++- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/analytics.py b/analytics.py index c73b08b..ff6428e 100644 --- a/analytics.py +++ b/analytics.py @@ -249,20 +249,33 @@ def return_folder_yesterday(): def return_file_access(): - """Return recent file access logs from memory (the last 10 minutes).""" + """Return recent audio file access logs from memory (the last 10 minutes).""" global file_access_temp - if file_access_temp: - # Create a timezone-aware cutoff time - cutoff_time = datetime.now(timezone.utc).astimezone() - timedelta(minutes=10) - # Only keep entries with timestamps greater than or equal to cutoff_time - file_access_temp[:] = [ - entry for entry in file_access_temp - if datetime.fromisoformat(entry[0]) >= cutoff_time - ] - return file_access_temp - else: + + def is_audio(entry): + """Check whether a log entry references an audio file.""" + mime_val = (entry[3] or "").lower() + if mime_val.startswith("audio/"): + return True + path_val = (entry[1] or "").lower() + return path_val.endswith(( + ".mp3", ".wav", ".flac", ".m4a", ".aac", + ".ogg", ".wma", ".aiff", ".alac", ".opus" + )) + + if not file_access_temp: return [] + # Create a timezone-aware cutoff time + cutoff_time = datetime.now(timezone.utc).astimezone() - timedelta(minutes=10) + # Only keep entries with timestamps greater than or equal to cutoff_time + file_access_temp[:] = [ + entry for entry in file_access_temp + if datetime.fromisoformat(entry[0]) >= cutoff_time + ] + # Only expose audio file accesses to the UI + return [entry for entry in file_access_temp if is_audio(entry)] + def return_file_access_with_geo(): """Return recent file access logs with geographic coordinates from the database.""" diff --git a/templates/connections.html b/templates/connections.html index 3f25712..f7d9c71 100644 --- a/templates/connections.html +++ b/templates/connections.html @@ -101,7 +101,8 @@ {% block content %}
-

Verbindungen der letzten 10 Minuten

+

Verbindungen der letzten 10 Minuten (nur Audio)

+

Diese Ansicht listet ausschließlich Zugriffe auf Audio-Dateien.

Last Connection