Actualiser js/admin.js
This commit is contained in:
+7
-13
@@ -447,23 +447,17 @@ function handleVideothequeUpload(input) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// ✅ Lots de 1 seul pour éviter le blocage Blu-ray.com
|
// ✅ Lots de 1 seul pour éviter le blocage Blu-ray.com
|
||||||
for (let i = 0; i < items.length; i += 1) {
|
const batchSize = 5; // ou 10 selon la puissance du serveur
|
||||||
const batch = items.slice(i, i + 1);
|
for (let i = 0; i < items.length; i += batchSize) {
|
||||||
|
const batch = items.slice(i, i + batchSize);
|
||||||
const res = await fetch(`${API_URL}?action=import_batch`, {
|
const res = await fetch(`${API_URL}?action=import_batch`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Authorization': localStorage.getItem('token'), 'Content-Type': 'application/json' },
|
headers: { 'Authorization': localStorage.getItem('token'), 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({ type: 'videotheque', items: batch })
|
body: JSON.stringify({ type: 'videotheque', items: batch })
|
||||||
});
|
});
|
||||||
|
// ... traitement de la réponse
|
||||||
if (!res.ok) throw new Error(`Erreur HTTP ${res.status}`);
|
// Petit délai optionnel (100 ms) pour éviter de saturer le serveur
|
||||||
const data = await res.json();
|
await new Promise(r => setTimeout(r, 100));
|
||||||
if (!data.success) throw new Error(data.error || "Échec API");
|
|
||||||
|
|
||||||
totalImp += data.imported || 0;
|
|
||||||
totalSkp += data.skipped || 0;
|
|
||||||
processed += batch.length;
|
|
||||||
updateImportModal(processed, items.length);
|
|
||||||
await new Promise(r => setTimeout(r, 500)); // Délai de sécurité
|
|
||||||
}
|
}
|
||||||
|
|
||||||
input.value = '';
|
input.value = '';
|
||||||
@@ -479,7 +473,7 @@ function handleVideothequeUpload(input) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
reader.readAsText(file);
|
reader.readAsText(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
function showImportModal(total, type) {
|
function showImportModal(total, type) {
|
||||||
document.getElementById('import-modal-title').innerHTML = type === 'critique' ? '<i class="ti ti-star"></i> Import Critiques' : '<i class="ti ti-video"></i> Import Vidéothèque';
|
document.getElementById('import-modal-title').innerHTML = type === 'critique' ? '<i class="ti ti-star"></i> Import Critiques' : '<i class="ti ti-video"></i> Import Vidéothèque';
|
||||||
|
|||||||
Reference in New Issue
Block a user