feat(ota): add 1-click update UI & API with changelog display
This commit is contained in:
1 parent
2376e7eebb
commit
5d60e66518
3 files changed
+230
-1
No files matched your search
@@ -144,6 +144,7 @@ async function loadState() {
|
||||
}
|
||||
renderAll();
|
||||
loadBackups();
|
||||
checkSystemUpdate(false);
|
||||
startMetricsPolling();
|
||||
} catch (err) {
|
||||
if (err.message !== 'Session expirée') {
|
||||
@@ -5636,3 +5637,132 @@ function copyYealinkUrl(inputId, btn) {
|
||||
showToast("Sélectionnez l'URL et appuyez sur Ctrl+C.", 'info');
|
||||
});
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// GESTIONNAIRE DE MISES À JOUR DU SYSTÈME NEXUSPBX (OTA)
|
||||
// =========================================================================
|
||||
async function checkSystemUpdate(notify = false) {
|
||||
const btnCheck = document.getElementById('btn-check-update');
|
||||
const btnRun = document.getElementById('btn-run-update');
|
||||
const statusText = document.getElementById('update-status-text');
|
||||
const lastChecked = document.getElementById('update-last-checked');
|
||||
const changelogContainer = document.getElementById('update-changelog-container');
|
||||
const changelogList = document.getElementById('update-changelog-list');
|
||||
const pingDot = document.getElementById('update-ping');
|
||||
const verTag = document.getElementById('system-version-tag');
|
||||
const appBadge = document.getElementById('app-version-badge');
|
||||
|
||||
if (btnCheck) {
|
||||
btnCheck.disabled = true;
|
||||
btnCheck.classList.add('opacity-50');
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await fetch('/api.php?action=check_update');
|
||||
const data = await res.json();
|
||||
|
||||
if (lastChecked) {
|
||||
const now = new Date();
|
||||
lastChecked.textContent = `Dernière vérification : ${now.toLocaleTimeString()}`;
|
||||
}
|
||||
|
||||
if (verTag && data.current_version) {
|
||||
verTag.textContent = `v${data.current_version}`;
|
||||
}
|
||||
if (appBadge && data.current_version) {
|
||||
appBadge.textContent = `v${data.current_version}`;
|
||||
}
|
||||
|
||||
if (data.has_update) {
|
||||
if (statusText) {
|
||||
statusText.className = 'text-amber-400 font-bold';
|
||||
statusText.innerHTML = `🚀 Nouvelle version disponible : <span class="underline">v${escapeHtml(data.latest_version)}</span> !`;
|
||||
}
|
||||
if (btnRun) {
|
||||
btnRun.style.display = 'inline-flex';
|
||||
btnRun.innerHTML = `<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"/></svg><span>Mettre à jour vers v${escapeHtml(data.latest_version)} (1-Clic)</span>`;
|
||||
}
|
||||
if (pingDot) pingDot.classList.remove('hidden');
|
||||
|
||||
if (changelogList && Array.isArray(data.changelog) && data.changelog.length > 0) {
|
||||
changelogList.innerHTML = data.changelog.map(item => `<li>${escapeHtml(item)}</li>`).join('');
|
||||
if (changelogContainer) changelogContainer.classList.remove('hidden');
|
||||
}
|
||||
if (notify) {
|
||||
showToast(`Nouvelle version NexusPBX v${data.latest_version} disponible !`, 'info');
|
||||
}
|
||||
} else {
|
||||
if (statusText) {
|
||||
statusText.className = 'text-emerald-400 font-bold';
|
||||
statusText.textContent = `Votre PBX est à jour avec la dernière version officielle (v${data.current_version}).`;
|
||||
}
|
||||
if (btnRun) btnRun.style.display = 'none';
|
||||
if (pingDot) pingDot.classList.add('hidden');
|
||||
if (changelogContainer) changelogContainer.classList.add('hidden');
|
||||
if (notify) {
|
||||
showToast("Votre système NexusPBX est parfaitement à jour !", 'success');
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
if (notify) {
|
||||
showToast("Erreur lors de la vérification des mises à jour : " + e.message, 'error');
|
||||
}
|
||||
} finally {
|
||||
if (btnCheck) {
|
||||
btnCheck.disabled = false;
|
||||
btnCheck.classList.remove('opacity-50');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function runSystemUpdate() {
|
||||
if (!confirm("Voulez-vous lancer la mise à jour de NexusPBX ?\n\nUne sauvegarde préventive automatique de vos configurations et de votre base de données sera créée.")) {
|
||||
return;
|
||||
}
|
||||
|
||||
const btnRun = document.getElementById('btn-run-update');
|
||||
const statusText = document.getElementById('update-status-text');
|
||||
|
||||
if (btnRun) {
|
||||
btnRun.disabled = true;
|
||||
btnRun.innerHTML = '<span class="animate-spin mr-1.5">↻</span> Mise à jour en cours...';
|
||||
}
|
||||
if (statusText) {
|
||||
statusText.className = 'text-cyan-300 font-bold';
|
||||
statusText.textContent = 'Mise à jour en cours : sauvegarde, git pull, migrations SQLite et rechargement des services...';
|
||||
}
|
||||
|
||||
showToast("Mise à jour en cours d'exécution en arrière-plan...", 'info');
|
||||
|
||||
try {
|
||||
const res = await fetch('/api.php?action=run_update', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({})
|
||||
});
|
||||
const data = await res.json();
|
||||
|
||||
if (data.success) {
|
||||
showToast(`NexusPBX a été mis à jour avec succès en v${data.new_version} ! Rechargement...`, 'success');
|
||||
if (statusText) {
|
||||
statusText.className = 'text-emerald-400 font-bold';
|
||||
statusText.textContent = `Mise à jour terminée avec succès (v${data.new_version}) ! Rechargement de la page...`;
|
||||
}
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 2500);
|
||||
} else {
|
||||
alert("Erreur lors de la mise à jour :\n\n" + (data.output || data.message));
|
||||
if (btnRun) {
|
||||
btnRun.disabled = false;
|
||||
btnRun.innerHTML = 'Réessayer la mise à jour';
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
alert("Erreur réseau lors de la mise à jour : " + e.message);
|
||||
if (btnRun) {
|
||||
btnRun.disabled = false;
|
||||
btnRun.innerHTML = 'Réessayer la mise à jour';
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user