mirror of
https://github.com/ZHANGTIANYAO1/teamspeak-music-bot.git
synced 2026-12-03 03:12:51 +08:00
fix(release): report the package version in health metadata
This commit is contained in:
1 parent
5c05eae530
commit
bd03cb1c59
4 files changed
+19
-18
No files matched your search
@@ -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,
|
||||
|
||||
@@ -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<Record<string, string>> = {
|
||||
playlist: "<id|url>",
|
||||
};
|
||||
|
||||
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);
|
||||
|
||||
@@ -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();
|
||||
+2
-1
@@ -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) => {
|
||||
|
||||
Reference in new issue
Block a user