web: React+Vite SPA — sessions, streaming chat, task panel, spawn flow (build clean)
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
export interface Settings {
|
||||
serverUrl: string;
|
||||
token: string;
|
||||
}
|
||||
|
||||
const STORAGE_KEY: string = "lvmh.settings";
|
||||
|
||||
export function getSettings(): Settings | null {
|
||||
try {
|
||||
const raw = localStorage.getItem(STORAGE_KEY);
|
||||
if (raw === null) return null;
|
||||
const parsed: unknown = JSON.parse(raw);
|
||||
if (
|
||||
parsed !== null &&
|
||||
typeof parsed === "object" &&
|
||||
typeof (parsed as { serverUrl?: unknown }).serverUrl === "string" &&
|
||||
typeof (parsed as { token?: unknown }).token === "string"
|
||||
) {
|
||||
return parsed as Settings;
|
||||
}
|
||||
return null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function saveSettings(settings: Settings): void {
|
||||
localStorage.setItem(STORAGE_KEY, JSON.stringify(settings));
|
||||
}
|
||||
|
||||
export function clearSettings(): void {
|
||||
localStorage.removeItem(STORAGE_KEY);
|
||||
}
|
||||
|
||||
export function buildWsUrl(settings: Settings): string {
|
||||
const base = settings.serverUrl.replace(/\/+$/, "").replace(/^http/, "ws");
|
||||
return `${base}/ws?token=${encodeURIComponent(settings.token)}`;
|
||||
}
|
||||
Reference in New Issue
Block a user