diff --git a/js/admin.js b/js/admin.js index e7c288e..704db03 100644 --- a/js/admin.js +++ b/js/admin.js @@ -419,41 +419,33 @@ async function handleCritiqueUpload(input) { loadDashboardData(); } +// 1. Normalisation des colonnes du CSV function normalizeVideothequeRow(row) { - // Ajout de 'Barcode' et 'UPC' / On ne retire plus les zéros de tête + // Récupération stricte de l'EAN sans supprimer les zéros du début let ean = row['ean_isbn13'] || row['EAN'] || row['ean'] || row['Barcode'] || row['UPC'] || ''; - if (ean !== '') { - ean = String(ean).replace(/[^0-9]/g, ''); - } - + if (ean !== '') ean = String(ean).replace(/[^0-9]/g, ''); // Garde que les chiffres + let length = row['length'] || row['Length'] || row['Runtime'] || row['runtime'] || ''; - if (length !== '' && length !== null) { - const l = parseFloat(length); - length = isNaN(l) ? '' : String(Math.round(l)); - } + if (length !== '') length = String(Math.round(parseFloat(length))); let discs = row['number_of_discs'] || row['Number_of_discs'] || row['Discs'] || row['discs'] || ''; - if (discs === '' || discs === null || isNaN(parseFloat(discs))) { - discs = 1; - } else { - discs = Math.round(parseFloat(discs)); - } + discs = (!discs || isNaN(parseFloat(discs))) ? 1 : Math.round(parseFloat(discs)); let aspect = row['aspect_ratio'] || row['Aspect_ratio'] || row['AspectRatio'] || row['Aspect Ratio'] || ''; - let actors = row['creators'] || row['Actors'] || row['actors'] || row['Cast'] || row['cast'] || ''; - let publisher = row['publisher'] || row['Publisher'] || row['Studio'] || row['studio'] || row['Label'] || row['label'] || ''; - let director = row['first_name'] && row['last_name'] ? (row['first_name'] + ' ' + row['last_name']).trim() : (row['Director'] || row['director'] || ''); + let publisher = row['publisher'] || row['Publisher'] || row['Studio'] || row['studio'] || row['Label'] || ''; let format = row['format'] || row['Format'] || row['Media'] || row['media'] || ''; + + // Certains CSV ont déjà les acteurs, on les garde au cas où + let actors = row['creators'] || row['Actors'] || row['actors'] || row['Cast'] || ''; return Object.assign({}, row, { ean: ean, length: length, number_of_discs: discs, aspect_ratio: aspect, - actors: actors, publisher: publisher, - director: director, - format: format // Le format est maintenant géré + format: format, + actors: actors }); } @@ -471,37 +463,27 @@ function handleVideothequeUpload(input) { return; } + // 2. Construction de l'objet pour l'API const items = parsedData.map(row => { const normalizedRow = normalizeVideothequeRow(row); - const title = row['title'] || row['Title'] || ''; if (!title) return null; - const ean = normalizedRow['ean'] || ''; const publishDate = row['publish_date'] || row['Publish_date'] || row['publishdate'] || ''; const year = publishDate ? publishDate.split('-')[0] : (row['year'] || row['Year'] || ''); - const description = row['description'] || row['Description'] || ''; - const length = normalizedRow['length'] || ''; - const discs = normalizedRow['number_of_discs'] || 1; - const aspect = normalizedRow['aspect_ratio'] || ''; - const actors = normalizedRow['actors'] || ''; - const publisher = normalizedRow['publisher'] || ''; - const director = normalizedRow['director'] || ''; - const format = normalizedRow['format'] || ''; // 👈 LIGNE À AJOUTER - return { title: title.trim(), - ean: ean, year: year, - description: description.trim(), - length: length, - number_of_discs: discs, - aspect_ratio: aspect, - actors: actors, - publisher: publisher, - director: director, - format: format // 👈 LIGNE À AJOUTER + description: (row['description'] || row['Description'] || '').trim(), + ean: normalizedRow['ean'], + length: normalizedRow['length'], + number_of_discs: normalizedRow['number_of_discs'], + aspect_ratio: normalizedRow['aspect_ratio'], + publisher: normalizedRow['publisher'], + format: normalizedRow['format'], + actors: normalizedRow['actors'], + director: row['director'] || row['Director'] || '' }; }).filter(item => item !== null);