Actualiser js/admin.js
This commit is contained in:
+22
-40
@@ -419,41 +419,33 @@ async function handleCritiqueUpload(input) {
|
|||||||
loadDashboardData();
|
loadDashboardData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 1. Normalisation des colonnes du CSV
|
||||||
function normalizeVideothequeRow(row) {
|
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'] || '';
|
let ean = row['ean_isbn13'] || row['EAN'] || row['ean'] || row['Barcode'] || row['UPC'] || '';
|
||||||
if (ean !== '') {
|
if (ean !== '') ean = String(ean).replace(/[^0-9]/g, ''); // Garde que les chiffres
|
||||||
ean = String(ean).replace(/[^0-9]/g, '');
|
|
||||||
}
|
|
||||||
|
|
||||||
let length = row['length'] || row['Length'] || row['Runtime'] || row['runtime'] || '';
|
let length = row['length'] || row['Length'] || row['Runtime'] || row['runtime'] || '';
|
||||||
if (length !== '' && length !== null) {
|
if (length !== '') length = String(Math.round(parseFloat(length)));
|
||||||
const l = parseFloat(length);
|
|
||||||
length = isNaN(l) ? '' : String(Math.round(l));
|
|
||||||
}
|
|
||||||
|
|
||||||
let discs = row['number_of_discs'] || row['Number_of_discs'] || row['Discs'] || row['discs'] || '';
|
let discs = row['number_of_discs'] || row['Number_of_discs'] || row['Discs'] || row['discs'] || '';
|
||||||
if (discs === '' || discs === null || isNaN(parseFloat(discs))) {
|
discs = (!discs || isNaN(parseFloat(discs))) ? 1 : Math.round(parseFloat(discs));
|
||||||
discs = 1;
|
|
||||||
} else {
|
|
||||||
discs = Math.round(parseFloat(discs));
|
|
||||||
}
|
|
||||||
|
|
||||||
let aspect = row['aspect_ratio'] || row['Aspect_ratio'] || row['AspectRatio'] || row['Aspect Ratio'] || '';
|
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'] || '';
|
||||||
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 format = row['format'] || row['Format'] || row['Media'] || row['media'] || '';
|
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, {
|
return Object.assign({}, row, {
|
||||||
ean: ean,
|
ean: ean,
|
||||||
length: length,
|
length: length,
|
||||||
number_of_discs: discs,
|
number_of_discs: discs,
|
||||||
aspect_ratio: aspect,
|
aspect_ratio: aspect,
|
||||||
actors: actors,
|
|
||||||
publisher: publisher,
|
publisher: publisher,
|
||||||
director: director,
|
format: format,
|
||||||
format: format // Le format est maintenant géré
|
actors: actors
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -471,37 +463,27 @@ function handleVideothequeUpload(input) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 2. Construction de l'objet pour l'API
|
||||||
const items = parsedData.map(row => {
|
const items = parsedData.map(row => {
|
||||||
const normalizedRow = normalizeVideothequeRow(row);
|
const normalizedRow = normalizeVideothequeRow(row);
|
||||||
|
|
||||||
const title = row['title'] || row['Title'] || '';
|
const title = row['title'] || row['Title'] || '';
|
||||||
if (!title) return null;
|
if (!title) return null;
|
||||||
|
|
||||||
const ean = normalizedRow['ean'] || '';
|
|
||||||
const publishDate = row['publish_date'] || row['Publish_date'] || row['publishdate'] || '';
|
const publishDate = row['publish_date'] || row['Publish_date'] || row['publishdate'] || '';
|
||||||
const year = publishDate ? publishDate.split('-')[0] : (row['year'] || row['Year'] || '');
|
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 {
|
return {
|
||||||
title: title.trim(),
|
title: title.trim(),
|
||||||
ean: ean,
|
|
||||||
year: year,
|
year: year,
|
||||||
description: description.trim(),
|
description: (row['description'] || row['Description'] || '').trim(),
|
||||||
length: length,
|
ean: normalizedRow['ean'],
|
||||||
number_of_discs: discs,
|
length: normalizedRow['length'],
|
||||||
aspect_ratio: aspect,
|
number_of_discs: normalizedRow['number_of_discs'],
|
||||||
actors: actors,
|
aspect_ratio: normalizedRow['aspect_ratio'],
|
||||||
publisher: publisher,
|
publisher: normalizedRow['publisher'],
|
||||||
director: director,
|
format: normalizedRow['format'],
|
||||||
format: format // 👈 LIGNE À AJOUTER
|
actors: normalizedRow['actors'],
|
||||||
|
director: row['director'] || row['Director'] || ''
|
||||||
};
|
};
|
||||||
}).filter(item => item !== null);
|
}).filter(item => item !== null);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user