Improved serverlist structure
This commit is contained in:
+15
-18
@@ -4,33 +4,30 @@ export interface KnownServer {
|
||||
name: string;
|
||||
description: string;
|
||||
publicKey: string;
|
||||
hostname: string;
|
||||
isSecure: boolean;
|
||||
}
|
||||
|
||||
export async function saveServerList(servers: KnownServer[]): Promise<void> {
|
||||
export type ServerList = Record<string, KnownServer>;
|
||||
|
||||
export async function saveServerList(servers: ServerList): Promise<void> {
|
||||
await invoke("save_server_list", { servers });
|
||||
}
|
||||
|
||||
export async function getServerList(): Promise<KnownServer[]> {
|
||||
export async function getServerList(): Promise<ServerList> {
|
||||
return await invoke("get_server_list");
|
||||
}
|
||||
|
||||
export function getHTTPUrl(
|
||||
server: { hostname: string; isSecure: boolean },
|
||||
path: string,
|
||||
) {
|
||||
const hostname = server.hostname.includes(":")
|
||||
? server.hostname
|
||||
: server.hostname + ":3415";
|
||||
|
||||
return (server.isSecure ? "https://" : "http://") + hostname + path;
|
||||
export function getHTTPUrl(hostname: string, isSecure: boolean, path: string) {
|
||||
return (
|
||||
(isSecure ? "https://" : "http://") +
|
||||
(hostname.includes(":") ? hostname : hostname + ":3415") +
|
||||
path
|
||||
);
|
||||
}
|
||||
|
||||
export function getWSUrl(server: { hostname: string; isSecure: boolean }) {
|
||||
const hostname = server.hostname.includes(":")
|
||||
? server.hostname
|
||||
: server.hostname + ":3415";
|
||||
|
||||
return (server.isSecure ? "wss://" : "ws://") + hostname;
|
||||
export function getWSUrl(hostname: string, isSecure: boolean) {
|
||||
return (
|
||||
(isSecure ? "wss://" : "ws://") +
|
||||
(hostname.includes(":") ? hostname : hostname + ":3415")
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user