Actualiser js/admin.js
This commit is contained in:
+9
-8
@@ -412,14 +412,14 @@ async function handleCritiqueUpload(input) {
|
||||
loadDashboardData();
|
||||
}
|
||||
|
||||
// ✅ NOUVEAU : Retourne l'EAN ET le titre du CSV
|
||||
function normalizeVideothequeRow(row) {
|
||||
let ean = row['ean_isbn13'] || row['EAN'] || row['ean'] || row['Barcode'] || row['UPC'] || row['upc_isbn10'] || '';
|
||||
if (ean) ean = String(ean).replace(/[^0-9]/g, '');
|
||||
|
||||
// ✅ NOUVEAU : Récupérer aussi le titre du CSV
|
||||
// ✅ Récupérer le titre du CSV comme secours
|
||||
let title = row['title'] ? String(row['title']).trim() : '';
|
||||
|
||||
// On garde la ligne si on a au moins un EAN ou un titre
|
||||
if (!ean && !title) return null;
|
||||
|
||||
return {
|
||||
@@ -437,6 +437,7 @@ function handleVideothequeUpload(input) {
|
||||
const parsed = parseCSV(text);
|
||||
if (!parsed.length) { alert("❌ CSV vide."); return; }
|
||||
|
||||
// ✅ NOUVEAU : On garde le titre du CSV
|
||||
const items = parsed.map(row => normalizeVideothequeRow(row)).filter(Boolean);
|
||||
|
||||
if (!items.length) { alert("❌ Aucun titre ou EAN valide trouvé."); return; }
|
||||
@@ -445,9 +446,9 @@ function handleVideothequeUpload(input) {
|
||||
let processed = 0, totalImp = 0, totalSkp = 0;
|
||||
|
||||
try {
|
||||
// Lots de 2 pour respecter les limites UPCitemdb (2s/requête)
|
||||
for (let i = 0; i < items.length; i += 2) {
|
||||
const batch = items.slice(i, i + 2);
|
||||
// ✅ Lots de 1 seul pour éviter le blocage Blu-ray.com
|
||||
for (let i = 0; i < items.length; i += 1) {
|
||||
const batch = items.slice(i, i + 1);
|
||||
const res = await fetch(`${API_URL}?action=import_batch`, {
|
||||
method: 'POST',
|
||||
headers: { 'Authorization': localStorage.getItem('token'), 'Content-Type': 'application/json' },
|
||||
@@ -462,13 +463,13 @@ function handleVideothequeUpload(input) {
|
||||
totalSkp += data.skipped || 0;
|
||||
processed += batch.length;
|
||||
updateImportModal(processed, items.length);
|
||||
await new Promise(r => setTimeout(r, 1500)); // Délai de sécurité
|
||||
await new Promise(r => setTimeout(r, 2000)); // ✅ Délai de 2s pour Blu-ray.com
|
||||
}
|
||||
|
||||
input.value = '';
|
||||
closeImportModal();
|
||||
const msg = totalSkp > 0 ? ` (${totalSkp} EAN ignoré(s) — introuvables UPC/TMDB)` : '';
|
||||
showSuccessModal(`${totalImp} édition(s) importée(s) (UPC + TMDB).${msg}`);
|
||||
const msg = totalSkp > 0 ? ` (${totalSkp} ignoré(s))` : '';
|
||||
showSuccessModal(`${totalImp} édition(s) importée(s).${msg}`);
|
||||
loadDashboardData();
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
|
||||
Reference in New Issue
Block a user