fix: align connection diagnostics and localize announcement

This commit is contained in:
illusia committed 2026-09-06 08:53:39 +08:00
1 parent 62e41dbc51
commit a5e5dd6592
11 files changed
+87 -27

No files matched your search

+6 -3
View File
@@ -14,7 +14,7 @@ export interface AdminConnectionRecord {
startedAt: string;
connectedAt: string | null;
disconnectedAt: string | null;
durationSeconds: number;
durationSeconds: number | null;
status: "active" | "connecting" | "disconnected" | "failed";
reason: string | null;
}
@@ -349,6 +349,7 @@ function readSettingsInput(body: Record<string, unknown>): AdminSettingsInput {
accessMode: body.accessMode === "open" ? "open" : body.accessMode === "fixed" ? "fixed" : body.accessMode as never,
siteName: readString(body, "siteName", 80),
welcomeText: readOptionalString(body, "welcomeText", 500),
welcomeTextEn: typeof body.welcomeTextEn === "string" ? body.welcomeTextEn.slice(0, 500) : undefined,
webRtcEnabled: body.webRtcEnabled === true,
webRtcUdpStart: readOptionalInteger(body, "webRtcUdpStart"),
webRtcUdpEnd: readOptionalInteger(body, "webRtcUdpEnd"),
@@ -475,7 +476,7 @@ export function readConnectionHistory(logFile: string | undefined, limit: number
? Math.max(0, Math.floor(log.raw.durationSeconds))
: current.connectedAt
? Math.max(0, Math.floor((Date.parse(log.timestamp) - Date.parse(current.connectedAt)) / 1000))
: 0;
: null;
current.reason = typeof log.raw.reason === "string" ? log.raw.reason : null;
current.status = current.connectedAt ? "disconnected" : "failed";
}
@@ -494,7 +495,9 @@ export function readConnectionHistory(logFile: string | undefined, limit: number
startedAt: record.startedAt,
connectedAt: record.connectedAt,
disconnectedAt: record.disconnectedAt,
durationSeconds: record.durationSeconds ?? Math.max(0, Math.floor((end - Date.parse(start)) / 1000)),
durationSeconds: record.durationSeconds ?? (record.status === "active" || record.status === "connecting"
? Math.max(0, Math.floor((end - Date.parse(start)) / 1000))
: null),
status: record.status,
reason: record.reason,
};
+8
View File
@@ -17,6 +17,7 @@ export interface AdminSettingsInput {
accessMode: AccessMode;
siteName: string;
welcomeText: string;
welcomeTextEn?: string;
webRtcEnabled: boolean;
webRtcUdpStart?: number;
webRtcUdpEnd?: number;
@@ -97,6 +98,7 @@ export class AdminService {
initialized: this.isInitialized(),
siteName: settings.siteName,
welcomeText: settings.welcomeText,
welcomeTextEn: settings.welcomeTextEn,
accessMode: settings.accessMode,
target: formatTeamSpeakTarget({ host: settings.tsHost, port: settings.tsPort }),
};
@@ -110,6 +112,7 @@ export class AdminService {
accessMode: settings.accessMode,
siteName: settings.siteName,
welcomeText: settings.welcomeText,
welcomeTextEn: settings.welcomeTextEn,
lastTestAt: settings.lastTestAt,
lastTestLatencyMs: settings.lastTestLatencyMs,
lastTestError: settings.lastTestError,
@@ -263,8 +266,10 @@ export class AdminService {
}
const siteName = input.siteName.trim();
const welcomeText = input.welcomeText.trim();
const welcomeTextEn = typeof input.welcomeTextEn === "string" ? input.welcomeTextEn.trim() : current.welcomeTextEn;
if (!siteName || siteName.length > 80) throw new AdminInputError("INVALID_SITE_NAME", "Site name must contain 1 to 80 characters");
if (welcomeText.length > 500) throw new AdminInputError("INVALID_WELCOME_TEXT", "Welcome text cannot exceed 500 characters");
if (welcomeTextEn.length > 500) throw new AdminInputError("INVALID_WELCOME_TEXT_EN", "English welcome text cannot exceed 500 characters");
if (input.accessMode !== "fixed" && input.accessMode !== "open") {
throw new AdminInputError("INVALID_ACCESS_MODE", "Access mode is invalid");
}
@@ -293,6 +298,7 @@ export class AdminService {
return {
siteName,
welcomeText,
welcomeTextEn,
accessMode: input.accessMode,
tsHost: target.host,
tsPort: target.port,
@@ -324,6 +330,7 @@ export class AdminService {
return {
siteName: settings.siteName,
welcomeText: settings.welcomeText,
welcomeTextEn: settings.welcomeTextEn,
accessMode: settings.accessMode,
tsHost: settings.tsHost,
tsPort: settings.tsPort,
@@ -342,6 +349,7 @@ export class AdminService {
this.database.updateSettings({
siteName: current.siteName,
welcomeText: current.welcomeText,
welcomeTextEn: current.welcomeTextEn,
accessMode: current.accessMode,
tsHost: legacy.tsHost,
tsPort: legacy.tsPort,