Files
beenvoice/apps/mobile/lib/server-mode.ts
T
soconnor d057ba208d Add 'apps/mobile/' from commit '5fa30f365f21531094cd4d2045042bb4f1370ac3'
git-subtree-dir: apps/mobile
git-subtree-mainline: 86f8987dff
git-subtree-split: 5fa30f365f
2026-08-16 21:42:59 -04:00

36 lines
1.1 KiB
TypeScript

import { DEFAULT_API_URL } from "@/lib/config";
import { normalizeInstanceUrl } from "@/lib/instance-url";
export type ServerMode = "official" | "self-hosted";
export const SERVER_MODE_OPTIONS: { value: ServerMode; label: string }[] = [
{ value: "official", label: "Official" },
{ value: "self-hosted", label: "Self-hosted" },
];
export function isOfficialServerUrl(url: string): boolean {
return url.replace(/\/$/, "") === DEFAULT_API_URL.replace(/\/$/, "");
}
export function resolveServerMode(url: string): ServerMode {
return isOfficialServerUrl(url) ? "official" : "self-hosted";
}
export function formatServerHost(url: string): string {
try {
return new URL(url).host;
} catch {
return url.replace(/^https?:\/\//, "").replace(/\/$/, "");
}
}
export function isServerConfigValid(mode: ServerMode, selfHostedUrl: string): boolean {
if (mode === "official") return true;
return normalizeInstanceUrl(selfHostedUrl) !== null;
}
export function resolveServerUrl(mode: ServerMode, selfHostedUrl: string): string | null {
if (mode === "official") return DEFAULT_API_URL;
return normalizeInstanceUrl(selfHostedUrl);
}