feat: Настройки › Автообновление - clients compare their version with the server's every N and update themselves; the server looks at GitLab every N and, when a newer release is out, offers it to an administrator at login (after the PIN) with «Обновить» and «Отказаться»; the words of a made picture's result are the model's only

This commit is contained in:
redtea committed 2026-10-18 12:33:24 +03:00
1 parent 916a49958b
commit 3d2f886f04
22 files changed
+1074 -7

No files matched your search

+47
View File
@@ -0,0 +1,47 @@
// A new release of the server: an administrator is offered it when they come
// in - after the PIN, or at once when there is none - once for each tab. The
// window says the versions and has «Обновить» and «Отказаться»; a refusal is
// kept for that release (a still newer one asks again). Only when the server
// is set to look for releases (Настройки › Автообновление).
(function () {
'use strict';
var root = document.documentElement;
var SHOWN = 'lpra.upd.shown';
// The PIN lock hides the page until it is unlocked.
function whenUnlocked(fn) {
if (!root.classList.contains('pin-wait')) { fn(); return; }
var mo = new MutationObserver(function () {
if (!root.classList.contains('pin-wait')) { mo.disconnect(); fn(); }
});
mo.observe(root, {attributes: true, attributeFilter: ['class']});
}
function toast(text, bad) {
if (window.FileViews && FileViews.toast) FileViews.toast(text, bad);
}
function post(url, body) {
return fetch(url, {method: 'POST', headers: {'Content-Type': 'application/json'}, credentials: 'same-origin',
body: JSON.stringify(body || {})}).then(function (r) { return r.json(); })
.catch(function () { return {ok: false, error: 'нет связи с сервером'}; });
}
function offer() {
try { if (sessionStorage.getItem(SHOWN) === '1') return; } catch (e) { /* offered again */ }
fetch('/api/panel/update/offer', {cache: 'no-store', credentials: 'same-origin'})
.then(function (r) { return r.ok ? r.json() : {}; })
.then(function (d) {
if (!d.offer || !window.UI) return;
try { sessionStorage.setItem(SHOWN, '1'); } catch (e) { /* not remembered */ }
UI.confirm('Вышла новая версия LPRA {chip}\nОбновить сервер сейчас? Панель будет недоступна около минуты.',
{ok: 'Обновить', cancel: 'Отказаться', chip: d.current + ' → ' + d.latest}).then(function (yes) {
if (!yes) { post('/api/panel/update/decline', {version: d.latest}); return; }
post('/api/panel/update/run').then(function (r) {
if (r.ok) toast('Обновление до ' + r.latest + ' запущено: сервер перезапустится в течение минуты - потом обновите страницу');
else toast(r.error || 'обновить не получилось', true);
});
});
})
.catch(function () { /* no offer */ });
}
whenUnlocked(offer);
})();