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