diff --git a/js/admin.js b/js/admin.js index a710de8..13f5510 100644 --- a/js/admin.js +++ b/js/admin.js @@ -100,7 +100,7 @@ function initEventListeners() { async function loadDashboardData() { try { const res = await fetch(`${API_URL}?action=get_films`, { cache: 'no-store' }); - const data = await res.json(); // Reçoit {critiques: [...], videotheque: [...]} + const data = await res.json(); dataStore = data; const secRes = await fetch(`${API_URL}?action=check_security_status`, { cache: 'no-store' }); @@ -121,7 +121,6 @@ function renderAdminTable() { const currentSearch = searchInput ? searchInput.value.toLowerCase() : ''; const physicalFilter = document.getElementById('admin-physical-checkbox'); - // On prend directement la bonne liste dans dataStore let filtered = dataStore[currentAdminTab] || []; if (physicalFilter && physicalFilter.checked && currentAdminTab === 'critique') { @@ -348,8 +347,6 @@ async function openConfigModal() { const data = await res.json(); const tmdbIn = document.getElementById('tmdb-key-input'); if (tmdbIn) tmdbIn.placeholder = data.tmdb_api_key ? '✅ Clé TMDB configurée' : 'Entrez votre clé TMDB'; - const upcIn = document.getElementById('upcmdb-key-input'); - if (upcIn) upcIn.placeholder = data.upcmdb_api_key ? '✅ Clé UPCMDB configurée' : 'Clé gratuite sur upcmdb.com'; } catch(e) { console.error(e); } } @@ -415,14 +412,10 @@ async function handleCritiqueUpload(input) { loadDashboardData(); } -// ✅ MODIFIÉ : Ne retourne QUE l'EAN function normalizeVideothequeRow(row) { let ean = row['ean_isbn13'] || row['EAN'] || row['ean'] || row['Barcode'] || row['UPC'] || row['upc_isbn10'] || ''; ean = String(ean).replace(/[^0-9]/g, ''); - - // Si pas d'EAN valide, on ignore la ligne if (!ean || ean.length < 8) return null; - return { ean: ean }; } @@ -435,7 +428,6 @@ function handleVideothequeUpload(input) { const parsed = parseCSV(text); if (!parsed.length) { alert("❌ CSV vide."); return; } - // ✅ Ne garde que les EANs valides const items = parsed.map(row => normalizeVideothequeRow(row)).filter(Boolean); if (!items.length) { alert("❌ Aucun code EAN valide trouvé dans le CSV."); return; } @@ -443,7 +435,6 @@ function handleVideothequeUpload(input) { let processed = 0, totalImp = 0, totalSkp = 0; try { - // Envoi par lot de 1 pour respecter le throttle de Blu-ray.com for (let i = 0; i < items.length; i += 1) { const batch = items.slice(i, i + 1); const res = await fetch(`${API_URL}?action=import_batch`, { @@ -460,7 +451,7 @@ function handleVideothequeUpload(input) { totalSkp += data.skipped || 0; processed += batch.length; updateImportModal(processed, items.length); - await new Promise(r => setTimeout(r, 300)); // Petit délai réseau + await new Promise(r => setTimeout(r, 300)); } input.value = ''; @@ -496,11 +487,9 @@ function closeImportModal() { document.getElementById('import-progress-modal').c async function saveConfigKeys() { const tmdb = document.getElementById('tmdb-key-input').value.trim(); - const upcmdb = document.getElementById('upcmdb-key-input').value.trim(); try { if (tmdb) await fetch(`${API_URL}?action=save_config`, { method:'POST', headers:{'Authorization':localStorage.getItem('token'),'Content-Type':'application/json'}, body:JSON.stringify({key_name:'tmdb_api_key',key_value:tmdb}) }); - if (upcmdb) await fetch(`${API_URL}?action=save_config`, { method:'POST', headers:{'Authorization':localStorage.getItem('token'),'Content-Type':'application/json'}, body:JSON.stringify({key_name:'upcmdb_api_key',key_value:upcmdb}) }); - alert('✅ Clés sauvegardées !'); + alert('✅ Clé sauvegardée !'); closeConfigModal(); } catch(e) { alert('Erreur serveur.'); } } @@ -523,7 +512,7 @@ function updateImportInterface() { const desc = document.getElementById('import-desc'); if (currentAdminTab === 'videotheque') { title.innerHTML = 'Importer ma Vidéothèque'; - desc.textContent = 'Importez votre CSV. Le système extraira uniquement les codes EAN pour récupérer les jaquettes HD et métadonnées via Blu-ray.com, MovieCovers et TMDB.'; + desc.textContent = 'Importez votre CSV. Le système extraira uniquement les codes EAN pour récupérer les jaquettes HD et métadonnées via la FNAC, Blu-ray.com, MovieCovers et TMDB.'; } else { title.innerHTML = 'Importer Critiques & Notes'; desc.textContent = 'Importez vos fichiers CSV de notes et critiques (ex: Letterboxd).'; @@ -542,29 +531,17 @@ function closeSuccessModal() { if (modalEl) modalEl.classList.remove('open'); } -// 1. Ouvre le choix entre Manuel ou EAN -function openAddMethodModal() { - document.getElementById('add-choice-modal').classList.add('open'); -} - -// 2. Ouvre la saisie EAN et ferme le choix +function openAddMethodModal() { document.getElementById('add-choice-modal').classList.add('open'); } function openEanModal() { document.getElementById('add-choice-modal').classList.remove('open'); document.getElementById('ean-input-modal').classList.add('open'); } - -// 3. Ouvre votre formulaire manuel existant (Adaptez le nom selon votre code actuel) function openManualForm() { document.getElementById('add-choice-modal').classList.remove('open'); - // On appelle ici l'ancienne fonction qui ouvre le formulaire manuel openAddModal(); } +function closeEanModal() { document.getElementById('ean-input-modal').classList.remove('open'); } -function closeEanModal() { - document.getElementById('ean-input-modal').classList.remove('open'); -} - -// 4. Soumission de l'EAN async function submitEan() { const ean = document.getElementById('ean-input').value.trim(); if (!ean) return;