Actualiser js/admin.js
This commit is contained in:
+6
-107
@@ -510,9 +510,9 @@ function handleVideothequeUpload(input) {
|
|||||||
let processed = 0;
|
let processed = 0;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Traiter par lots de 5 pour éviter la surcharge
|
// Traiter par lots de 3 pour éviter la surcharge (notrecinema.com est plus lent)
|
||||||
for (let i = 0; i < items.length; i += 5) {
|
for (let i = 0; i < items.length; i += 3) {
|
||||||
const batch = items.slice(i, i + 5);
|
const batch = items.slice(i, i + 3);
|
||||||
|
|
||||||
const response = await fetch(`${API_URL}?action=import_batch`, {
|
const response = await fetch(`${API_URL}?action=import_batch`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@@ -536,114 +536,13 @@ function handleVideothequeUpload(input) {
|
|||||||
processed += batch.length;
|
processed += batch.length;
|
||||||
updateImportModal(processed, items.length);
|
updateImportModal(processed, items.length);
|
||||||
|
|
||||||
// Petit délai pour éviter le rate limiting
|
// Délai plus long pour notrecinema.com
|
||||||
await new Promise(resolve => setTimeout(resolve, 500));
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||||
}
|
}
|
||||||
|
|
||||||
input.value = '';
|
input.value = '';
|
||||||
closeImportModal();
|
closeImportModal();
|
||||||
showSuccessModal(`${items.length} édition(s) physique(s) importée(s) avec succès !`);
|
showSuccessModal(`${items.length} édition(s) physique(s) importée(s) avec succès depuis NotreCinema.com !`);
|
||||||
loadDashboardData();
|
|
||||||
|
|
||||||
} catch (err) {
|
|
||||||
console.error("Erreur d'importation : ", err);
|
|
||||||
closeImportModal();
|
|
||||||
alert("❌ Échec de l'import : " + err.message);
|
|
||||||
input.value = '';
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
reader.readAsText(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleVideothequeUpload(input) {
|
|
||||||
const file = input.files[0];
|
|
||||||
if (!file) return;
|
|
||||||
|
|
||||||
const reader = new FileReader();
|
|
||||||
reader.onload = async (e) => {
|
|
||||||
const text = e.target.result;
|
|
||||||
const parsedData = parseCSV(text);
|
|
||||||
|
|
||||||
if (parsedData.length === 0) {
|
|
||||||
alert("❌ Fichier CSV vide ou invalide.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const items = parsedData.map(row => {
|
|
||||||
const normalizedRow = normalizeVideothequeRow(row);
|
|
||||||
|
|
||||||
const title = normalizedRow['title'] || normalizedRow['Title'] || '';
|
|
||||||
if (!title) return null;
|
|
||||||
|
|
||||||
const ean = normalizedRow['ean'] || '';
|
|
||||||
const publishDate = normalizedRow['publish_date'] || normalizedRow['Publish_date'] || normalizedRow['publishdate'] || '';
|
|
||||||
const year = publishDate ? publishDate.split('-')[0] : (normalizedRow['year'] || normalizedRow['Year'] || '');
|
|
||||||
|
|
||||||
const description = normalizedRow['description'] || normalizedRow['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'] || '';
|
|
||||||
|
|
||||||
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
|
|
||||||
};
|
|
||||||
}).filter(item => item !== null);
|
|
||||||
|
|
||||||
if (items.length === 0) {
|
|
||||||
alert("❌ Aucun film valide trouvé dans le fichier CSV.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
showImportModal(items.length, 'videotheque');
|
|
||||||
let processed = 0;
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Traiter par lots de 5 pour éviter la surcharge
|
|
||||||
for (let i = 0; i < items.length; i += 5) {
|
|
||||||
const batch = items.slice(i, i + 5);
|
|
||||||
|
|
||||||
const response = await fetch(`${API_URL}?action=import_batch`, {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Authorization': localStorage.getItem('token'),
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
},
|
|
||||||
body: JSON.stringify({ type: 'videotheque', items: batch })
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(`Erreur serveur ${response.status}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = await response.json();
|
|
||||||
|
|
||||||
if (!data.success) {
|
|
||||||
throw new Error(data.error || "Erreur inconnue");
|
|
||||||
}
|
|
||||||
|
|
||||||
processed += batch.length;
|
|
||||||
updateImportModal(processed, items.length);
|
|
||||||
|
|
||||||
// Petit délai pour éviter de surcharger le serveur
|
|
||||||
await new Promise(resolve => setTimeout(resolve, 500));
|
|
||||||
}
|
|
||||||
|
|
||||||
input.value = '';
|
|
||||||
closeImportModal();
|
|
||||||
showSuccessModal(`${items.length} édition(s) physique(s) importée(s) avec succès !`);
|
|
||||||
loadDashboardData();
|
loadDashboardData();
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
Reference in New Issue
Block a user