fix(ui): bust browser localStorage and HTTP cache on update, render version server-side (v1.3.9)
This commit is contained in:
1 parent
1d09f06dc2
commit
c5eb849095
5 files changed
+89
-31
No files matched your search
+51
-9
@@ -5735,15 +5735,26 @@ async function checkSystemUpdate(notify = false) {
|
||||
const TWENTY_FOUR_HOURS = 24 * 60 * 60 * 1000;
|
||||
|
||||
// Si pas de clic explicite (notify === false), vérifier si un check a déjà été fait il y a moins de 24h
|
||||
const installedVer = (appState && appState.version) ? appState.version : (document.querySelector('meta[name="nexus-app-version"]')?.content || '');
|
||||
if (!notify) {
|
||||
const lastTs = parseInt(localStorage.getItem(STORAGE_KEY_TIME) || '0', 10);
|
||||
const cachedRaw = localStorage.getItem(STORAGE_KEY_DATA);
|
||||
if (lastTs && (Date.now() - lastTs < TWENTY_FOUR_HOURS) && cachedRaw) {
|
||||
try {
|
||||
const cached = JSON.parse(cachedRaw);
|
||||
applyUpdateUI(cached);
|
||||
return;
|
||||
} catch (_) {}
|
||||
// Si la version locale correspond et qu'on n'a pas un vieux flag "mise à jour dispo" vers la version déjà installée
|
||||
if (installedVer && (cached.current_version !== installedVer || (cached.has_update && cached.latest_version === installedVer))) {
|
||||
// Cache périmé suite à une mise à jour : on purge pour rafraîchir en direct
|
||||
localStorage.removeItem(STORAGE_KEY_TIME);
|
||||
localStorage.removeItem(STORAGE_KEY_DATA);
|
||||
} else {
|
||||
applyUpdateUI(cached);
|
||||
return;
|
||||
}
|
||||
} catch (_) {
|
||||
localStorage.removeItem(STORAGE_KEY_TIME);
|
||||
localStorage.removeItem(STORAGE_KEY_DATA);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
localStorage.removeItem(STORAGE_KEY_TIME);
|
||||
@@ -5759,7 +5770,7 @@ async function checkSystemUpdate(notify = false) {
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await fetch('/api.php?action=check_update');
|
||||
const res = await fetch('/api.php?action=check_update&_t=' + Date.now());
|
||||
const data = await res.json();
|
||||
|
||||
// Enregistrement du timestamp de vérification et des données en cache local (24h)
|
||||
@@ -5860,8 +5871,12 @@ async function runSystemUpdate() {
|
||||
|
||||
showToast("Mise à jour en cours d'exécution en arrière-plan...", 'info');
|
||||
|
||||
// Purge préventive du cache local
|
||||
localStorage.removeItem('nexus_update_last_check_ts');
|
||||
localStorage.removeItem('nexus_update_cached_data');
|
||||
|
||||
try {
|
||||
const res = await fetch('/api.php?action=run_update', {
|
||||
const res = await fetch('/api.php?action=run_update&_t=' + Date.now(), {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({})
|
||||
@@ -5869,14 +5884,41 @@ async function runSystemUpdate() {
|
||||
const data = await res.json();
|
||||
|
||||
if (data.success) {
|
||||
showToast(`NexusPBX a été mis à jour avec succès en v${data.new_version} ! Rechargement...`, 'success');
|
||||
const newVer = data.new_version || '';
|
||||
|
||||
// 1. Mettre à jour immédiatement le cache avec l'état à jour
|
||||
localStorage.setItem('nexus_update_last_check_ts', Date.now().toString());
|
||||
localStorage.setItem('nexus_update_cached_data', JSON.stringify({
|
||||
success: true,
|
||||
current_version: newVer,
|
||||
latest_version: newVer,
|
||||
has_update: false,
|
||||
changelog: [],
|
||||
release_date: ''
|
||||
}));
|
||||
|
||||
// 2. Mettre à jour visuellement les badges immédiatement
|
||||
const verTag = document.getElementById('system-version-tag');
|
||||
const appBadge = document.getElementById('app-version-badge');
|
||||
const headerUpdateBadge = document.getElementById('header-update-badge');
|
||||
const pingDot = document.getElementById('update-ping-dot');
|
||||
|
||||
if (verTag && newVer) verTag.textContent = `v${newVer}`;
|
||||
if (appBadge && newVer) appBadge.textContent = `v${newVer}`;
|
||||
if (headerUpdateBadge) headerUpdateBadge.style.display = 'none';
|
||||
if (btnRun) btnRun.style.display = 'none';
|
||||
if (pingDot) pingDot.classList.add('hidden');
|
||||
|
||||
showToast(`NexusPBX a été mis à jour avec succès en v${newVer} ! 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...`;
|
||||
statusText.textContent = `Mise à jour terminée avec succès (v${newVer}) ! Rechargement...`;
|
||||
}
|
||||
|
||||
// 3. Rechargement avec paramètre anti-cache pour forcer le navigateur à récupérer le nouveau DOM
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 2500);
|
||||
window.location.href = window.location.origin + window.location.pathname + '?_t=' + Date.now();
|
||||
}, 2000);
|
||||
} else {
|
||||
alert("Erreur lors de la mise à jour :\n\n" + (data.output || data.message));
|
||||
if (btnRun) {
|
||||
|
||||
Reference in new issue
Block a user