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.
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).
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).
| Param | Type | Description |
|---|---|---|
| limit | number | Results per page (default 100, max 1000). |
| skip | number | Number of results to skip. Use with limit for pagination. |
| filter | string | up, down, or events (state transitions only). Omit for all pings. |
| before | number | Unix timestamp in seconds. Only returns pings older than this. |