Files
wehub-resource-sync d68f003000
CI / Change detection (push) Has been cancelled
CI / Version drift (push) Has been cancelled
CI / Lint (push) Has been cancelled
CI / Workflow RLM cache (push) Has been cancelled
CI / Test (macos-latest) (push) Has been cancelled
CI / Test (ubuntu-latest) (push) Has been cancelled
CI / Test (windows-latest) (push) Has been cancelled
CI / npm wrapper smoke (push) Has been cancelled
CI / Mobile runtime smoke (push) Has been cancelled
CI / Workflow lint (push) Has been cancelled
CI / Documentation (push) Has been cancelled
Web Frontend / Lint & Type Check (push) Failing after 1s
Auto-close harvested PRs / close (push) Failing after 1s
cargo-deny / cargo-deny (bans licenses sources) (push) Failing after 1s
Security audit / cargo-audit (push) Failing after 1s
Sync to CNB / sync (push) Failing after 1s
Web Frontend / Deploy to Cloudflare (push) Waiting to run
cargo-deny / cargo-deny (advisories) (push) Failing after 3s
chore: import upstream snapshot with attribution
2026-07-13 12:08:23 +08:00

38 lines
1.1 KiB
TypeScript

type AssetBinding = {
fetch(input: Request | string, init?: RequestInit): Promise<Response>;
};
type FallbackFetch = (
request: Request,
env: Record<string, unknown>,
ctx: unknown,
) => Response | Promise<Response>;
const INSTALL_SCRIPT_PATH = "/install.sh";
export async function fetchWithStaticInstaller(
request: Request,
env: Record<string, unknown>,
ctx: unknown,
fallbackFetch: FallbackFetch,
): Promise<Response> {
const url = new URL(request.url);
const assets = (env as { ASSETS?: AssetBinding }).ASSETS;
if (url.pathname === INSTALL_SCRIPT_PATH && assets) {
const assetResponse = await assets.fetch(request);
if (assetResponse.status !== 404) {
const headers = new Headers(assetResponse.headers);
headers.set("content-type", "text/x-shellscript; charset=utf-8");
headers.set("cache-control", "public, max-age=300");
return new Response(assetResponse.body, {
status: assetResponse.status,
statusText: assetResponse.statusText,
headers,
});
}
}
return fallbackFetch(request, env, ctx);
}