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