From 79fa989a6d14e939e052f68439632ba8bfe3e719 Mon Sep 17 00:00:00 2001 From: lelo Date: Sun, 14 Dec 2025 10:38:58 +0000 Subject: [PATCH] update connection page --- app.py | 19 ++++++++++++++++ templates/connections.html | 46 ++++++++++++++++++++++++++++++++------ 2 files changed, 58 insertions(+), 7 deletions(-) diff --git a/app.py b/app.py index cae6039..8f98b71 100755 --- a/app.py +++ b/app.py @@ -222,6 +222,23 @@ def generate_breadcrumbs(subpath=None): breadcrumbs.append({'name': part, 'path': path_accum}) return breadcrumbs + +def human_readable_size(num_bytes): + """ + Convert a byte count into a human-readable string (e.g., 1.2 MB). + """ + if num_bytes is None: + return "-" + try: + num = float(num_bytes) + except (TypeError, ValueError): + return "-" + units = ['B', 'KB', 'MB', 'GB', 'TB'] + for unit in units: + if num < 1024 or unit == units[-1]: + return f"{num:.1f} {unit}" if num % 1 else f"{int(num)} {unit}" + num /= 1024 + @app.route('/icon/.png') def serve_resized_icon(size): cached_image_bytes = get_cached_image(size) @@ -632,6 +649,7 @@ def query_recent_connections(): 'timestamp': datetime.fromisoformat(row[0]).strftime('%d.%m.%Y %H:%M:%S'), 'full_path': row[1], 'filesize': row[2], + 'filesize_human': human_readable_size(row[2]), 'mime_typ': row[3], 'location': row[4], 'user_agent': row[5], @@ -673,6 +691,7 @@ def handle_request_initial_data(): 'timestamp': datetime.fromisoformat(row[0]).strftime('%d.%m.%Y %H:%M:%S'), 'full_path': row[1], 'filesize' : row[2], + 'filesize_human': human_readable_size(row[2]), 'mime_typ' : row[3], 'location': row[4], 'user_agent': row[5], diff --git a/templates/connections.html b/templates/connections.html index 5394689..07cafb4 100644 --- a/templates/connections.html +++ b/templates/connections.html @@ -100,10 +100,6 @@

Verbindungen der letzten 10 Minuten

-
-
Active Dots
-
0
-
Last Connection
-
@@ -112,6 +108,14 @@
Total Connections
0
+
+
Total File Size
+
0 B
+
+
+
Cached %
+
0%
+
@@ -228,8 +232,6 @@ } function updateMapStats() { - document.getElementById('active-dots').textContent = activeDots.size; - let mostRecent = null; activeDots.forEach(dot => { if (!mostRecent || dot.lastUpdate > mostRecent) { @@ -252,6 +254,28 @@ return `${hours}h ago`; } + function formatBytes(bytes) { + if (!bytes && bytes !== 0) return "-"; + const units = ['B', 'KB', 'MB', 'GB', 'TB']; + let num = bytes; + let unitIndex = 0; + while (num >= 1024 && unitIndex < units.length - 1) { + num /= 1024; + unitIndex++; + } + const rounded = num % 1 === 0 ? num.toFixed(0) : num.toFixed(1); + return `${rounded} ${units[unitIndex]}`; + } + + function toBool(val) { + if (val === true || val === 1) return true; + if (typeof val === 'string') { + const lower = val.toLowerCase(); + return lower === 'true' || lower === '1' || lower === 'yes'; + } + return false; + } + function animateDots() { const now = Date.now(); const fadeTime = 10 * 60 * 1000; // 10 minutes @@ -306,6 +330,14 @@ // Table functions function updateStats(data) { document.getElementById("totalConnections").textContent = data.length; + const totalBytes = data.reduce((sum, rec) => { + const val = parseFloat(rec.filesize); + return sum + (isNaN(val) ? 0 : val); + }, 0); + document.getElementById("totalSize").textContent = formatBytes(totalBytes); + const cachedCount = data.reduce((sum, rec) => sum + (toBool(rec.cached) ? 1 : 0), 0); + const pct = data.length ? ((cachedCount / data.length) * 100).toFixed(0) : 0; + document.getElementById("cachedPercent").textContent = `${pct}%`; } function createRow(record, animate=true) { @@ -321,7 +353,7 @@ ${record.location} ${record.user_agent} ${record.full_path} - ${record.filesize} + ${record.filesize_human || record.filesize} ${record.mime_typ} ${record.cached} `;