From 5fde69fcf53080749f721d5fa16c212757676ed0 Mon Sep 17 00:00:00 2001 From: Gronod Date: Wed, 20 May 2026 01:07:52 +0100 Subject: [PATCH] Add speed formatting to display appropriate units (KB/s, MB/s) --- docker-compose.yaml | 6 +++++- public/app.js | 17 ++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index 1448404..6e21e71 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -44,13 +44,17 @@ services: volumes: # Persistent volume for token store and log file - sofarr-data:/app/data + # Mount code for development (comment out in production) + - ./server:/app/server + - ./public:/app/public # Mount your own TLS certificate and key (optional — snakeoil used if omitted) # - /path/to/your/server.crt:/app/certs/server.crt:ro # - /path/to/your/server.key:/app/certs/server.key:ro # Run as the built-in non-root 'node' user (UID/GID 1000) user: "1000:1000" # Read-only root filesystem; only the data volume is writable - read_only: true + # Comment out for development when mounting code volumes + # read_only: true tmpfs: - /tmp # Node.js needs a writable /tmp security_opt: diff --git a/public/app.js b/public/app.js index 67427f8..d3ecdd2 100644 --- a/public/app.js +++ b/public/app.js @@ -879,7 +879,7 @@ function createDownloadCard(download) { } if (download.speed && download.speed > 0) { - const speed = createDetailItem('Speed', download.speed); + const speed = createDetailItem('Speed', formatSpeed(download.speed)); details.appendChild(speed); } @@ -936,6 +936,21 @@ function createDownloadCard(download) { return card; } +function formatSpeed(bytesPerSecond) { + if (!bytesPerSecond || bytesPerSecond === 0) return '0 B/s'; + + const units = ['B/s', 'KB/s', 'MB/s', 'GB/s']; + let value = bytesPerSecond; + let unitIndex = 0; + + while (value >= 1024 && unitIndex < units.length - 1) { + value /= 1024; + unitIndex++; + } + + return `${value.toFixed(2)} ${units[unitIndex]}`; +} + function createDetailItem(label, value) { const item = document.createElement('div'); item.className = 'detail-item';