mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 03:52:50 +08:00
feat(skins): ship protected built-ins and instance defaults
This commit is contained in:
1 parent
2b7e908d31
commit
e09a19b7b4
58 files changed
+2467
-414
No files matched your search
@@ -14,6 +14,7 @@ import { identityFromString } from "@echosixhiya/teamspeak-client";
|
||||
import { JoinRateLimiter } from "./join-rate-limit.js";
|
||||
import type { ConfiguredAccelerationRelay } from "./acceleration-relay.js";
|
||||
import type { SkinRegistry } from "../admin/skin-registry.js";
|
||||
import { resolveVisitorTotal } from "./visitor-count.js";
|
||||
|
||||
export interface WebServerOptions {
|
||||
port: number;
|
||||
@@ -79,11 +80,10 @@ export function createWebServer(options: WebServerOptions): WebServer {
|
||||
logger.warn({ err: error instanceof Error ? error.message : String(error) }, "Visitor number could not be assigned");
|
||||
}
|
||||
}
|
||||
let visitorTotal: number | null = null;
|
||||
let visitorTotal = resolveVisitorTotal(visitorNumber, null);
|
||||
if (options.visitorCount) {
|
||||
try {
|
||||
const count = options.visitorCount();
|
||||
if (Number.isSafeInteger(count) && count >= 0) visitorTotal = count;
|
||||
visitorTotal = resolveVisitorTotal(visitorNumber, options.visitorCount());
|
||||
} catch (error: unknown) {
|
||||
logger.warn({ err: error instanceof Error ? error.message : String(error) }, "Visitor total could not be read");
|
||||
}
|
||||
@@ -101,7 +101,10 @@ export function createWebServer(options: WebServerOptions): WebServer {
|
||||
|
||||
app.get("/api/skins", async (_request, response) => {
|
||||
response.setHeader("Cache-Control", "no-cache");
|
||||
response.json({ skins: await options.skinRegistry?.list() ?? [] });
|
||||
response.json({
|
||||
skins: await options.skinRegistry?.list() ?? [],
|
||||
defaultSkinId: await options.skinRegistry?.getDefaultSkinId() ?? "builtin.light",
|
||||
});
|
||||
});
|
||||
|
||||
app.get("/api/skins/:id/package", async (request, response) => {
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { resolveVisitorTotal } from "./visitor-count.js";
|
||||
|
||||
test("visitor total never disappears or falls below the current visitor ordinal", () => {
|
||||
assert.equal(resolveVisitorTotal(3, 0), 3);
|
||||
assert.equal(resolveVisitorTotal(3, 5), 5);
|
||||
assert.equal(resolveVisitorTotal(3, undefined), 3);
|
||||
assert.equal(resolveVisitorTotal(null, 8), 8);
|
||||
assert.equal(resolveVisitorTotal(null, -1), null);
|
||||
assert.equal(resolveVisitorTotal(0, 2), 2);
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
export function resolveVisitorTotal(visitorNumber: number | null, recordedTotal: unknown): number | null {
|
||||
const currentVisitor = Number.isSafeInteger(visitorNumber) && Number(visitorNumber) > 0
|
||||
? Number(visitorNumber)
|
||||
: null;
|
||||
const total = typeof recordedTotal === "number" && Number.isSafeInteger(recordedTotal) && recordedTotal >= 0
|
||||
? recordedTotal
|
||||
: null;
|
||||
|
||||
if (total === null) return currentVisitor;
|
||||
return Math.max(total, currentVisitor ?? 0);
|
||||
}
|
||||
Reference in new issue
Block a user