ultisuite-client/lib/native/http.ts
R3D347HR4Y efaaf16f60
Some checks are pending
E2E / Playwright e2e (push) Waiting to run
feat: update metadata and layout for new product pages
- Refactored metadata for contacts, administration, and Ulticards pages to utilize dynamic app names and descriptions.
- Introduced new product pages for Ultiai, Ultical, Ulticards, Ultidrive, Ultimail, and Ultimeet with appropriate metadata.
- Enhanced layout components to ensure consistent styling and functionality across new product sections.
- Updated various components to replace hardcoded labels with dynamic references to improve maintainability and consistency.
2026-06-19 22:11:42 +02:00

49 lines
1.3 KiB
TypeScript

/**
* HTTP for native shells. WebView fetch() is blocked by CORS on Authentik
* (/auth/* has no Access-Control-Allow-Origin). Rust reqwest bypasses that.
*/
import { invoke } from "@/lib/native/bridge"
import { isTauriRuntime } from "@/lib/platform"
type NativeHttpResponse = {
status: number
body: string
}
function headersRecord(init?: RequestInit): Record<string, string> {
if (!init?.headers) return {}
const out: Record<string, string> = {}
const h = new Headers(init.headers)
h.forEach((value, key) => {
out[key] = value
})
return out
}
async function nativeHttpRequest(
url: string,
init?: RequestInit
): Promise<Response | null> {
const result = await invoke<NativeHttpResponse>("plugin:ulti-core|http_request", {
url,
method: init?.method ?? "GET",
headers: headersRecord(init),
body: typeof init?.body === "string" ? init.body : undefined,
})
if (!result) return null
return new Response(result.body, { status: result.status })
}
/** fetch() on web; native HTTP in Tauri (no WebView CORS fallback). */
export async function runtimeFetch(
url: string,
init?: RequestInit
): Promise<Response> {
if (isTauriRuntime()) {
const res = await nativeHttpRequest(url, init)
if (res) return res
throw new TypeError(`Native HTTP failed: ${url}`)
}
return fetch(url, init)
}