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 <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
root
2026-01-23 11:17:37 +00:00
parent 3d7a17d0d7
commit adb43ee371
+20 -4
View File
@@ -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