fix: clamp ETA bounds, store stats interval, add activeDownloads finally-cleanup, prevent progress backward jump

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
xRangerDE 2026-03-21 15:04:59 +01:00
parent 4607ba9cc6
commit 6c47c63fa8
2 changed files with 86 additions and 79 deletions

View File

@ -2204,17 +2204,19 @@ function downloadVODPart(
if (speed > 0 && downloadedBytes > 0) {
const itemStartTime = itemTracking.startTime;
const elapsedSec = (Date.now() - itemStartTime) / 1000;
if (elapsedSec > 3) {
if (elapsedSec > 5) { // Wait at least 5 seconds before showing ETA
const avgSpeed = downloadedBytes / elapsedSec;
if (expectedDurationSeconds && expectedDurationSeconds > 0) {
const estimatedTotalBytes = avgSpeed * expectedDurationSeconds;
if (estimatedTotalBytes > downloadedBytes) {
const remainingSec = (estimatedTotalBytes - downloadedBytes) / avgSpeed;
if (remainingSec > 0 && remainingSec < 86400) { // Between 0 and 24 hours
etaStr = formatETA(remainingSec);
}
}
}
}
}
onProgress({
id: itemId,
@ -2798,6 +2800,7 @@ async function processOneQueueItem(item: QueueItem): Promise<void> {
item.last_error = '';
try {
let finalResult: DownloadResult = { success: false, error: 'Unbekannter Fehler beim Download' };
const maxAttempts = getRetryAttemptLimit();
@ -2861,8 +2864,6 @@ async function processOneQueueItem(item: QueueItem): Promise<void> {
if (!hasQueueItemId(item.id)) {
appendDebugLog('queue-item-finished-removed', { itemId: item.id });
activeDownloads.delete(item.id);
cancelledItemIds.delete(item.id);
return;
}
@ -2877,9 +2878,6 @@ async function processOneQueueItem(item: QueueItem): Promise<void> {
runtimeMetrics.downloadsFailed += 1;
}
activeDownloads.delete(item.id);
cancelledItemIds.delete(item.id);
appendDebugLog('queue-item-finished', {
itemId: item.id,
status: item.status,
@ -2888,6 +2886,10 @@ async function processOneQueueItem(item: QueueItem): Promise<void> {
saveQueue(downloadQueue);
emitQueueUpdated();
} finally {
activeDownloads.delete(item.id);
cancelledItemIds.delete(item.id);
}
}
async function processQueue(): Promise<void> {

View File

@ -99,7 +99,7 @@ async function init(): Promise<void> {
// Update stats bar
updateStatsBar();
setInterval(updateStatsBar, 5000);
const _statsInterval = setInterval(updateStatsBar, 5000);
if (config.client_id && config.client_secret) {
await connect();
@ -275,9 +275,14 @@ function mergeQueueState(nextQueue: QueueItem[]): QueueItem[] {
return item;
}
// Keep the higher progress value to prevent backward jumps from stale data
const bestProgress = (prev.status === 'downloading' && prev.progress > item.progress)
? prev.progress
: (item.progress > 0 ? item.progress : prev.progress);
return {
...item,
progress: item.progress > 0 ? item.progress : prev.progress,
progress: bestProgress,
speed: item.speed || prev.speed,
eta: item.eta || prev.eta,
currentPart: item.currentPart || prev.currentPart,