Actualiser js/admin.js
This commit is contained in:
+18
-74
@@ -392,68 +392,34 @@ 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 += 3) {
|
||||||
for (let i = 0; i < allData.length; i += 3) { // 🔥 Réduit de 10 à 3 pour éviter le timeout serveur
|
|
||||||
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`, {
|
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' }) });
|
||||||
method: 'POST',
|
if (!response.ok) throw new Error(`Erreur serveur ${response.status}`);
|
||||||
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();
|
const result = await response.json();
|
||||||
if (!result.success) {
|
if (!result.success) throw new Error(result.error || "Erreur inconnue.");
|
||||||
throw new Error(result.error || "Erreur inconnue lors de l'import.");
|
|
||||||
}
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
closeImportModal(); alert("❌ Échec de l'import : " + err.message); input.value = ''; return;
|
||||||
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 = ''; closeImportModal();
|
||||||
input.value = '';
|
|
||||||
closeImportModal();
|
|
||||||
showSuccessModal(`${allData.length} critique(s) importée(s) avec succès.`);
|
showSuccessModal(`${allData.length} critique(s) importée(s) avec succès.`);
|
||||||
loadDashboardData();
|
loadDashboardData();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 🔥 NETTOYAGE DES DONNÉES CSV VIDÉOTHÈQUE (Collectorz / CLZ)
|
|
||||||
function normalizeVideothequeRow(row) {
|
function normalizeVideothequeRow(row) {
|
||||||
let ean = row['ean_isbn13'] || row['EAN'] || '';
|
let ean = row['ean_isbn13'] || row['EAN'] || '';
|
||||||
if (ean !== '') {
|
if (ean !== '') { const eanNum = parseFloat(ean); ean = isNaN(eanNum) ? '' : String(Math.round(eanNum)); }
|
||||||
const eanNum = parseFloat(ean);
|
|
||||||
ean = isNaN(eanNum) ? '' : String(Math.round(eanNum));
|
|
||||||
}
|
|
||||||
let length = row['length'] || '';
|
let length = row['length'] || '';
|
||||||
if (length !== '' && length !== null) {
|
if (length !== '' && length !== null) { const l = parseFloat(length); length = isNaN(l) ? '' : String(Math.round(l)); }
|
||||||
const l = parseFloat(length);
|
|
||||||
length = isNaN(l) ? '' : String(Math.round(l));
|
|
||||||
}
|
|
||||||
let discs = row['number_of_discs'] || '';
|
let discs = row['number_of_discs'] || '';
|
||||||
if (discs === '' || discs === null || isNaN(parseFloat(discs))) {
|
if (discs === '' || discs === null || isNaN(parseFloat(discs))) { discs = 1; } else { discs = Math.round(parseFloat(discs)); }
|
||||||
discs = 1;
|
return Object.assign({}, row, { ean_isbn13: ean, length: length, number_of_discs: discs });
|
||||||
} else {
|
|
||||||
discs = Math.round(parseFloat(discs));
|
|
||||||
}
|
|
||||||
return Object.assign({}, row, {
|
|
||||||
ean_isbn13: ean,
|
|
||||||
length: length,
|
|
||||||
number_of_discs: discs
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleVideothequeUpload(input) {
|
async function handleVideothequeUpload(input) {
|
||||||
@@ -461,42 +427,23 @@ async function handleVideothequeUpload(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.'); }
|
||||||
|
|
||||||
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 += 3) {
|
||||||
for (let i = 0; i < allData.length; i += 3) { // 🔥 Réduit de 10 à 3 pour éviter le timeout serveur
|
|
||||||
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`, {
|
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' }) });
|
||||||
method: 'POST',
|
if (!response.ok) throw new Error(`Erreur serveur ${response.status}`);
|
||||||
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();
|
const result = await response.json();
|
||||||
if (!result.success) {
|
if (!result.success) throw new Error(result.error || "Erreur inconnue.");
|
||||||
throw new Error(result.error || "Erreur inconnue lors de l'import.");
|
|
||||||
}
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
closeImportModal(); alert("❌ Échec de l'import : " + err.message); input.value = ''; return;
|
||||||
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 = ''; closeImportModal();
|
||||||
input.value = '';
|
|
||||||
closeImportModal();
|
|
||||||
showSuccessModal(`${allData.length} support(s) importé(s) avec succès.`);
|
showSuccessModal(`${allData.length} support(s) importé(s) avec succès.`);
|
||||||
loadDashboardData();
|
loadDashboardData();
|
||||||
}
|
}
|
||||||
@@ -515,17 +462,14 @@ function updateImportModal(current, total) {
|
|||||||
document.getElementById('import-modal-counter').textContent = `${pct}%`;
|
document.getElementById('import-modal-counter').textContent = `${pct}%`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function closeImportModal() {
|
function closeImportModal() { document.getElementById('import-progress-modal').classList.remove('open'); }
|
||||||
document.getElementById('import-progress-modal').classList.remove('open');
|
|
||||||
}
|
|
||||||
|
|
||||||
async function saveConfigKeys() {
|
async function saveConfigKeys() {
|
||||||
const keyValue = document.getElementById('tmdb-key-input').value.trim();
|
const keyValue = document.getElementById('tmdb-key-input').value.trim();
|
||||||
if (!keyValue) { closeConfigModal(); return; }
|
if (!keyValue) { closeConfigModal(); return; }
|
||||||
try {
|
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 }) });
|
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 !');
|
alert('✅ Clé sauvegardée !'); closeConfigModal();
|
||||||
closeConfigModal();
|
|
||||||
} catch (err) { alert('Erreur serveur.'); }
|
} catch (err) { alert('Erreur serveur.'); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user