feat: rebuild xiteng.site homelab platform

This commit is contained in:
2026-08-12 09:48:25 +08:00
parent 557b0eca33
commit 5b84988789
128 changed files with 14979 additions and 292 deletions
+23
View File
@@ -0,0 +1,23 @@
import type {ProviderDefinition, ProviderSecret} from "./provider-types";
export function createBrowserProviderFetch(provider: ProviderDefinition, secret: ProviderSecret) {
const proxy = provider.connection.proxy;
if (!proxy) return fetch;
if (proxy.type !== "relay") throw new Error(`Unsupported frontend proxy: ${proxy.type}`);
return async (input: RequestInfo | URL, init: RequestInit = {}) => {
const headers = new Headers(init.headers);
const relayHeaders: Record<string, string> = {"Content-Type": "application/json"};
if (secret.proxy?.token) relayHeaders.Authorization = `Bearer ${secret.proxy.token}`;
return fetch(proxy.url, {
method: "POST",
headers: relayHeaders,
body: JSON.stringify({
url: String(input),
method: init.method || "GET",
headers: Object.fromEntries(headers.entries()),
body: typeof init.body === "string" ? init.body : null
}),
signal: init.signal
});
};
}