diff --git a/ui/scripts.js b/ui/scripts.js index 88c9002..95f3632 100644 --- a/ui/scripts.js +++ b/ui/scripts.js @@ -149,6 +149,19 @@ async function fetchQueue() { return apiFetch('/api/queue'); } +/** Map internal qBittorrent-shaped states to labels the UI should show. */ +function displayState(e) { + const s = e.state || ''; + // Fake qBt uses "uploading" for finished (seeding) — show "done" in the UI. + if (s === 'uploading' || ((e.progress || 0) >= 1 && s !== 'error' && s !== 'downloading')) { + return { key: 'done', label: 'done' }; + } + if (s === 'queuedDL') return { key: 'queued', label: 'queued' }; + if (s === 'downloading') return { key: 'downloading', label: 'downloading' }; + if (s === 'error') return { key: 'error', label: 'error' }; + return { key: s || 'unknown', label: s || 'unknown' }; +} + function renderQueue() { fetchQueue().then(entries => { if (!entries || entries.length === 0) { @@ -159,22 +172,24 @@ function renderQueue() { const pct = Math.round((e.progress || 0) * 100); const downloaded = formatSize(e.progress * e.size); const total = formatSize(e.size); + const st = displayState(e); let fillClass = ''; - if (e.state === 'uploading') fillClass = 'done'; - else if (e.state === 'error') fillClass = 'error'; - else if (e.state === 'queuedDL') fillClass = 'queued'; + if (st.key === 'done') fillClass = 'done'; + else if (st.key === 'error') fillClass = 'error'; + else if (st.key === 'queued') fillClass = 'queued'; + const speed = st.key === 'done' ? '' : (e.speed || ''); return `