Actualiser js/admin.js
This commit is contained in:
+49
-6
@@ -392,16 +392,39 @@ async function handleCritiqueUpload(input) {
|
|||||||
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) { try { allData = allData.concat(parseCSV(await file.text())); } catch(e) {} }
|
||||||
if (allData.length === 0) { input.value = ''; return alert('❌ Fichier vide.'); }
|
if (allData.length === 0) { input.value = ''; return alert('❌ Fichier vide.'); }
|
||||||
|
|
||||||
showImportModal(allData.length, 'critique');
|
showImportModal(allData.length, 'critique');
|
||||||
let processed = 0;
|
let processed = 0;
|
||||||
|
|
||||||
for (let i = 0; i < allData.length; i += 10) {
|
for (let i = 0; i < allData.length; i += 10) {
|
||||||
const batch = allData.slice(i, i + 10);
|
const batch = allData.slice(i, i + 10);
|
||||||
try {
|
try {
|
||||||
await fetch(`${API_URL}?action=import_batch`, { method: 'POST', headers: { 'Authorization': localStorage.getItem('token'), 'Content-Type': 'application/json' }, body: JSON.stringify({ items: batch, type: 'critique' }) });
|
const response = await fetch(`${API_URL}?action=import_batch`, {
|
||||||
} catch (err) { console.error(err); }
|
method: 'POST',
|
||||||
|
headers: { 'Authorization': localStorage.getItem('token'), 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ items: batch, type: 'critique' })
|
||||||
|
});
|
||||||
|
|
||||||
|
// 🔥 VÉRIFICATION DE LA RÉPONSE SERVEUR
|
||||||
|
if (!response.ok) {
|
||||||
|
const errText = await response.text();
|
||||||
|
throw new Error(`Erreur serveur ${response.status}`);
|
||||||
|
}
|
||||||
|
const result = await response.json();
|
||||||
|
if (!result.success) {
|
||||||
|
throw new Error(result.error || "Erreur inconnue lors de l'import.");
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
closeImportModal();
|
||||||
|
alert("❌ Échec de l'import : " + err.message);
|
||||||
|
input.value = '';
|
||||||
|
return; // Stoppe l'import en cas d'erreur
|
||||||
|
}
|
||||||
processed += batch.length;
|
processed += batch.length;
|
||||||
updateImportModal(processed, allData.length);
|
updateImportModal(processed, allData.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
input.value = '';
|
input.value = '';
|
||||||
closeImportModal();
|
closeImportModal();
|
||||||
showSuccessModal(`${allData.length} critique(s) importée(s) avec succès.`);
|
showSuccessModal(`${allData.length} critique(s) importée(s) avec succès.`);
|
||||||
@@ -439,19 +462,39 @@ async function handleVideothequeUpload(input) {
|
|||||||
for (const file of input.files) { try { allData = allData.concat(parseCSV(await file.text())); } catch(e) {} }
|
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.'); }
|
if (allData.length === 0) { input.value = ''; return alert('❌ Fichier vide.'); }
|
||||||
|
|
||||||
// 🔥 Application du nettoyage avant envoi au serveur
|
|
||||||
allData = allData.map(normalizeVideothequeRow);
|
allData = allData.map(normalizeVideothequeRow);
|
||||||
|
|
||||||
showImportModal(allData.length, 'videotheque');
|
showImportModal(allData.length, 'videotheque');
|
||||||
let processed = 0;
|
let processed = 0;
|
||||||
|
|
||||||
for (let i = 0; i < allData.length; i += 10) {
|
for (let i = 0; i < allData.length; i += 10) {
|
||||||
const batch = allData.slice(i, i + 10);
|
const batch = allData.slice(i, i + 10);
|
||||||
try {
|
try {
|
||||||
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`, {
|
||||||
} catch (err) { console.error(err); }
|
method: 'POST',
|
||||||
|
headers: { 'Authorization': localStorage.getItem('token'), 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ items: batch, type: 'videotheque' })
|
||||||
|
});
|
||||||
|
|
||||||
|
// 🔥 VÉRIFICATION DE LA RÉPONSE SERVEUR
|
||||||
|
if (!response.ok) {
|
||||||
|
const errText = await response.text();
|
||||||
|
throw new Error(`Erreur serveur ${response.status}`);
|
||||||
|
}
|
||||||
|
const result = await response.json();
|
||||||
|
if (!result.success) {
|
||||||
|
throw new Error(result.error || "Erreur inconnue lors de l'import.");
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
closeImportModal();
|
||||||
|
alert("❌ Échec de l'import : " + err.message);
|
||||||
|
input.value = '';
|
||||||
|
return; // Stoppe l'import en cas d'erreur
|
||||||
|
}
|
||||||
processed += batch.length;
|
processed += batch.length;
|
||||||
updateImportModal(processed, allData.length);
|
updateImportModal(processed, allData.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
input.value = '';
|
input.value = '';
|
||||||
closeImportModal();
|
closeImportModal();
|
||||||
showSuccessModal(`${allData.length} support(s) importé(s) avec succès.`);
|
showSuccessModal(`${allData.length} support(s) importé(s) avec succès.`);
|
||||||
|
|||||||
Reference in New Issue
Block a user