fix: docs

This commit is contained in:
nate 2026-04-09 22:00:46 +04:00
parent 79ba63d86b
commit 7877b14f85
2 changed files with 18 additions and 7 deletions

View File

@ -197,21 +197,23 @@ export const monitors = new Elysia({ prefix: "/monitors" })
if (!monitor) { set.status = 404; return { error: "Not found" }; } if (!monitor) { set.status = 404; return { error: "Not found" }; }
const limit = Math.min(Number(query.limit) || 100, 1000); 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 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 cursorClause = before ? sql`AND checked_at < ${new Date(before)}` : sql``;
const offsetClause = skip > 0 ? sql`OFFSET ${skip}` : sql``;
if (filter === "up") { if (filter === "up") {
return sql` return sql`
SELECT * FROM pings WHERE monitor_id = ${params.id} AND up = true ${cursorClause} 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") { if (filter === "down") {
return sql` return sql`
SELECT * FROM pings WHERE monitor_id = ${params.id} AND up = false ${cursorClause} 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") { if (filter === "events") {
@ -222,12 +224,12 @@ export const monitors = new Elysia({ prefix: "/monitors" })
) t ) t
WHERE prev_up IS NULL OR up != prev_up WHERE prev_up IS NULL OR up != prev_up
${before ? sql`AND checked_at < ${new Date(before)}` : sql``} ${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` return sql`
SELECT * FROM pings WHERE monitor_id = ${params.id} ${cursorClause} 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"] } }); }, { detail: { summary: "Get ping history", tags: ["monitors"] } });

View File

@ -187,8 +187,17 @@
<p class="endpoint-desc">Enable or disable a monitor without deleting it.</p> <p class="endpoint-desc">Enable or disable a monitor without deleting it.</p>
<h3>Ping History</h3> <h3>Ping History</h3>
<div class="endpoint"><span class="method get">GET</span><span class="path">/monitors/:id/pings?limit=100</span></div> <div class="endpoint"><span class="method get">GET</span><span class="path">/monitors/:id/pings</span></div>
<p class="endpoint-desc">Returns recent ping results for a monitor. Max 1000. Each ping carries an <code>important</code> boolean - true on status transitions and resend ticks (the beats that triggered notifications).</p> <p class="endpoint-desc">Returns recent ping results for a monitor. Each ping carries an <code>important</code> boolean - true on status transitions and resend ticks (the beats that triggered notifications).</p>
<table>
<thead><tr><th>Param</th><th>Type</th><th>Description</th></tr></thead>
<tbody>
<tr><td>limit</td><td>number</td><td>Results per page (default 100, max 1000).</td></tr>
<tr><td>skip</td><td>number</td><td>Number of results to skip. Use with <code>limit</code> for pagination.</td></tr>
<tr><td>filter</td><td>string</td><td><code>up</code>, <code>down</code>, or <code>events</code> (state transitions only). Omit for all pings.</td></tr>
<tr><td>before</td><td>number</td><td>Unix timestamp in seconds. Only returns pings older than this.</td></tr>
</tbody>
</table>
</div> </div>
<!-- Notifications --> <!-- Notifications -->