import { sha256Hex } from "@/worker/auth/crypto"; export function clientIp(request: Request): string | null { const forwardedFor = request.headers.get("x-forwarded-for")?.split(",")[0]?.trim(); return request.headers.get("cf-connecting-ip") ?? forwardedFor ?? request.headers.get("x-real-ip") ?? null; } export async function hashNullable(value: string | null | undefined): Promise { return value ? await sha256Hex(value) : null; } export function pathPrefix(pathname: string): string { const segment = pathname.split("/").filter(Boolean)[0]; return segment ? `/${segment}` : "/"; } export function destinationHost(request: Request): string | null { const destination = request.headers.get("destination"); if (!destination) return null; try { return new URL(destination).host; } catch { return null; } }