Add auto updater

This commit is contained in:
2026-03-10 23:38:57 +01:00
parent e8e5c24600
commit c3fbd7d4fe
20 changed files with 2272 additions and 14 deletions

View File

@@ -3,6 +3,7 @@ import path from 'path';
export interface ServerVariablesConfig {
klipyApiKey: string;
releaseManifestUrl: string;
}
const DATA_DIR = path.join(process.cwd(), 'data');
@@ -12,6 +13,10 @@ function normalizeKlipyApiKey(value: unknown): string {
return typeof value === 'string' ? value.trim() : '';
}
function normalizeReleaseManifestUrl(value: unknown): string {
return typeof value === 'string' ? value.trim() : '';
}
function readRawVariables(): { rawContents: string; parsed: Record<string, unknown> } {
if (!fs.existsSync(VARIABLES_FILE)) {
return { rawContents: '', parsed: {} };
@@ -48,7 +53,8 @@ export function ensureVariablesConfig(): ServerVariablesConfig {
const { rawContents, parsed } = readRawVariables();
const normalized = {
...parsed,
klipyApiKey: normalizeKlipyApiKey(parsed.klipyApiKey)
klipyApiKey: normalizeKlipyApiKey(parsed.klipyApiKey),
releaseManifestUrl: normalizeReleaseManifestUrl(parsed.releaseManifestUrl)
};
const nextContents = JSON.stringify(normalized, null, 2) + '\n';
@@ -56,7 +62,10 @@ export function ensureVariablesConfig(): ServerVariablesConfig {
fs.writeFileSync(VARIABLES_FILE, nextContents, 'utf8');
}
return { klipyApiKey: normalized.klipyApiKey };
return {
klipyApiKey: normalized.klipyApiKey,
releaseManifestUrl: normalized.releaseManifestUrl
};
}
export function getVariablesConfig(): ServerVariablesConfig {
@@ -70,3 +79,7 @@ export function getKlipyApiKey(): string {
export function hasKlipyApiKey(): boolean {
return getKlipyApiKey().length > 0;
}
export function getReleaseManifestUrl(): string {
return getVariablesConfig().releaseManifestUrl;
}

View File

@@ -1,9 +1,26 @@
import { Router } from 'express';
import fs from 'fs';
import path from 'path';
import { getAllPublicServers } from '../cqrs';
import { getReleaseManifestUrl } from '../config/variables';
import { connectedUsers } from '../websocket/state';
const router = Router();
function getServerProjectVersion(): string {
try {
const packageJsonPath = path.join(process.cwd(), 'package.json');
const rawContents = fs.readFileSync(packageJsonPath, 'utf8');
const parsed = JSON.parse(rawContents) as { version?: unknown };
return typeof parsed.version === 'string' && parsed.version.trim().length > 0
? parsed.version.trim()
: '0.0.0';
} catch {
return '0.0.0';
}
}
router.get('/health', async (_req, res) => {
const servers = await getAllPublicServers();
@@ -11,7 +28,9 @@ router.get('/health', async (_req, res) => {
status: 'ok',
timestamp: Date.now(),
serverCount: servers.length,
connectedUsers: connectedUsers.size
connectedUsers: connectedUsers.size,
serverVersion: getServerProjectVersion(),
releaseManifestUrl: getReleaseManifestUrl()
});
});