Actualiser js/admin.js

This commit is contained in:
2026-06-19 14:20:40 +02:00
parent a97ece2e0a
commit 37af023c3e
+15 -3
View File
@@ -263,22 +263,34 @@ async function saveFilmForm(e) {
// ── IMPORT CSV ── // ── IMPORT CSV ──
async function handleCsvUpload(input) { async function handleCsvUpload(input) {
if (!input.files || input.files.length === 0) return; if (!input.files || input.files.length === 0) return;
const file = input.files[0]; const file = input.files[0];
const formData = new FormData(); const formData = new FormData();
formData.append('csv_file', file); formData.append('csv_file', file);
formData.append('type', currentAdminTab); formData.append('type', currentAdminTab);
try { try {
await fetch(`${API_URL}?action=import_csv`, { const res = await fetch(`${API_URL}?action=import_csv`, {
method: 'POST', method: 'POST',
headers: { 'Authorization': localStorage.getItem('token') }, headers: { 'Authorization': localStorage.getItem('token') },
body: formData body: formData
}); });
const data = await res.json();
// 🚨 Vérification de l'erreur serveur
if (!res.ok || data.error) {
alert('❌ Erreur import : ' + (data.error || 'Erreur serveur inconnue'));
return;
}
input.value = ''; input.value = '';
closeConfigModal(); closeConfigModal();
alert(`✅ Import réussi ! ${data.imported || 0} élément(s) traité(s).`);
loadDashboardData(); loadDashboardData();
} catch (err) { console.error('Erreur import CSV :', err); } } catch (err) {
console.error('Erreur import CSV :', err);
alert('❌ Erreur de communication avec le serveur.');
}
} }
// ── SAUVEGARDE CLÉ TMDB (EN BASE DE DONNÉES) ── // ── SAUVEGARDE CLÉ TMDB (EN BASE DE DONNÉES) ──