Create standalone browser port of LTX Athena with authenticated native API transport

This commit is contained in:
Mikei386
2026-09-29 17:59:23 +02:00
commit 1333b0c36b
202 changed files with 63054 additions and 0 deletions
+24
View File
@@ -0,0 +1,24 @@
let cached: { url: string; token: string } | null = null
export async function getBackendCredentials(): Promise<{ url: string; token: string }> {
if (!cached) cached = await window.electronAPI.getBackend()
return cached
}
export function resetBackendCredentials(): void {
cached = null
}
export async function backendFetch(path: string, init?: RequestInit): Promise<Response> {
const { url, token } = await getBackendCredentials()
const headers = new Headers(init?.headers)
if (token) headers.set('Authorization', `Bearer ${token}`)
return fetch(`${url}${path}`, { ...init, headers })
}
export async function backendWsUrl(path: string): Promise<string> {
const { url, token } = await getBackendCredentials()
const ws = url.replace('http://', 'ws://')
const sep = path.includes('?') ? '&' : '?'
return `${ws}${path}${sep}token=${token}`
}