This commit is contained in:
nate 2026-04-08 16:29:20 +04:00
parent 601c918e9f
commit 5b3994b042
2 changed files with 11 additions and 11 deletions

View File

@ -50,7 +50,7 @@ function splitSlugAndFormat(raw: string): { slug: string; format: "html" | "json
}
async function renderHtml(slug: string, request: Request): Promise<Response> {
const page = await cached(`page:${slug}`, 60, () => loadStatusPage(slug));
const page = await cached(`page:${slug}`, 15, () => loadStatusPage(slug));
if (!page) return notFound();
if (!isAuthorised(page, request)) {
return new Response(eta.render("password", { title: page.title, slug: page.slug, error: null }), {
@ -58,12 +58,12 @@ async function renderHtml(slug: string, request: Request): Promise<Response> {
headers: { "content-type": "text/html; charset=utf-8" },
});
}
const payload = await cached(`payload:${slug}`, 60, () => loadPagePayload(slug));
const payload = await cached(`payload:${slug}`, 15, () => loadPagePayload(slug));
if (!payload) return notFound();
const html = eta.render("page", payload);
const headers: Record<string, string> = {
"content-type": "text/html; charset=utf-8",
"cache-control": "public, max-age=30, s-maxage=60",
"cache-control": "public, max-age=15, s-maxage=15",
"x-frame-options":"SAMEORIGIN",
"x-content-type-options": "nosniff",
"referrer-policy":"strict-origin-when-cross-origin",
@ -73,16 +73,16 @@ async function renderHtml(slug: string, request: Request): Promise<Response> {
}
async function renderJson(slug: string, request: Request, win?: Window): Promise<Response> {
const page = await cached(`page:${slug}`, 60, () => loadStatusPage(slug));
const page = await cached(`page:${slug}`, 15, () => loadStatusPage(slug));
if (!page) return new Response(JSON.stringify({ error: "not found" }), { status: 404, headers: { "content-type": "application/json" } });
if (!isAuthorised(page, request)) return new Response(JSON.stringify({ error: "password required" }), { status: 401, headers: { "content-type": "application/json" } });
const cacheKey = `payload:${slug}:${win ?? page.default_window}`;
const payload = await cached(cacheKey, 60, () => loadPagePayload(slug, win));
const payload = await cached(cacheKey, 15, () => loadPagePayload(slug, win));
if (!payload) return new Response(JSON.stringify({ error: "not found" }), { status: 404, headers: { "content-type": "application/json" } });
return new Response(JSON.stringify(payload), {
headers: {
"content-type": "application/json",
"cache-control": "public, max-age=30, s-maxage=60",
"cache-control": "public, max-age=15, s-maxage=15",
...(page.index_search ? {} : { "x-robots-tag": "noindex, nofollow" }),
},
});
@ -117,14 +117,14 @@ const app = new Elysia()
// Public SVG badge
.get("/:slug/badge.svg", async ({ params, request }) => {
if (!allow(params.slug, clientIp(request))) return rateLimited();
const payload = await cached(`payload:${params.slug}`, 60, () => loadPagePayload(params.slug));
const payload = await cached(`payload:${params.slug}`, 15, () => loadPagePayload(params.slug));
if (!payload) return notFound();
const { message, color } = badgeFromState(payload.monitors);
const svg = renderBadge("status", message, color);
return new Response(svg, {
headers: {
"content-type": "image/svg+xml",
"cache-control": "public, max-age=60, s-maxage=60",
"cache-control": "public, max-age=15, s-maxage=15",
},
});
})
@ -139,7 +139,7 @@ const app = new Elysia()
const monitorId = idWithExt.endsWith(".json") ? idWithExt.slice(0, -5) : idWithExt;
const win = (query as any)?.window as Window | undefined;
const cacheKey = `monitor:${params.slug}:${monitorId}:${win ?? ''}`;
const payload = await cached(cacheKey, 60, () => loadMonitorDetail(params.slug, monitorId, win));
const payload = await cached(cacheKey, 15, () => loadMonitorDetail(params.slug, monitorId, win));
if (!payload) {
return new Response(JSON.stringify({ error: "not found" }), {
status: 404,
@ -149,7 +149,7 @@ const app = new Elysia()
return new Response(JSON.stringify(payload), {
headers: {
"content-type": "application/json",
"cache-control": "public, max-age=30, s-maxage=60",
"cache-control": "public, max-age=15, s-maxage=15",
},
});
})

View File

@ -113,7 +113,7 @@
.monitor-name .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.monitor-meta { display: flex; gap: 1rem; align-items: center; font-size: 0.85rem; color: var(--muted); }
.uptime-pct { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--fg); }
.bars { display: flex; gap: 2px; height: 32px; margin-top: 0.75rem; align-items: stretch; }
.bars { display: flex; gap: 0.1rem; height: 32px; margin-top: 0.75rem; align-items: stretch; }
.bar { flex: 1; min-width: 0; border-radius: 2px; transition: opacity 0.15s; }
.bar:hover { opacity: 0.8; }
.bars-meta { display: flex; justify-content: space-between; font-size: 0.7rem; color: var(--muted); margin-top: 0.4rem; }