copier: прогресс по байтам, скорость и ETA

- Прогрессбар по скопированным байтам (doneBytes / totalBytes)
- SpeedBPS и ETASec добавлены в Task
- Dashboard показывает скорость (МБ/с) и ETA справа от прогрессбара

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-23 22:00:14 +03:00
parent 7c5736b935
commit 5b3cb9e393
3 changed files with 61 additions and 6 deletions

View File

@@ -30,7 +30,10 @@
<div class="progress-bar-bg">
<div class="progress-bar-fill" id="progressFill" style="width:0%"></div>
</div>
<div class="progress-label" id="progressMsg">Подготовка…</div>
<div style="display:flex;justify-content:space-between;align-items:baseline;margin-top:6px">
<div class="progress-label" id="progressMsg">Подготовка…</div>
<div class="progress-label" id="progressMeta" style="text-align:right"></div>
</div>
</div>
</section>
@@ -83,6 +86,21 @@ async function refreshDisk() {
function startTaskPoll(id) { stopTaskPoll(); pollInterval = setInterval(() => pollTask(id), 1500); }
function stopTaskPoll() { if (pollInterval) { clearInterval(pollInterval); pollInterval = null; } }
function fmtSpeed(bps) {
if (!bps) return '';
if (bps >= 1e9) return (bps/1e9).toFixed(1) + ' ГБ/с';
if (bps >= 1e6) return (bps/1e6).toFixed(1) + ' МБ/с';
if (bps >= 1e3) return (bps/1e3).toFixed(0) + ' КБ/с';
return bps + ' Б/с';
}
function fmtETA(sec) {
if (!sec || sec <= 0) return '';
if (sec >= 3600) return Math.floor(sec/3600) + ' ч ' + Math.floor((sec%3600)/60) + ' мин';
if (sec >= 60) return Math.floor(sec/60) + ' мин';
return sec + ' с';
}
async function pollTask(id) {
try {
const r = await fetch('/api/tasks/' + id);
@@ -90,12 +108,18 @@ async function pollTask(id) {
const t = await r.json();
document.getElementById('progressFill').style.width = t.progress + '%';
document.getElementById('progressMsg').textContent = t.message || '…';
const speed = fmtSpeed(t.speed_bps);
const eta = fmtETA(t.eta_sec);
const meta = [speed, eta ? 'ETA: ' + eta : ''].filter(Boolean).join(' · ');
document.getElementById('progressMeta').textContent = meta;
if (['success','failed','canceled'].includes(t.status)) {
stopTaskPoll(); activeTaskId = null;
document.getElementById('btnStart').disabled = false;
document.getElementById('btnStart').classList.remove('hidden');
document.getElementById('btnCancel').classList.add('hidden');
document.getElementById('progressPanel').classList.add('hidden');
document.getElementById('progressMeta').textContent = '';
if (t.status === 'success') toast(t.message || 'Готово', 'ok');
if (t.status === 'failed') toast('Ошибка: ' + t.error, 'error');
if (t.status === 'canceled') toast('Копирование отменено', 'error');