From 2688a8775d7b0f5572b79e05700a1b43893dd2b4 Mon Sep 17 00:00:00 2001 From: Cedric Date: Wed, 24 Jun 2026 10:36:14 +0200 Subject: [PATCH] Actualiser js/admin.js --- js/admin.js | 61 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 54 insertions(+), 7 deletions(-) diff --git a/js/admin.js b/js/admin.js index 9d46ad3..6f5f323 100644 --- a/js/admin.js +++ b/js/admin.js @@ -425,25 +425,72 @@ function normalizeVideothequeRow(row) { async function handleVideothequeUpload(input) { if (!input.files || input.files.length === 0) return; let allData = []; - for (const file of input.files) { try { allData = allData.concat(parseCSV(await file.text())); } catch(e) {} } - if (allData.length === 0) { input.value = ''; return alert('❌ Fichier vide.'); } + for (const file of input.files) { + try { + allData = allData.concat(parseCSV(await file.text())); + } catch(e) { + console.error('Erreur parsing CSV:', e); + } + } + if (allData.length === 0) { + input.value = ''; + return alert('❌ Fichier vide.'); + } + allData = allData.map(normalizeVideothequeRow); showImportModal(allData.length, 'videotheque'); let processed = 0; + let allDebugLogs = []; // 🔥 COLLECTER LES LOGS + for (let i = 0; i < allData.length; i += 3) { const batch = allData.slice(i, i + 3); try { - const response = await fetch(`${API_URL}?action=import_batch`, { method: 'POST', headers: { 'Authorization': localStorage.getItem('token'), 'Content-Type': 'application/json' }, body: JSON.stringify({ items: batch, type: 'videotheque' }) }); - if (!response.ok) throw new Error(`Erreur serveur ${response.status}`); + const response = await fetch(`${API_URL}?action=import_batch`, { + method: 'POST', + headers: { + 'Authorization': localStorage.getItem('token'), + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ items: batch, type: 'videotheque' }) + }); + + if (!response.ok) { + const errText = await response.text(); + throw new Error(`Erreur serveur ${response.status}: ${errText}`); + } + const result = await response.json(); - if (!result.success) throw new Error(result.error || "Erreur inconnue."); + + // 🔥 COLLECTER LES LOGS DE DÉBOGAGE + if (result.debug) { + allDebugLogs = allDebugLogs.concat(result.debug); + } + + if (!result.success) { + throw new Error(result.error || "Erreur inconnue."); + } } catch (err) { - closeImportModal(); alert("❌ Échec de l'import : " + err.message); input.value = ''; return; + console.error('Erreur import:', err); + closeImportModal(); + alert("❌ Échec de l'import : " + err.message); + input.value = ''; + return; } processed += batch.length; updateImportModal(processed, allData.length); } - input.value = ''; closeImportModal(); + + input.value = ''; + closeImportModal(); + + // 🔥 AFFICHER LES LOGS DANS LA CONSOLE + if (allDebugLogs.length > 0) { + console.log('=== LOGS D\'IMPORT VIDÉOTHÈQUE ==='); + allDebugLogs.forEach(log => console.log(log)); + console.log('=================================='); + console.log(`✅ ${allData.length} film(s) importé(s)`); + } + showSuccessModal(`${allData.length} support(s) importé(s) avec succès.`); loadDashboardData(); }