diff --git a/src/ts-protocol/open-protocol.test.ts b/src/ts-protocol/open-protocol.test.ts index 9a3d6f3..d76a4c5 100644 --- a/src/ts-protocol/open-protocol.test.ts +++ b/src/ts-protocol/open-protocol.test.ts @@ -1,11 +1,11 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import pino from "pino"; +import { APP_VERSION } from "../version.js"; import { ACK_GLOBAL_BURST, ANNOUNCE_DEBOUNCE_MS, ANNOUNCE_RETRY_DELAY_MS, APP_NAME, - APP_VERSION, BOT_CAPABILITIES, COMMANDS_LIST_REQ_COOLDOWN_MS, COMMANDS_PLUGIN, diff --git a/src/ts-protocol/open-protocol.ts b/src/ts-protocol/open-protocol.ts index 128ceaf..887896b 100644 --- a/src/ts-protocol/open-protocol.ts +++ b/src/ts-protocol/open-protocol.ts @@ -1,6 +1,6 @@ -import { readFileSync } from "node:fs"; import { PlayMode } from "../audio/queue.js"; import type { Logger } from "../logger.js"; +import { APP_VERSION } from "../version.js"; import type { PluginCommandTarget, TS3PluginCommand } from "./client.js"; export const OPEN_PROTOCOL_VERSION = 1; @@ -100,21 +100,6 @@ const CORE_COMMAND_ARGS_EN: Readonly> = { playlist: "", }; -function loadAppVersion(): string { - try { - const raw = readFileSync(new URL("../../package.json", import.meta.url), "utf8"); - const parsed = JSON.parse(raw) as { version?: unknown }; - if (typeof parsed.version === "string" && parsed.version.trim().length > 0) { - return truncateChars(parsed.version.trim(), MAX_APP_META_CHARS); - } - } catch { - // Fallback below if package.json is unavailable in a custom bundle - } - return "0.1.0"; -} - -export const APP_VERSION = loadAppVersion(); - function truncateChars(value: string, maxChars: number): string { const sanitized = value.replace(/[\u0000-\u001F\u007F]/g, ""); const chars = Array.from(sanitized); diff --git a/src/version.ts b/src/version.ts new file mode 100644 index 0000000..c6fd747 --- /dev/null +++ b/src/version.ts @@ -0,0 +1,15 @@ +import { readFileSync } from "node:fs"; + +function loadAppVersion(): string { + try { + const manifest = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")) as { version?: unknown }; + if (typeof manifest.version === "string" && manifest.version.trim()) { + return manifest.version.trim(); + } + } catch { + // A custom bundle may omit the package manifest. + } + return "unknown"; +} + +export const APP_VERSION = loadAppVersion(); diff --git a/src/web/server.ts b/src/web/server.ts index 77875ab..9328cce 100755 --- a/src/web/server.ts +++ b/src/web/server.ts @@ -8,6 +8,7 @@ import type { MusicProvider } from "../music/provider.js"; import type { BotDatabase } from "../data/database.js"; import type { BotConfig, GuestModeConfig } from "../data/config.js"; import type { Logger } from "../logger.js"; +import { APP_VERSION } from "../version.js"; import type { CookieStore } from "../music/auth.js"; import type { AvatarStore } from "../data/avatars.js"; import { createBotRouter } from "./api/bot.js"; @@ -116,7 +117,7 @@ export function createWebServer(options: WebServerOptions): WebServer { }); app.get("/api/health", (_req, res) => { - res.json({ status: "ok", version: "0.1.0" }); + res.json({ status: "ok", version: APP_VERSION }); }); app.get("/api/config/public-url", (_req, res) => {