Actualiser js/admin.js

This commit is contained in:
2026-07-01 10:34:27 +02:00
parent 08f5b9ec40
commit abaf2668b1
+21 -27
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; input.value = '';
totalSkp += data.skipped || 0; closeImportModal();
processed += batch.length; const msg = totalSkp > 0 ? ` (${totalSkp} ignoré(s))` : '';
updateImportModal(processed, items.length); showSuccessModal(`${totalImp} édition(s) importée(s).${msg}`);
await new Promise(r => setTimeout(r, 500)); // Délai de sécurité loadDashboardData();
} catch (err) {
console.error(err);
closeImportModal();
alert("❌ Échec import : " + err.message);
input.value = '';
}
};
reader.readAsText(file);
} }
input.value = '';
closeImportModal();
const msg = totalSkp > 0 ? ` (${totalSkp} ignoré(s))` : '';
showSuccessModal(`${totalImp} édition(s) importée(s).${msg}`);
loadDashboardData();
} catch (err) {
console.error(err);
closeImportModal();
alert("❌ Échec import : " + err.message);
input.value = '';
}
};
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';