Add 'apps/mobile/' from commit '5fa30f365f21531094cd4d2045042bb4f1370ac3'
git-subtree-dir: apps/mobile git-subtree-mainline:86f8987dffgit-subtree-split:5fa30f365f
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user