Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
43e0e77790 | ||
|
|
1bb1c2cc99 |
+11
-15
@@ -360,8 +360,16 @@ def save_config_file():
|
||||
|
||||
# --- AGGIORNAMENTO SERVER OTA ---
|
||||
|
||||
def background_gitea_check():
|
||||
global GLOBAL_SERVER_UPDATE_AVAILABLE, LAST_GITEA_CHECK_TIME
|
||||
@api_bp.route('/api/server_update/check', methods=['GET'])
|
||||
def get_server_update_status():
|
||||
global LAST_GITEA_CHECK_TIME, GLOBAL_SERVER_UPDATE_AVAILABLE
|
||||
auth = get_auth()
|
||||
if not auth or auth['role'] != 'admin':
|
||||
return err("Non autorizzato", 403)
|
||||
|
||||
# Eseguiamo il controllo sincrono (ci mette max 1-2 secondi) ogni ora
|
||||
# In questo modo il frontend riceve subito il risultato VERO, non quello della cache precedente
|
||||
if time.time() - LAST_GITEA_CHECK_TIME > 3600:
|
||||
try:
|
||||
subprocess.run(['git', 'fetch'], timeout=10, cwd=BASE_DIR)
|
||||
local_hash = subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=BASE_DIR).decode('utf-8').strip()
|
||||
@@ -369,19 +377,7 @@ def background_gitea_check():
|
||||
GLOBAL_SERVER_UPDATE_AVAILABLE = (local_hash != remote_hash)
|
||||
LAST_GITEA_CHECK_TIME = time.time()
|
||||
except Exception as e:
|
||||
logger.error(f"Errore controllo Gitea in background: {e}")
|
||||
|
||||
@api_bp.route('/api/server_update/check', methods=['GET'])
|
||||
def get_server_update_status():
|
||||
global LAST_GITEA_CHECK_TIME
|
||||
auth = get_auth()
|
||||
if not auth or auth['role'] != 'admin':
|
||||
return err("Non autorizzato", 403)
|
||||
|
||||
# Se è passata più di un'ora (3600 secondi) dall'ultimo controllo, avvia il thread
|
||||
if time.time() - LAST_GITEA_CHECK_TIME > 3600:
|
||||
import threading
|
||||
threading.Thread(target=background_gitea_check, daemon=True).start()
|
||||
logger.error(f"Errore controllo Gitea: {e}")
|
||||
|
||||
return jsonify({"success": True, "update_available": GLOBAL_SERVER_UPDATE_AVAILABLE})
|
||||
|
||||
|
||||
+17
-11
@@ -789,7 +789,22 @@ async function refreshStates() {
|
||||
cardDiv.dataset.status = isOnline ? 'online' : 'offline';
|
||||
renderSeen(c, data, isOnline);
|
||||
|
||||
const warns = (data.warnings && data.warnings[c.id.toLowerCase()]) || [];
|
||||
let warns = (data.warnings && data.warnings[c.id.toLowerCase()]) ? [...data.warnings[c.id.toLowerCase()]] : [];
|
||||
|
||||
let hasOfflineService = false;
|
||||
if (healthObj && healthObj.processes) {
|
||||
for (const [svcName, svcStatus] of Object.entries(healthObj.processes)) {
|
||||
let s = svcStatus.toLowerCase();
|
||||
if (s !== 'online' && s !== 'standby') {
|
||||
hasOfflineService = true;
|
||||
warns.push(`SVC KO: ${svcName.toUpperCase()}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!latestStatesData.warnings) latestStatesData.warnings = {};
|
||||
latestStatesData.warnings[c.id.toLowerCase()] = warns;
|
||||
|
||||
cardDiv.dataset.hasWarn = (warns.length > 0) ? 'true' : 'false';
|
||||
const diagDiv = document.getElementById(`diag-warn-${c.id}`);
|
||||
if (diagDiv) {
|
||||
@@ -936,16 +951,7 @@ async function refreshStates() {
|
||||
if (healthContainer) healthContainer.style.display = 'none';
|
||||
}
|
||||
|
||||
// Logica tollerante per i Gateway in standby (spenti dalla UI)
|
||||
let hasOfflineService = false;
|
||||
if (healthObj && healthObj.processes) {
|
||||
for (const [svcName, svcStatus] of Object.entries(healthObj.processes)) {
|
||||
let s = svcStatus.toLowerCase();
|
||||
if (s !== 'online' && s !== 'standby') {
|
||||
hasOfflineService = true; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Logica tollerante per i Gateway in standby (hasOfflineService calcolato in alto)
|
||||
const warnBadge = document.getElementById(`svc-warn-${c.id}`); const btnSvc = document.getElementById(`btn-svc-${c.id}`);
|
||||
if (warnBadge) warnBadge.style.display = hasOfflineService ? 'block' : 'none';
|
||||
if (btnSvc) { if (hasOfflineService) { btnSvc.style.borderColor = 'var(--danger)'; btnSvc.style.color = 'var(--danger)'; } else { btnSvc.style.borderColor = 'var(--text-main)'; btnSvc.style.color = 'var(--text-main)'; } }
|
||||
|
||||
Reference in New Issue
Block a user