Actualiser js/admin.js

This commit is contained in:
2026-06-24 10:25:13 +02:00
parent 4bf47c8bda
commit 07ba1d8842
+18 -74
View File
@@ -392,68 +392,34 @@ async function handleCritiqueUpload(input) {
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.'); }
showImportModal(allData.length, 'critique');
let processed = 0;
for (let i = 0; i < allData.length; i += 3) { // 🔥 Réduit de 10 à 3 pour éviter le timeout serveur
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: 'critique' })
});
// 🔥 VÉRIFICATION DE LA RÉPONSE SERVEUR
if (!response.ok) {
const errText = await response.text();
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: 'critique' }) });
if (!response.ok) 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.");
}
if (!result.success) throw new Error(result.error || "Erreur inconnue.");
} catch (err) {
console.error(err);
closeImportModal();
alert("❌ Échec de l'import : " + err.message);
input.value = '';
return; // Stoppe l'import en cas d'erreur
closeImportModal(); alert("❌ Échec de l'import : " + err.message); input.value = ''; return;
}
processed += batch.length;
updateImportModal(processed, allData.length);
}
input.value = '';
closeImportModal();
input.value = ''; closeImportModal();
showSuccessModal(`${allData.length} critique(s) importée(s) avec succès.`);
loadDashboardData();
}
// 🔥 NETTOYAGE DES DONNÉES CSV VIDÉOTHÈQUE (Collectorz / CLZ)
function normalizeVideothequeRow(row) {
let ean = row['ean_isbn13'] || row['EAN'] || '';
if (ean !== '') {
const eanNum = parseFloat(ean);
ean = isNaN(eanNum) ? '' : String(Math.round(eanNum));
}
if (ean !== '') { const eanNum = parseFloat(ean); ean = isNaN(eanNum) ? '' : String(Math.round(eanNum)); }
let length = row['length'] || '';
if (length !== '' && length !== null) {
const l = parseFloat(length);
length = isNaN(l) ? '' : String(Math.round(l));
}
if (length !== '' && length !== null) { const l = parseFloat(length); length = isNaN(l) ? '' : String(Math.round(l)); }
let discs = row['number_of_discs'] || '';
if (discs === '' || discs === null || isNaN(parseFloat(discs))) {
discs = 1;
} else {
discs = Math.round(parseFloat(discs));
}
return Object.assign({}, row, {
ean_isbn13: ean,
length: length,
number_of_discs: discs
});
if (discs === '' || discs === null || isNaN(parseFloat(discs))) { discs = 1; } else { discs = Math.round(parseFloat(discs)); }
return Object.assign({}, row, { ean_isbn13: ean, length: length, number_of_discs: discs });
}
async function handleVideothequeUpload(input) {
@@ -461,42 +427,23 @@ async function handleVideothequeUpload(input) {
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.'); }
allData = allData.map(normalizeVideothequeRow);
showImportModal(allData.length, 'videotheque');
let processed = 0;
for (let i = 0; i < allData.length; i += 3) { // 🔥 Réduit de 10 à 3 pour éviter le timeout serveur
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' })
});
// 🔥 VÉRIFICATION DE LA RÉPONSE SERVEUR
if (!response.ok) {
const errText = await response.text();
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) 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.");
}
if (!result.success) throw new Error(result.error || "Erreur inconnue.");
} catch (err) {
console.error(err);
closeImportModal();
alert("❌ Échec de l'import : " + err.message);
input.value = '';
return; // Stoppe l'import en cas d'erreur
closeImportModal(); alert("❌ Échec de l'import : " + err.message); input.value = ''; return;
}
processed += batch.length;
updateImportModal(processed, allData.length);
}
input.value = '';
closeImportModal();
input.value = ''; closeImportModal();
showSuccessModal(`${allData.length} support(s) importé(s) avec succès.`);
loadDashboardData();
}
@@ -515,17 +462,14 @@ function updateImportModal(current, total) {
document.getElementById('import-modal-counter').textContent = `${pct}%`;
}
function closeImportModal() {
document.getElementById('import-progress-modal').classList.remove('open');
}
function closeImportModal() { document.getElementById('import-progress-modal').classList.remove('open'); }
async function saveConfigKeys() {
const keyValue = document.getElementById('tmdb-key-input').value.trim();
if (!keyValue) { closeConfigModal(); return; }
try {
await fetch(`${API_URL}?action=save_config`, { method: 'POST', headers: { 'Authorization': localStorage.getItem('token'), 'Content-Type': 'application/json' }, body: JSON.stringify({ key_name: 'tmdb_api_key', key_value: keyValue }) });
alert('✅ Clé sauvegardée !');
closeConfigModal();
alert('✅ Clé sauvegardée !'); closeConfigModal();
} catch (err) { alert('Erreur serveur.'); }
}