From adb43ee3714e56e7f285ee1c853be8860dca1648 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 23 Jan 2026 11:17:37 +0000 Subject: [PATCH] fix: Prevent network loop during cleanup operation - Add isClearing flag to prevent auto-refresh conflicts during deletion - Use Promise.all() to delete all tasks in parallel instead of sequential await - Add error handling with try/catch/finally block - Skip loadDownloads() when isClearing is true This fixes the infinite network request loop that occurred when clicking cleanup. Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude Co-Authored-By: Happy --- templates/index.html | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/templates/index.html b/templates/index.html index dff2839..59f6e04 100644 --- a/templates/index.html +++ b/templates/index.html @@ -838,6 +838,7 @@ let searchResultsCache = {}; let allDownloads = []; // Store all downloads for filtering let collapsedGroups = new Set(); // Store which groups are collapsed + let isClearing = false; // Flag to prevent conflicts during cleanup // Extract series name from filename (for grouping) function extractSeriesName(filename) { @@ -988,11 +989,22 @@ return; } - for (const dl of unwanted) { - await fetch(`${API_BASE}/download/${dl.id}`, { method: 'DELETE' }); - } + // Set flag to prevent auto-refresh conflicts + isClearing = true; - loadDownloads(); + try { + // Delete all in parallel (much faster) + await Promise.all(unwanted.map(dl => + fetch(`${API_BASE}/download/${dl.id}`, { method: 'DELETE' }) + )); + } catch (error) { + console.error('Error deleting downloads:', error); + alert('Erreur lors de la suppression'); + } finally { + // Clear flag and refresh + isClearing = false; + loadDownloads(); + } } // Search Anime across all providers @@ -1506,6 +1518,10 @@ } async function loadDownloads() { + // Skip refresh if currently clearing downloads to avoid conflicts + if (isClearing) { + return; + } const response = await fetch(`${API_BASE}/downloads`); const data = await response.json(); allDownloads = data.downloads; // Store all downloads