Actualiser js/admin.js

This commit is contained in:
2026-06-24 10:36:14 +02:00
parent 61d86005d0
commit 2688a8775d
+54 -7
View File
@@ -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();
}