55 lines
1.6 KiB
JavaScript
55 lines
1.6 KiB
JavaScript
// ===============================
|
|
// main.js — Bootstrap dell'app
|
|
// ===============================
|
|
|
|
async function initGallery() {
|
|
console.log("=== INIT GALLERY ===");
|
|
|
|
// 1) CARICO CONFIG
|
|
console.log("[initGallery] Chiamo /config...");
|
|
let cfg;
|
|
try {
|
|
cfg = await fetch("/config").then(r => r.json());
|
|
} catch (e) {
|
|
console.error("❌ Errore caricamento /config:", e);
|
|
return;
|
|
}
|
|
|
|
console.log("[initGallery] /config RISPOSTA:", cfg);
|
|
|
|
// 2) PARAMETRI GLOBALI
|
|
window.PATH_FULL = cfg.pathFull;
|
|
const payload = parseJwt(localStorage.getItem("token"));
|
|
const user = payload?.name || "Common";
|
|
const refreshSeconds = cfg.galleryRefreshSeconds || 30;
|
|
|
|
console.log("[initGallery] Utente:", user);
|
|
console.log("[initGallery] refreshSeconds:", refreshSeconds);
|
|
|
|
// 3) CARICO CACHE LOCALE (se esiste)
|
|
const cached = loadLocalState();
|
|
if (cached.length > 0) {
|
|
console.log(`[initGallery] Cache locale caricata: ${cached.length} foto`);
|
|
refreshGallery();
|
|
}
|
|
|
|
// 4) SYNC INIZIALE
|
|
console.log("[initGallery] Avvio incrementalSync() iniziale...");
|
|
await incrementalSync();
|
|
console.log("[initGallery] incrementalSync() COMPLETATO");
|
|
|
|
// 5) POLLING DI SICUREZZA
|
|
if (refreshSeconds > 0) {
|
|
console.log(`[initGallery] Polling attivo ogni ${refreshSeconds} secondi...`);
|
|
|
|
setInterval(async () => {
|
|
console.log(">>> TIMER: incrementalSync()");
|
|
await incrementalSync();
|
|
}, refreshSeconds * 1000);
|
|
} else {
|
|
console.log("[initGallery] Polling disattivato");
|
|
}
|
|
}
|
|
|
|
// Bootstrap
|
|
window.addEventListener("DOMContentLoaded", initGallery);
|