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:
+19
-3
@@ -838,6 +838,7 @@
|
|||||||
let searchResultsCache = {};
|
let searchResultsCache = {};
|
||||||
let allDownloads = []; // Store all downloads for filtering
|
let allDownloads = []; // Store all downloads for filtering
|
||||||
let collapsedGroups = new Set(); // Store which groups are collapsed
|
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)
|
// Extract series name from filename (for grouping)
|
||||||
function extractSeriesName(filename) {
|
function extractSeriesName(filename) {
|
||||||
@@ -988,12 +989,23 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const dl of unwanted) {
|
// Set flag to prevent auto-refresh conflicts
|
||||||
await fetch(`${API_BASE}/download/${dl.id}`, { method: 'DELETE' });
|
isClearing = true;
|
||||||
}
|
|
||||||
|
|
||||||
|
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();
|
loadDownloads();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Search Anime across all providers
|
// Search Anime across all providers
|
||||||
async function searchAnime() {
|
async function searchAnime() {
|
||||||
@@ -1506,6 +1518,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function loadDownloads() {
|
async function loadDownloads() {
|
||||||
|
// Skip refresh if currently clearing downloads to avoid conflicts
|
||||||
|
if (isClearing) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const response = await fetch(`${API_BASE}/downloads`);
|
const response = await fetch(`${API_BASE}/downloads`);
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
allDownloads = data.downloads; // Store all downloads
|
allDownloads = data.downloads; // Store all downloads
|
||||||
|
|||||||
Reference in New Issue
Block a user