From 7877b14f853bf41dd4ffb2e559dae3f32a0f3c5d Mon Sep 17 00:00:00 2001 From: nate Date: Thu, 9 Apr 2026 22:00:46 +0400 Subject: [PATCH] fix: docs --- apps/api/src/routes/monitors.ts | 12 +++++++----- apps/web/src/views/docs.ejs | 13 +++++++++++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/apps/api/src/routes/monitors.ts b/apps/api/src/routes/monitors.ts index 3d7a0b6..56f5d00 100644 --- a/apps/api/src/routes/monitors.ts +++ b/apps/api/src/routes/monitors.ts @@ -197,21 +197,23 @@ export const monitors = new Elysia({ prefix: "/monitors" }) if (!monitor) { set.status = 404; return { error: "Not found" }; } const limit = Math.min(Number(query.limit) || 100, 1000); + const skip = Math.max(0, Math.floor(Number(query.skip) || 0)); const filter = query.filter; // "up", "down", "events", or undefined/all - const before = query.before; // cursor: ISO timestamp for pagination + const before = query.before ? Number(query.before) * 1000 : null; // unix timestamp (seconds) -> ms const cursorClause = before ? sql`AND checked_at < ${new Date(before)}` : sql``; + const offsetClause = skip > 0 ? sql`OFFSET ${skip}` : sql``; if (filter === "up") { return sql` SELECT * FROM pings WHERE monitor_id = ${params.id} AND up = true ${cursorClause} - ORDER BY checked_at DESC LIMIT ${limit} + ORDER BY checked_at DESC LIMIT ${limit} ${offsetClause} `; } if (filter === "down") { return sql` SELECT * FROM pings WHERE monitor_id = ${params.id} AND up = false ${cursorClause} - ORDER BY checked_at DESC LIMIT ${limit} + ORDER BY checked_at DESC LIMIT ${limit} ${offsetClause} `; } if (filter === "events") { @@ -222,12 +224,12 @@ export const monitors = new Elysia({ prefix: "/monitors" }) ) t WHERE prev_up IS NULL OR up != prev_up ${before ? sql`AND checked_at < ${new Date(before)}` : sql``} - ORDER BY checked_at DESC LIMIT ${limit} + ORDER BY checked_at DESC LIMIT ${limit} ${offsetClause} `; } return sql` SELECT * FROM pings WHERE monitor_id = ${params.id} ${cursorClause} - ORDER BY checked_at DESC LIMIT ${limit} + ORDER BY checked_at DESC LIMIT ${limit} ${offsetClause} `; }, { detail: { summary: "Get ping history", tags: ["monitors"] } }); diff --git a/apps/web/src/views/docs.ejs b/apps/web/src/views/docs.ejs index f70466d..e0b5ae1 100644 --- a/apps/web/src/views/docs.ejs +++ b/apps/web/src/views/docs.ejs @@ -187,8 +187,17 @@

Enable or disable a monitor without deleting it.

Ping History

-
GET/monitors/:id/pings?limit=100
-

Returns recent ping results for a monitor. Max 1000. Each ping carries an important boolean - true on status transitions and resend ticks (the beats that triggered notifications).

+
GET/monitors/:id/pings
+

Returns recent ping results for a monitor. Each ping carries an important boolean - true on status transitions and resend ticks (the beats that triggered notifications).

+ + + + + + + + +
ParamTypeDescription
limitnumberResults per page (default 100, max 1000).
skipnumberNumber of results to skip. Use with limit for pagination.
filterstringup, down, or events (state transitions only). Omit for all pings.
beforenumberUnix timestamp in seconds. Only returns pings older than this.