1
0
Fork 0
mirror of https://codeberg.org/Mo8it/git-webhook-client synced 2024-11-23 11:11:36 +00:00

Use query for id

This commit is contained in:
Mo 2022-12-05 23:44:48 +01:00
parent c3bc254924
commit 2c837e55d0
3 changed files with 13 additions and 10 deletions

View file

@ -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"] }

View file

@ -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);

View file

@ -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<Arc<states::DB>>) -> Result<Response, errors::AppError> {
index_id(State(db_state), Path(-1)).await
#[derive(Deserialize)]
pub struct IndexQuery {
id: Option<i32>,
}
pub async fn index_id(
pub async fn index(
State(db_state): State<Arc<states::DB>>,
Path(id): Path<i32>,
query: Query<IndexQuery>,
) -> Result<Response, errors::AppError> {
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)?;