diff --git a/server/clients/SABnzbdClient.js b/server/clients/SABnzbdClient.js index e3f7344..f3f1d46 100644 --- a/server/clients/SABnzbdClient.js +++ b/server/clients/SABnzbdClient.js @@ -45,9 +45,10 @@ class SABnzbdClient extends DownloadClient { async getActiveDownloads() { try { // Get both queue and history to provide complete picture - const [queueResponse, historyResponse] = await Promise.all([ + const [queueResponse, historyResponse, clientStatus] = await Promise.all([ this.makeRequest({ mode: 'queue' }), - this.makeRequest({ mode: 'history', limit: 10 }) + this.makeRequest({ mode: 'history', limit: 10 }), + this.getClientStatus() ]); const queueData = queueResponse.data; @@ -57,15 +58,19 @@ class SABnzbdClient extends DownloadClient { // Process active queue items if (queueData.queue && queueData.queue.slots) { + // Find the currently downloading slot (first one with status 'Downloading') + const activeSlot = queueData.queue.slots.find(slot => slot.status === 'Downloading'); + const activeSpeed = activeSlot && clientStatus ? (clientStatus.kbpersec ? clientStatus.kbpersec * 1024 : 0) : 0; + for (const slot of queueData.queue.slots) { - downloads.push(this.normalizeDownload(slot, 'queue')); + downloads.push(this.normalizeDownload(slot, 'queue', activeSlot === slot ? activeSpeed : 0)); } } // Process recent history items (last 10) if (historyData.history && historyData.history.slots) { for (const slot of historyData.history.slots) { - downloads.push(this.normalizeDownload(slot, 'history')); + downloads.push(this.normalizeDownload(slot, 'history', 0)); } } @@ -102,7 +107,7 @@ class SABnzbdClient extends DownloadClient { } } - normalizeDownload(slot, source) { + normalizeDownload(slot, source, speed = 0) { const isHistory = source === 'history'; // Map SABnzbd statuses to normalized status @@ -164,6 +169,7 @@ class SABnzbdClient extends DownloadClient { progress: Math.round(progress), size: Math.round(size), downloaded: Math.round(downloaded), + speed: speed, eta: this.calculateEta(slot.timeleft || slot.eta), category: slot.cat || undefined, tags: slot.labels ? (Array.isArray(slot.labels) ? slot.labels : slot.labels.split(',')).filter(tag => tag && tag.trim()) : [],