Files
wibosim/server/src/version.js
T
db9979andClaude Opus 5.5 939fe5def5 Version 0.9.0, Änderungsprotokoll und automatisches Update
- Versionsnummer, Build (Git-Commit) und Bauzeit unter /api/version, in /api/info und hello
- Änderungsprotokoll für Spieler unter /api/changelog (Test prüft Übereinstimmung mit package.json)
- Server meldet Neustarts an die Clients; statische Dateien ohne langes Zwischenspeichern
- Admin: Hinweis, wenn auf GitHub eine neuere Version liegt
- Pi: scripts/install-autoupdate.sh (systemd-Timer oder cron) mit Zeitfenster, Gesundheitscheck und automatischem Zurückrollen
- CI übergibt Bauzeit ans Image; Doku zu Updates, Versionen und KI-Auswertung

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018i4GUhQVoPUusUzxgxLWkK
2026-12-03 19:56:03 +00:00

56 lines
2.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Versionsangaben: Versionsnummer aus package.json, Build (Git-Commit) und Bauzeit aus dem Docker-Image.
import fs from 'node:fs';
import path from 'node:path';
import { execFileSync } from 'node:child_process';
import { fileURLToPath } from 'node:url';
import { CHANGELOG } from './changelog.js';
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
const pkg = JSON.parse(fs.readFileSync(path.join(ROOT, 'package.json'), 'utf8'));
function gitCommit() {
try { return execFileSync('git', ['rev-parse', 'HEAD'], { cwd: ROOT, stdio: ['ignore', 'pipe', 'ignore'], timeout: 2000 }).toString().trim(); } catch { return ''; }
}
const envBuild = process.env.WIBOSIM_VERSION && process.env.WIBOSIM_VERSION !== 'dev' ? process.env.WIBOSIM_VERSION : '';
const commit = envBuild || gitCommit();
export const VERSION = {
version: pkg.version,
commit: commit || null,
build: commit ? commit.slice(0, 7) : 'dev',
builtAt: process.env.WIBOSIM_BUILT_AT || null,
startedAt: Date.now(),
};
export { CHANGELOG };
export const versionLabel = () => `${VERSION.version}${VERSION.build !== 'dev' ? ` (${VERSION.build})` : ''}`;
/**
* Prüft (für das Admin-Menü), ob auf GitHub ein neuerer Stand liegt. Fehler sind egal – dann eben keine Angabe.
* repo: "owner/name"
*/
export class UpdateCheck {
constructor(repo, everyMs = 30 * 60_000) {
this.repo = repo;
this.everyMs = everyMs;
this.state = { latest: null, latestDate: null, latestMessage: null, available: false, checkedAt: 0, error: null };
}
start() { this.check(); this.timer = setInterval(() => this.check(), this.everyMs); this.timer.unref?.(); }
stop() { clearInterval(this.timer); }
async check() {
if (!VERSION.commit) { this.state.error = 'Unbekannter Build (Entwicklungsstand)'; return this.state; }
try {
const res = await fetch(`https://api.github.com/repos/${this.repo}/commits/main`, {
headers: { accept: 'application/vnd.github+json', 'user-agent': 'WiBoSim-Updatecheck' }, signal: AbortSignal.timeout(10_000),
});
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const j = await res.json();
this.state = {
latest: String(j.sha ?? '').slice(0, 7), latestDate: j.commit?.committer?.date ?? null,
latestMessage: String(j.commit?.message ?? '').split('\n')[0].slice(0, 160),
available: !!j.sha && j.sha !== VERSION.commit, checkedAt: Date.now(), error: null,
};
} catch (e) { this.state = { ...this.state, checkedAt: Date.now(), error: String(e.message ?? e).slice(0, 120) }; }
return this.state;
}
}