my own status page
1import type { Env, UptimeResponse } from "../types";
2import { getUptimeBuckets } from "../db";
3
4export async function handleUptime(
5 env: Env,
6 serviceId: string,
7 url: URL,
8): Promise<Response> {
9 const windowParam = url.searchParams.get("window");
10 const window_hours = windowParam ? parseInt(windowParam, 10) * 24 : 90 * 24;
11
12 const buckets = await getUptimeBuckets(env.DB, serviceId, window_hours);
13
14 return Response.json(
15 { service_id: serviceId, window_hours, buckets } satisfies UptimeResponse,
16 );
17}