Compare commits

...
7 changed files with 166 additions and 16 deletions

No files matched your search

+2
View File
@@ -73,6 +73,8 @@ logs/
# Database # Database
*.db *.db
*.db-shm
*.db-wal
*.sqlite3 *.sqlite3
instance/ instance/
+1 -1
View File
@@ -1 +1 @@
0.7.6-experimental 0.7.9-experimental
+1 -1
View File
@@ -199,7 +199,7 @@ class PlayerService:
def get_player_detail(self, player_id): def get_player_detail(self, player_id):
player = self.db.query(""" player = self.db.query("""
SELECT a.*, a.transform::text as transform_text, SELECT a.*, a.transform::text as transform_text,
ea.id as account_id, ea.user as account_email, ea.platform_id, ea.id as account_id, ea.user as account_email, acc.platform_id,
acc.funcom_id, acc.funcom_id,
COALESCE(NULLIF(ps.character_name, ''), NULLIF(acc.funcom_id, ''), 'Character ' || a.id::text) as player_name, COALESCE(NULLIF(ps.character_name, ''), NULLIF(acc.funcom_id, ''), 'Character ' || a.id::text) as player_name,
ps.online_status::text as online_status, ps.online_status::text as online_status,
+40 -10
View File
@@ -99,6 +99,7 @@ class UpdateService:
self._channel = channel_of(self._current_version) self._channel = channel_of(self._current_version)
self._latest = None # {'version', 'tag', 'notes', 'zipball_url'} self._latest = None # {'version', 'tag', 'notes', 'zipball_url'}
self._other_latest = None self._other_latest = None
self._releases = {'experimental': [], 'stable': []} # per-channel lists, newest first
self._last_check = 0 self._last_check = 0
self._check_interval = 1800 # 30 minutes self._check_interval = 1800 # 30 minutes
self._update_in_progress = False self._update_in_progress = False
@@ -226,9 +227,13 @@ class UpdateService:
return '' return ''
@staticmethod @staticmethod
def _pick_latest(releases, channel): def _collect_channel(releases, channel):
"""Newest release for a channel. Returns entry dict or None.""" """All releases for a channel, newest first.
best = None
Each entry is {'version', 'tag', 'notes', 'zipball_url'}.
Drafts, non-matching tags and unparsable versions are skipped.
"""
found = []
for release in releases: for release in releases:
if not isinstance(release, dict) or release.get('draft'): if not isinstance(release, dict) or release.get('draft'):
continue continue
@@ -239,23 +244,34 @@ class UpdateService:
if parsed is None: if parsed is None:
continue continue
version = tag[1:] if tag.lower().startswith('v') else tag version = tag[1:] if tag.lower().startswith('v') else tag
entry = { found.append({
'version': version, 'version': version,
'tag': tag, 'tag': tag,
'notes': str(release.get('body') or ''), 'notes': str(release.get('body') or ''),
'zipball_url': str(release.get('zipball_url') or ''), 'zipball_url': str(release.get('zipball_url') or ''),
} })
if best is None or compare_versions(entry['version'], best['version']) > 0: found.sort(key=lambda e: parse_version(e['version'])[0], reverse=True)
best = entry return found
return best
@staticmethod
def _pick_latest(releases, channel):
"""Newest release for a channel. Returns entry dict or None."""
collected = UpdateService._collect_channel(releases, channel)
return collected[0] if collected else None
def check_for_updates(self): def check_for_updates(self):
"""Refresh latest-version info for our channel (and the other one).""" """Refresh latest-version info for our channel (and the other one)."""
try: try:
releases = self._fetch_releases() releases = self._fetch_releases()
other = 'stable' if self._channel == 'experimental' else 'experimental' other = 'stable' if self._channel == 'experimental' else 'experimental'
self._latest = self._pick_latest(releases, self._channel) self._releases = {
self._other_latest = self._pick_latest(releases, other) 'experimental': self._collect_channel(releases, 'experimental'),
'stable': self._collect_channel(releases, 'stable'),
}
self._latest = (self._releases[self._channel][0]
if self._releases[self._channel] else None)
self._other_latest = (self._releases[other][0]
if self._releases[other] else None)
self._last_check = time.time() self._last_check = time.time()
if self._latest: if self._latest:
logger.info( logger.info(
@@ -280,11 +296,21 @@ class UpdateService:
show_other = bool( show_other = bool(
other and other['version'] != (latest['version'] if latest else None) other and other['version'] != (latest['version'] if latest else None)
and self._is_newer_or_same(other['version'])) and self._is_newer_or_same(other['version']))
# Per-channel release lists for the version picker (newest first).
# zipball URLs stay server-side; the panel only needs version/notes.
lists = {}
for channel, entries in (self._releases or {}).items():
lists[channel] = [
{'version': e['version'], 'tag': e['tag'],
'notes': e['notes']}
for e in entries
]
return { return {
'current_version': self._current_version, 'current_version': self._current_version,
'channel': self._channel, 'channel': self._channel,
'available': available, 'available': available,
'latest': latest, 'latest': latest,
'releases': lists,
'other_channel': { 'other_channel': {
'channel': 'stable' if self._channel == 'experimental' else 'experimental', 'channel': 'stable' if self._channel == 'experimental' else 'experimental',
'latest': other, 'latest': other,
@@ -314,6 +340,10 @@ class UpdateService:
for entry in (self._latest, self._other_latest): for entry in (self._latest, self._other_latest):
if entry and entry['version'] == version: if entry and entry['version'] == version:
return entry return entry
for entries in (self._releases or {}).values():
for entry in entries:
if entry['version'] == version:
return entry
return None return None
def apply_update(self, version=None): def apply_update(self, version=None):
+81 -3
View File
@@ -210,6 +210,7 @@
// silence controls. Auto-expands only for a new, non-silenced update. // silence controls. Auto-expands only for a new, non-silenced update.
let ubData = null; let ubData = null;
let ubViewChannel = null; // channel shown in the panel; null = own channel let ubViewChannel = null; // channel shown in the panel; null = own channel
let ubViewVersion = null; // version picked in the dropdown; null = newest
let ubExpanded = false; let ubExpanded = false;
function ubChannelLatest(channel) { function ubChannelLatest(channel) {
@@ -224,6 +225,37 @@
return null; return null;
} }
// All known releases for a channel, newest first. Falls back to the
// single latest entry when the server payload predates release lists.
function ubChannelReleases(channel) {
if (!ubData) return [];
const lists = ubData.releases || {};
if (Array.isArray(lists[channel]) && lists[channel].length) {
return lists[channel];
}
const entry = ubChannelLatest(channel);
return entry ? [entry] : [];
}
// Numeric version compare mirroring the server's compare_versions:
// compares the X.Y.Z numbers only, so stable and experimental versions
// are comparable across channels. Returns -1, 0 or 1.
function ubCmpVer(a, b) {
const parse = (v) => {
const m = /^v?(\d+)\.(\d+)\.(\d+)(?:-([A-Za-z0-9]+))?$/.exec(String(v || '').trim());
return m ? [parseInt(m[1], 10), parseInt(m[2], 10), parseInt(m[3], 10)] : null;
};
const pa = parse(a), pb = parse(b);
if (!pa && !pb) return 0;
if (!pa) return -1;
if (!pb) return 1;
for (let i = 0; i < 3; i++) {
if (pa[i] < pb[i]) return -1;
if (pa[i] > pb[i]) return 1;
}
return 0;
}
function ubHasNews() { function ubHasNews() {
if (!ubData || ubData.silence_all) return false; if (!ubData || ubData.silence_all) return false;
if (ubData.preview) return true; if (ubData.preview) return true;
@@ -278,6 +310,22 @@
const isSilenced = !!(entry && silenced.includes(entry.version)); const isSilenced = !!(entry && silenced.includes(entry.version));
const canUpdate = !!(entry && entry.available && !isSilenced); const canUpdate = !!(entry && entry.available && !isSilenced);
// Per-version picker: every known release on the viewed channel,
// newest first. Older than the running version cannot be installed;
// same-numbered is a reinstall (works across channels); newer is
// an update. Settings and protected paths are preserved either way.
const releases = ubChannelReleases(viewing);
let picked = null;
if (releases.length) {
picked = releases.find(r => r.version === ubViewVersion) || releases[0];
if (!ubViewVersion || !releases.some(r => r.version === ubViewVersion)) {
ubViewVersion = picked.version;
}
}
const cmp = picked ? ubCmpVer(picked.version, data.current_version) : 0;
const pickedSilenced = !!(picked && silenced.includes(picked.version));
const pickedCanInstall = !!(picked && cmp >= 0 && !pickedSilenced);
let opts = ''; let opts = '';
channels.forEach(ch => { channels.forEach(ch => {
const label = ch === data.channel ? `${ch} (yours)` : ch; const label = ch === data.channel ? `${ch} (yours)` : ch;
@@ -285,9 +333,19 @@
}); });
let body = `<div class="ub-sub">You are on ${escHtml(data.current_version)} (${escHtml(data.channel)})</div>`; let body = `<div class="ub-sub">You are on ${escHtml(data.current_version)} (${escHtml(data.channel)})</div>`;
body += `<div class="ub-row"><label>Channel: <select id="ub-channel" onchange="ubViewChannel=this.value;renderUpdateBanner();">${opts}</select></label>` + body += `<div class="ub-row"><label>Channel: <select id="ub-channel" onchange="ubViewChannel=this.value;ubViewVersion=null;renderUpdateBanner();">${opts}</select></label>` +
`<button onclick="checkUpdatesNow()">Check now</button></div>`; `<button onclick="checkUpdatesNow()">Check now</button></div>`;
if (releases.length) {
let vopts = '';
releases.forEach(r => {
const c = ubCmpVer(r.version, data.current_version);
const tag = c < 0 ? ' — Older' : (c === 0 ? ' — Current (reinstall)' : ' — Update available');
vopts += `<option value="${escHtml(r.version)}"${picked && r.version === picked.version ? ' selected' : ''}>${escHtml(r.version)}${escHtml(tag)}</option>`;
});
body += `<div class="ub-row"><label>Version: <select id="ub-version" onchange="ubViewVersion=this.value;renderUpdateBanner();">${vopts}</select></label></div>`;
}
if (data.preview && ubSafeVer(data.preview.version)) { if (data.preview && ubSafeVer(data.preview.version)) {
ubNotesCache[data.preview.version] = data.preview.notes || ''; ubNotesCache[data.preview.version] = data.preview.notes || '';
body += `<div class="ub-title">${escHtml(data.preview.version)} <span class="ub-preview-tag">preview</span></div>` + body += `<div class="ub-title">${escHtml(data.preview.version)} <span class="ub-preview-tag">preview</span></div>` +
@@ -295,7 +353,25 @@
`<button class="ub-ghost" onclick="clearPreview()">Clear preview</button></div>`; `<button class="ub-ghost" onclick="clearPreview()">Clear preview</button></div>`;
} }
if (entry && ubSafeVer(entry.version)) { if (picked && ubSafeVer(picked.version)) {
ubNotesCache[picked.version] = picked.notes || '';
const isCurrent = cmp === 0;
const stateLine = cmp < 0
? `<div class="ub-sub">${escHtml(picked.version)} is older than your current version — cannot install.</div>`
: (!pickedCanInstall && pickedSilenced)
? `<div class="ub-sub">${escHtml(picked.version)} silenced - a newer version will show again.</div>`
: isCurrent
? `<div class="ub-title">Reinstall: ${escHtml(picked.version)} (same as current)</div>`
: `<div class="ub-title">Update available: ${escHtml(picked.version)}</div>`;
body += stateLine;
body += '<div class="ub-actions">' +
(picked.notes ? `<button class="ub-ghost" onclick="openNotesOverlay('${picked.version}')">Patch notes</button>` : '') +
(pickedCanInstall ? (isCurrent
? `<button onclick="applyUpdate('${picked.version}')">Reinstall ${escHtml(picked.version)}</button>`
: `<button onclick="applyUpdate('${picked.version}')">Update to ${escHtml(picked.version)}</button>`) : '') +
(cmp > 0 && !pickedSilenced ? `<button class="ub-ghost" onclick="silenceUpdateVersion('${picked.version}')">Silence this version</button>` : '') +
'</div>';
} else if (entry && ubSafeVer(entry.version)) {
ubNotesCache[entry.version] = entry.notes || ''; ubNotesCache[entry.version] = entry.notes || '';
const stateLine = !entry.available const stateLine = !entry.available
? `<div class="ub-sub">${escHtml(viewing)} is up to date at ${escHtml(entry.version)}.</div>` ? `<div class="ub-sub">${escHtml(viewing)} is up to date at ${escHtml(entry.version)}.</div>`
@@ -370,7 +446,9 @@
} }
async function applyUpdate(version) { async function applyUpdate(version) {
if (!confirm(`Update to ${version}? The dashboard backs itself up, installs, then restarts. Players will be briefly disconnected from the panel (not the game).`)) return; const isReinstall = ubData && version === ubData.current_version;
const action = isReinstall ? 'Reinstall' : 'Update to';
if (!confirm(`${action} ${version}? Settings and protected files are preserved. The dashboard backs itself up, installs, then restarts. Players will be briefly disconnected from the panel (not the game).`)) return;
const st = document.getElementById('ub-status'); const st = document.getElementById('ub-status');
if (st) st.textContent = 'Updating - the panel will restart...'; if (st) st.textContent = 'Updating - the panel will restart...';
try { try {
+1 -1
View File
@@ -168,7 +168,7 @@ function initMap() {
markerClusterGroup = (typeof L.markerClusterGroup !== 'undefined') markerClusterGroup = (typeof L.markerClusterGroup !== 'undefined')
? L.markerClusterGroup({ ? L.markerClusterGroup({
chunkedLoading: true, chunkedLoading: true,
maxClusterRadius: 5, maxClusterRadius: 12,
spiderfyOnMaxZoom: true, spiderfyOnMaxZoom: true,
showCoverageOnHover: false, showCoverageOnHover: false,
iconCreateFunction: function(cluster) { iconCreateFunction: function(cluster) {
+40
View File
@@ -75,6 +75,46 @@ class TestPickLatest:
assert UpdateService._pick_latest([], 'stable') is None assert UpdateService._pick_latest([], 'stable') is None
class TestReleaseLists:
def test_collect_channel_newest_first(self):
releases = UpdateService._collect_channel(make_releases(), 'experimental')
assert [e['version'] for e in releases] == [
'0.7.5-experimental', '0.7.3-Experimental']
def test_collect_skips_drafts_and_garbage(self):
releases = UpdateService._collect_channel(make_releases(), 'stable')
assert [e['version'] for e in releases] == ['0.7.4']
def test_status_includes_lists_and_find_searches_them(self, tmp_path, monkeypatch):
svc = make_service(tmp_path, '0.7.4-experimental')
monkeypatch.setattr(svc, '_fetch_releases', make_releases)
svc.check_for_updates()
status = svc.status()
assert [e['version'] for e in status['releases']['experimental']] == [
'0.7.5-experimental', '0.7.3-Experimental']
assert [e['version'] for e in status['releases']['stable']] == ['0.7.4']
# list payload stays lean (no download URLs for the panel)
assert 'zipball_url' not in status['releases']['experimental'][0]
# an older (non-latest) version is known but refused as a downgrade
assert svc._find_release('0.7.3-Experimental')['tag'] == 'v0.7.3-Experimental'
ok, msg = svc.apply_update('0.7.3-Experimental')
assert ok is False
assert 'owngrade' in msg or 'older' in msg
def test_cross_channel_same_number_is_reinstall(self, tmp_path, monkeypatch):
# Stable 0.7.4 installing experimental 0.7.4 is numeric-equal:
# allowed past validation (fails later only on download).
svc = make_service(tmp_path, '0.7.4')
monkeypatch.setattr(svc, '_fetch_releases', lambda: [
{'tag_name': 'v0.7.4-experimental', 'body': 'x',
'zipball_url': 'https://example.com/x.zip'},
])
svc.check_for_updates()
ok, msg = svc.apply_update('0.7.4-experimental')
assert ok is False
assert 'owngrade' not in msg and 'Unknown version' not in msg
class TestApplyRules: class TestApplyRules:
def test_refuses_downgrade_without_network(self, tmp_path): def test_refuses_downgrade_without_network(self, tmp_path):
svc = make_service(tmp_path, '0.7.5-experimental') svc = make_service(tmp_path, '0.7.5-experimental')