Actualiser js/admin.js

This commit is contained in:
2026-07-01 10:34:27 +02:00
parent 08f5b9ec40
commit abaf2668b1
+20 -26
View File
@@ -447,39 +447,33 @@ function handleVideothequeUpload(input) {
try { try {
// ✅ Lots de 1 seul pour éviter le blocage Blu-ray.com // ✅ Lots de 1 seul pour éviter le blocage Blu-ray.com
for (let i = 0; i < items.length; i += 1) { const batchSize = 5; // ou 10 selon la puissance du serveur
const batch = items.slice(i, i + 1); for (let i = 0; i < items.length; i += batchSize) {
const batch = items.slice(i, i + batchSize);
const res = await fetch(`${API_URL}?action=import_batch`, { const res = await fetch(`${API_URL}?action=import_batch`, {
method: 'POST', method: 'POST',
headers: { 'Authorization': localStorage.getItem('token'), 'Content-Type': 'application/json' }, headers: { 'Authorization': localStorage.getItem('token'), 'Content-Type': 'application/json' },
body: JSON.stringify({ type: 'videotheque', items: batch }) body: JSON.stringify({ type: 'videotheque', items: batch })
}); });
// ... traitement de la réponse
if (!res.ok) throw new Error(`Erreur HTTP ${res.status}`); // Petit délai optionnel (100 ms) pour éviter de saturer le serveur
const data = await res.json(); await new Promise(r => setTimeout(r, 100));
if (!data.success) throw new Error(data.error || "Échec API");
totalImp += data.imported || 0;
totalSkp += data.skipped || 0;
processed += batch.length;
updateImportModal(processed, items.length);
await new Promise(r => setTimeout(r, 500)); // Délai de sécurité
} }
input.value = ''; input.value = '';
closeImportModal(); closeImportModal();
const msg = totalSkp > 0 ? ` (${totalSkp} ignoré(s))` : ''; const msg = totalSkp > 0 ? ` (${totalSkp} ignoré(s))` : '';
showSuccessModal(`${totalImp} édition(s) importée(s).${msg}`); showSuccessModal(`${totalImp} édition(s) importée(s).${msg}`);
loadDashboardData(); loadDashboardData();
} catch (err) { } catch (err) {
console.error(err); console.error(err);
closeImportModal(); closeImportModal();
alert("❌ Échec import : " + err.message); alert("❌ Échec import : " + err.message);
input.value = ''; input.value = '';
} }
}; };
reader.readAsText(file); reader.readAsText(file);
} }
function showImportModal(total, type) { function showImportModal(total, type) {
document.getElementById('import-modal-title').innerHTML = type === 'critique' ? '<i class="ti ti-star"></i> Import Critiques' : '<i class="ti ti-video"></i> Import Vidéothèque'; document.getElementById('import-modal-title').innerHTML = type === 'critique' ? '<i class="ti ti-star"></i> Import Critiques' : '<i class="ti ti-video"></i> Import Vidéothèque';