feat: list recent restore jobs across all snapshots
Add GET /api/v1/restore-jobs?limit= (admin only, newest first, default 50, at most 200) so the activity log can show restores without asking snapshot by snapshot. The existing history test now also covers ordering and the limit. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,7 +5,7 @@ use super::{
|
||||
use crate::state::HubState;
|
||||
use axum::{
|
||||
body::Body,
|
||||
extract::{rejection::JsonRejection, ConnectInfo, Path, State},
|
||||
extract::{rejection::JsonRejection, ConnectInfo, Path, Query, State},
|
||||
http::{header, HeaderMap, StatusCode},
|
||||
response::{IntoResponse, Response},
|
||||
routing::{get, post},
|
||||
@@ -29,7 +29,7 @@ pub(super) fn routes() -> Router<HubState> {
|
||||
.route("/api/v1/restore-targets", post(register))
|
||||
.route("/api/v1/capture-profiles/:id/restore-targets", get(targets))
|
||||
.route("/api/v1/snapshots/:id/restore-targets", get(snapshot_targets))
|
||||
.route("/api/v1/restore-jobs", post(enqueue))
|
||||
.route("/api/v1/restore-jobs", post(enqueue).get(recent))
|
||||
.route("/api/v1/snapshots/:id/restore-jobs", get(history))
|
||||
.route("/api/v1/restore-jobs/:id", get(job).delete(cancel))
|
||||
.route("/api/v1/restore-jobs/:id/reconcile", post(reconcile))
|
||||
@@ -222,6 +222,26 @@ async fn history(
|
||||
.map_err(internal)
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct Recent {
|
||||
limit: Option<u32>,
|
||||
}
|
||||
|
||||
/// The newest restore jobs across all snapshots. The activity log reads this instead of asking snapshot by snapshot.
|
||||
async fn recent(
|
||||
ConnectInfo(peer): ConnectInfo<SocketAddr>,
|
||||
State(state): State<HubState>,
|
||||
headers: HeaderMap,
|
||||
Query(query): Query<Recent>,
|
||||
) -> Result<Json<Vec<RestoreJob>>, StatusCode> {
|
||||
require_admin(&state, peer, &headers)?;
|
||||
state
|
||||
.db
|
||||
.restore_recent(query.limit.unwrap_or(50).clamp(1, 200), now())
|
||||
.map(Json)
|
||||
.map_err(internal)
|
||||
}
|
||||
|
||||
async fn cancel(
|
||||
ConnectInfo(peer): ConnectInfo<SocketAddr>,
|
||||
State(state): State<HubState>,
|
||||
|
||||
Reference in New Issue
Block a user