Actualiser js/admin.js
This commit is contained in:
+54
-7
@@ -425,25 +425,72 @@ function normalizeVideothequeRow(row) {
|
|||||||
async function handleVideothequeUpload(input) {
|
async function handleVideothequeUpload(input) {
|
||||||
if (!input.files || input.files.length === 0) return;
|
if (!input.files || input.files.length === 0) return;
|
||||||
let allData = [];
|
let allData = [];
|
||||||
for (const file of input.files) { try { allData = allData.concat(parseCSV(await file.text())); } catch(e) {} }
|
for (const file of input.files) {
|
||||||
if (allData.length === 0) { input.value = ''; return alert('❌ Fichier vide.'); }
|
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);
|
allData = allData.map(normalizeVideothequeRow);
|
||||||
showImportModal(allData.length, 'videotheque');
|
showImportModal(allData.length, 'videotheque');
|
||||||
let processed = 0;
|
let processed = 0;
|
||||||
|
let allDebugLogs = []; // 🔥 COLLECTER LES LOGS
|
||||||
|
|
||||||
for (let i = 0; i < allData.length; i += 3) {
|
for (let i = 0; i < allData.length; i += 3) {
|
||||||
const batch = allData.slice(i, i + 3);
|
const batch = allData.slice(i, i + 3);
|
||||||
try {
|
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' }) });
|
const response = await fetch(`${API_URL}?action=import_batch`, {
|
||||||
if (!response.ok) throw new Error(`Erreur serveur ${response.status}`);
|
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();
|
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) {
|
} 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;
|
processed += batch.length;
|
||||||
updateImportModal(processed, allData.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.`);
|
showSuccessModal(`${allData.length} support(s) importé(s) avec succès.`);
|
||||||
loadDashboardData();
|
loadDashboardData();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user