Actualiser js/admin.js

This commit is contained in:
2026-06-30 14:59:03 +02:00
parent 43a1f39615
commit e0958ab4fb
+11 -5
View File
@@ -20,6 +20,11 @@ function getStarsHTML(rating) {
function parseCSV(text) {
if (text.charCodeAt(0) === 0xFEFF) text = text.slice(1);
// ✅ NOUVEAU : Détection automatique du séparateur le plus utilisé sur la première ligne
const firstLine = text.split(/[\r\n]+/)[0] || '';
const sep = (firstLine.match(/;/g) || []).length > (firstLine.match(/,/g) || []).length ? ';' : ',';
const rows = [];
let col = '', row = [], inQuotes = false;
for (let i = 0; i < text.length; i++) {
@@ -31,7 +36,7 @@ function parseCSV(text) {
} else col += c;
} else {
if (c === '"') inQuotes = true;
else if (c === ',') { row.push(col); col = ''; }
else if (c === sep) { row.push(col); col = ''; } // ✅ On utilise le séparateur détecté
else if (c === '\n' || c === '\r') {
if (c === '\r' && text[i+1] === '\n') i++;
row.push(col); col = '';
@@ -416,14 +421,15 @@ 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
let title = row['title'] ? String(row['title']).trim() : '';
// ✅ Tolérance sur le nom de la colonne
let title = row['Title'] || row['title'] || row['Titre'] || row['titre'] || row['Name'] || row['name'] || '';
title = String(title).trim();
if (!ean && !title) return null;
return {
ean: ean,
title: title // ✅ Titre envoyé au backend
title: title
};
}
@@ -461,7 +467,7 @@ function handleVideothequeUpload(input) {
totalSkp += data.skipped || 0;
processed += batch.length;
updateImportModal(processed, items.length);
await new Promise(r => setTimeout(r, 2000)); // ✅ Délai de 2s pour Blu-ray.com
await new Promise(r => setTimeout(r, 5500)); // ✅ Délai de 5.5s pour éviter le blocage
}
input.value = '';