diff --git a/Cargo.toml b/Cargo.toml index 3c90993..c2bd1a1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ license-file = "LICENSE.txt" anyhow = "1.0" askama = { git = "https://github.com/djc/askama.git" } askama_axum = { git = "https://github.com/djc/askama.git", package = "askama_axum" } -axum = { version = "0.6", default-features = false, features = ["http1", "tokio", "macros"] } +axum = { version = "0.6", default-features = false, features = ["http1", "tokio", "macros", "query"] } axum-extra = { version = "0.4", features = ["spa"] } bytes = "1.3" chrono = { version = "0.4", default-features = false, features = ["clock"] } diff --git a/src/main.rs b/src/main.rs index bc69316..a708548 100644 --- a/src/main.rs +++ b/src/main.rs @@ -36,7 +36,6 @@ async fn init() -> Result<()> { let api_routes = Router::new().route("/trigger", post(routes::trigger)); let routes = Router::new() .route("/", get(routes::index)) - .route("/:id", get(routes::index_id)) .nest("/api", api_routes) .with_state(app_state); diff --git a/src/routes.rs b/src/routes.rs index daa170f..448d80b 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -1,10 +1,11 @@ use anyhow::Context; use askama_axum::IntoResponse; -use axum::extract::{Path, State}; +use axum::extract::{Query, State}; use axum::http::header::HeaderMap; use axum::response::Response; use bytes::Bytes; use hmac::{Hmac, Mac}; +use serde::Deserialize; use serde_json::Value; use sha2::Sha256; use std::process::Command; @@ -14,17 +15,20 @@ use tracing::info; use crate::{db, errors, states, templates}; -pub async fn index(State(db_state): State>) -> Result { - index_id(State(db_state), Path(-1)).await +#[derive(Deserialize)] +pub struct IndexQuery { + id: Option, } -pub async fn index_id( +pub async fn index( State(db_state): State>, - Path(id): Path, + query: Query, ) -> Result { - if id == 0 { - return Err("id=0 not allowed!".into()); - } + let id = match query.id { + Some(id) if id != 0 => id, + Some(_) => return Err("id=0 not allowed!".into()), + None => -1, + }; let hook_log = db::get_hook_log(&db_state.pool, id)?;