fix: expose server identity and refine KAAK client

This commit is contained in:
illusia committed 2026-10-11 17:14:56 +08:00
1 parent e8164abafe
commit 17fb27b89a
28 files changed
+1504 -334

No files matched your search

+4
View File
@@ -31,6 +31,8 @@ export interface FavoriteServer {
nickname?: string;
identityId?: string;
lastChannelHint?: { id?: string; name?: string };
serverName?: string;
serverIcon?: string;
}
export interface RecentServer {
@@ -40,6 +42,8 @@ export interface RecentServer {
identityId?: string;
lastConnectedAt: number;
lastChannelHint?: { id?: string; name?: string };
serverName?: string;
serverIcon?: string;
}
export interface LocalPreferences {
+32
View File
@@ -46,3 +46,35 @@ test("quick server addresses are trimmed, normalized, and empty targets are skip
assert.equal(quickServers[0].id, "voice.example:9987");
assert.equal(quickServers[0].address, "Voice.Example:9987");
});
test("server-provided name and image replace address placeholders while custom favorite names stay intact", () => {
const icon = "data:image/png;base64,iVBORw0KGgo=";
const quickServers = mergeQuickServers(
[
{ id: "shanghai", label: "shanghai.example:9987", address: "shanghai.example:9987" },
{ id: "custom", label: "My room", address: "custom.example:9987" },
],
[
{ id: "recent-shanghai", address: "shanghai.example:9987", serverName: "兄弟们的teamspeak", serverIcon: icon, lastConnectedAt: 2 },
{ id: "recent-custom", address: "custom.example:9987", serverName: "Original TeamSpeak name", lastConnectedAt: 1 },
],
);
const shanghai = quickServers.find((server) => server.address === "shanghai.example:9987");
const custom = quickServers.find((server) => server.address === "custom.example:9987");
assert.equal(shanghai?.label, "兄弟们的teamspeak");
assert.equal(shanghai?.serverIcon, icon);
assert.equal(custom?.label, "My room");
assert.equal(custom?.serverName, "Original TeamSpeak name");
});
test("unsafe or non-image server icon URLs are ignored", () => {
const quickServers = mergeQuickServers([], [{
id: "recent",
address: "voice.example:9987",
serverName: "Voice",
serverIcon: "https://tracking.example/image.png",
lastConnectedAt: 1,
}]);
assert.equal(quickServers[0].serverIcon, undefined);
});
+27 -2
View File
@@ -1,4 +1,5 @@
import type { FavoriteServer, RecentServer } from "./local-persistence.js";
import { splitTeamSpeakTarget } from "./teamspeak-target.js";
export interface QuickServer {
id: string;
@@ -9,6 +10,20 @@ export interface QuickServer {
lastChannelHint?: { id?: string; name?: string };
isFavorite: boolean;
lastConnectedAt?: number;
serverName?: string;
serverIcon?: string;
}
export function isSafeQuickServerIcon(value: unknown): value is string {
return typeof value === "string" && value.length <= 180_000
&& /^data:image\/(?:png|jpeg|gif|webp);base64,[A-Za-z0-9+/]+={0,2}$/.test(value);
}
export function isQuickServerAddressLabel(label: string, address: string): boolean {
const normalizedLabel = label.trim().toLocaleLowerCase();
const candidates = new Set([address.trim()]);
try { candidates.add(splitTeamSpeakTarget(address).address.trim()); } catch { /* Persisted targets are validated on write. */ }
return [...candidates].some((candidate) => candidate.length >= 3 && normalizedLabel.includes(candidate.toLocaleLowerCase()));
}
/**
@@ -33,11 +48,19 @@ export function mergeQuickServers(
if (!key || seen.has(key)) continue;
seen.add(key);
const recent = recentByAddress.get(key);
const serverName = recent?.serverName?.trim() || favorite.serverName?.trim() || "";
const serverIcon = isSafeQuickServerIcon(recent?.serverIcon) ? recent.serverIcon
: isSafeQuickServerIcon(favorite.serverIcon) ? favorite.serverIcon : "";
const savedLabel = favorite.label.trim();
result.push({
id: key,
address: favorite.address.trim(),
label: favorite.label.trim() || favorite.address.trim(),
label: serverName && (!savedLabel || isQuickServerAddressLabel(savedLabel, favorite.address))
? serverName
: savedLabel || favorite.address.trim(),
isFavorite: true,
...(serverName ? { serverName } : {}),
...(serverIcon ? { serverIcon } : {}),
...(recent?.nickname || favorite.nickname ? { nickname: recent?.nickname || favorite.nickname } : {}),
...(recent?.identityId || favorite.identityId ? { identityId: recent?.identityId || favorite.identityId } : {}),
...(recent?.lastChannelHint || favorite.lastChannelHint ? { lastChannelHint: recent?.lastChannelHint ?? favorite.lastChannelHint } : {}),
@@ -52,8 +75,10 @@ export function mergeQuickServers(
result.push({
id: key,
address: recent.address.trim(),
label: recent.address.trim(),
label: recent.serverName?.trim() || recent.address.trim(),
isFavorite: false,
...(recent.serverName?.trim() ? { serverName: recent.serverName.trim() } : {}),
...(isSafeQuickServerIcon(recent.serverIcon) ? { serverIcon: recent.serverIcon } : {}),
...(recent.nickname ? { nickname: recent.nickname } : {}),
...(recent.identityId ? { identityId: recent.identityId } : {}),
...(recent.lastChannelHint ? { lastChannelHint: recent.lastChannelHint } : {}),
+1 -1
View File
@@ -46,7 +46,7 @@ export const BUILTIN_SKIN_CATALOG: SkinCatalogEntry[] = [
{
id: BUILTIN_KAAK_SKIN_ID,
name: "KAAK",
version: "3.1.62",
version: "3.1.64",
author: "WebSpeak Project",
license: "AGPL-3.0-only",
description: "A KOOK-inspired voice-room workspace with collapsible voice groups, channel chat, TeamSpeak profile cards, accessible host-owned member controls, and WebSpeak screen sharing.",
+24 -6
View File
@@ -464,7 +464,7 @@ test("the distributable KAAK package provides full home and voice surfaces", asy
const file = new File([archive], "kaak-voice.wskin", { type: "application/octet-stream" });
const skin = await importSkinPack(file);
assert.equal(skin.id, "community.kaak-voice");
assert.equal(skin.version, "3.1.62");
assert.equal(skin.version, "3.1.64");
assert.equal(BUILTIN_SKIN_CATALOG.find((entry) => entry.id === skin.id)?.version, skin.version);
assert.equal(skin.schemaVersion, 3);
const home = skin.pluginData?.components.find((component) => component.page === "home");
@@ -517,8 +517,11 @@ test("the distributable KAAK package provides full home and voice surfaces", asy
assert.equal(chatExpand?.attributes?.["aria-expanded"], "{{state.chatopen}}");
assert.deepEqual(findPart(voice?.root, "chat")?.when, { path: "state.chatopen", equals: true });
assert.equal(voice?.root.attributes?.["data-chat-open"], "{{state.chatopen}}");
assert.equal(findPart(voice?.root, "server-monogram")?.children?.[0]?.text, "{{server.monogram}}");
assert.equal(findPart(voice?.root, "server-icon")?.attributes?.src, "{{server.icon}}");
assert.equal(findPart(voice?.root, "server-monogram-initial")?.children?.[0]?.text, "{{server.monogram}}");
assert.equal(findPart(voice?.root, "server-monogram")?.attributes?.["data-tone"], "{{server.tone}}");
assert.deepEqual(findPart(voice?.root, "identity-online")?.when, { path: "session.status.connected", equals: true });
assert.equal(findPart(voice?.root, "identity-online")?.attributes?.role, "img");
const voiceStageHeadingItem = findPart(voice?.root, "voice-stage-heading-item");
assert.equal(voiceStageHeadingItem?.repeat?.path, "session.channels");
const voiceStageHeading = findPart(voiceStageHeadingItem, "voice-stage-heading");
@@ -617,14 +620,29 @@ test("the distributable KAAK package provides full home and voice surfaces", asy
assert.match(skin.css, /kaak-workspace\.voice-channel-group-toggle/);
assert.match(skin.css, /voice-channel-list[\s\S]*?grid-template-rows: 1fr;[\s\S]*?transition: grid-template-rows \.18s ease/);
assert.match(skin.css, /data-voice-group-open="false"[\s\S]*?voice-channel-list[\s\S]*?grid-template-rows: 0fr;[\s\S]*?visibility: hidden;[\s\S]*?visibility 0s linear \.18s/);
assert.match(skin.css, /kaak-workspace\.server-monogram"\]\[data-tone="0"\]/);
assert.match(skin.css, /voice-stage-heading[\s\S]*?flex: 0 0 46px;/);
assert.doesNotMatch(skin.css, /aria-expanded="true"\]\s*[^\n]*voice-stage-heading[^\n]*display: none;/);
assert.match(skin.css, /kaak-workspace"\]:has\(\[data-ws-plugin-part="kaak-workspace\.chat-panel-toggle"\]\[aria-expanded="false"\]\)[\s\S]*?grid-template-columns: 80px 290px minmax\(280px, 1fr\) 0;/);
assert.match(skin.css, /grid-template-columns: 80px 290px/);
assert.match(skin.css, /kaak-workspace"\]:has\(\[data-ws-plugin-part="kaak-workspace\.chat-panel-toggle"\]\[aria-expanded="false"\]\)[\s\S]*?grid-template-columns: 86px 290px minmax\(280px, 1fr\) 0;/);
assert.match(skin.css, /grid-template-columns: 86px 290px/);
assert.match(skin.css, /minmax\(340px, min\(38vw, 520px\)\)/);
assert.match(skin.css, /grid-template-rows: 40px/);
assert.match(skin.css, /kaak-workspace\.server-monogram[\s\S]*?width: 48px;[\s\S]*?height: 48px;/);
assert.match(skin.css, /kaak-workspace\.server-rail"\]\s*\{[\s\S]*?--skin-kaak-rail-bg: #191a1d;[\s\S]*?--skin-kaak-rail-item-bg: #2b2d32;[\s\S]*?--skin-kaak-rail-accent: #75c900;[\s\S]*?gap: 18px;[\s\S]*?padding: 14px 0 96px;[\s\S]*?background: var\(--skin-kaak-rail-bg\);/);
assert.match(skin.css, /kaak-workspace\.quick-server-item"\]\s*\{[\s\S]*?width: 58px;[\s\S]*?height: 58px;/);
assert.match(skin.css, /kaak-workspace\.quick-server"\]\s*\{[\s\S]*?width: 58px;[\s\S]*?height: 58px;[\s\S]*?border: 2px solid transparent;[\s\S]*?border-radius: 18px;/);
assert.match(skin.css, /quick-server\"\]\:hover[\s\S]*?background: #383a40;/);
assert.match(skin.css, /quick-server\"\]\:not\(\[aria-current=\"true\"\]\):hover[\s\S]*?server-monogram[\s\S]*?background: #383a40;/);
assert.match(skin.css, /quick-server\"\]\[aria-current=\"true\"\] \{[\s\S]*?border-color: var\(--skin-kaak-rail-accent\);[\s\S]*?background: var\(--skin-kaak-rail-item-bg\);/);
assert.match(skin.css, /quick-server\"\]\[aria-current=\"true\"\][\s\S]*?server-monogram[\s\S]*?background: var\(--skin-kaak-rail-item-bg\);/);
assert.match(skin.css, /quick-server\"\]\[aria-current=\"true\"\]::before[\s\S]*?left: -16px;[\s\S]*?top: 10px;[\s\S]*?width: 4px;[\s\S]*?height: 34px;/);
assert.match(skin.css, /kaak-workspace\.identity-entry\"\]\s*\{[\s\S]*?width: 86px;[\s\S]*?background: #191a1d;/);
assert.match(skin.css, /kaak-workspace\.server-monogram[\s\S]*?width: 100%;[\s\S]*?height: 100%;[\s\S]*?border-radius: 16px;[\s\S]*?font-size: 23px;[\s\S]*?font-weight: 600;/);
assert.match(skin.css, /kaak-workspace\.server-icon[\s\S]*?width: 100%;[\s\S]*?height: 100%;[\s\S]*?border-radius: inherit;[\s\S]*?object-fit: cover;/);
assert.doesNotMatch(skin.css, /server-monogram\"\]\[data-tone=/);
assert.match(skin.css, /kaak-workspace\.identity-monogram\"\]\s*\{[\s\S]*?width: 54px;[\s\S]*?height: 54px;[\s\S]*?border-radius: 50%;[\s\S]*?background: #176a9e;[\s\S]*?font-size: 17px;/);
assert.match(skin.css, /kaak-workspace\.identity-online\"\]\s*\{[\s\S]*?right: -2px;[\s\S]*?bottom: -2px;[\s\S]*?width: 17px;[\s\S]*?height: 17px;[\s\S]*?border: 3px solid #191a1d;[\s\S]*?background: #75c900;/);
assert.match(skin.css, /kaak-workspace\.identity-name\"\]\s*\{\s*display: none;/);
assert.match(skin.css, /@media \(max-width: 820px\)[\s\S]*?grid-template-columns: 86px minmax\(0, 1fr\);[\s\S]*?grid-template-columns: 86px minmax\(0, 1fr\);/);
assert.match(skin.css, /@media \(max-height: 620px\)[\s\S]*?server-rail[\s\S]*?padding-bottom: 76px;/);
assert.match(skin.css, /voice-grid[\s\S]*?grid-template-columns: repeat\(auto-fit/);
assert.match(skin.css, /voice-card[\s\S]*?aspect-ratio: 1\.82;/);
assert.match(skin.css, /\.voice-card\s*\{[\s\S]*?transition: border-color \.18s ease, background-color \.18s ease, box-shadow \.18s ease;/);
+8 -3
View File
@@ -1,10 +1,11 @@
import type { QuickServer } from "./quick-servers.js";
import { isSafeQuickServerIcon, type QuickServer } from "./quick-servers.js";
import { splitTeamSpeakTarget } from "./teamspeak-target.js";
export interface SkinPluginQuickServer {
id: string;
label: string;
monogram: string;
icon: string;
tone: number;
current: boolean;
kind: "favorite" | "recent";
@@ -47,13 +48,17 @@ export function createSkinPluginQuickServerProjection(createId: () => string = r
}
targetByOpaqueId.set(opaqueId, server);
const label = server.label.trim();
const serverName = server.serverName?.trim() ?? "";
const safeLabel = !label || containsConnectionTarget(label, server.address)
? `${server.isFavorite ? "Favorite" : "Recent"} ${index + 1}`
? serverName && !containsConnectionTarget(serverName, server.address)
? serverName
: `${server.isFavorite ? "Favorite" : "Recent"} ${index + 1}`
: label;
return {
id: opaqueId,
label: safeLabel,
monogram: Array.from(safeLabel)[0] ?? "?",
monogram: Array.from(serverName || safeLabel)[0] ?? "?",
icon: isSafeQuickServerIcon(server.serverIcon) ? server.serverIcon : "",
tone: safeLabelTone(safeLabel),
current: isCurrent(server),
kind: server.isFavorite ? "favorite" : "recent",
@@ -83,3 +83,21 @@ test("skin quick-server data redacts connection targets and resolves only host-g
assert.equal(projection.resolve("opaque-1")?.address, "192.0.2.10:9987");
assert.equal(projection.resolve("192.0.2.10:9987"), undefined);
});
test("skin quick-server projection uses the TeamSpeak name and public icon while keeping its target private", () => {
const icon = "data:image/png;base64,iVBORw0KGgo=";
const projection = createSkinPluginQuickServerProjection(() => "opaque-server");
const [server] = projection.project([{
id: "shanghai.example:9987",
address: "shanghai.example:9987",
label: "shanghai.example:9987",
serverName: "兄弟们的teamspeak",
serverIcon: icon,
isFavorite: false,
}], () => true);
assert.equal(server.label, "兄弟们的teamspeak");
assert.equal(server.monogram, "兄");
assert.equal(server.icon, icon);
assert.equal(JSON.stringify(server).includes("shanghai.example"), false);
});