first commit

This commit is contained in:
2026-04-26 21:27:00 +07:00
commit 3ce6f0510b
48 changed files with 9700 additions and 0 deletions
+36
View File
@@ -0,0 +1,36 @@
type ApiError = {
status: number;
bodyText: string;
};
function buildUrl(path: string) {
const base = (import.meta.env.VITE_API_BASE_URL as string | undefined) ?? "/api";
if (path.startsWith("http://") || path.startsWith("https://")) return path;
if (path.startsWith("/")) return `${base}${path}`;
return `${base}/${path}`;
}
export async function apiJson<T>(path: string, init?: RequestInit): Promise<T> {
const url = buildUrl(path);
const res = await fetch(url, {
...init,
headers: {
"Content-Type": "application/json",
...(init?.headers ?? {}),
},
});
if (!res.ok) {
const bodyText = await res.text().catch(() => "");
const err: ApiError = { status: res.status, bodyText };
throw err;
}
return (await res.json()) as T;
}
export function getMediamtxWebrtcBaseUrl(configUrl?: string) {
const env = import.meta.env.VITE_MEDIAMTX_WEBRTC_URL as string | undefined;
return env ?? configUrl ?? "http://localhost:8889";
}