mirror of
https://codeberg.org/Mo8it/git-webhook-client
synced 2024-11-24 11:21:36 +00:00
Use query for id
This commit is contained in:
parent
c3bc254924
commit
2c837e55d0
3 changed files with 13 additions and 10 deletions
|
@ -11,7 +11,7 @@ license-file = "LICENSE.txt"
|
||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
askama = { git = "https://github.com/djc/askama.git" }
|
askama = { git = "https://github.com/djc/askama.git" }
|
||||||
askama_axum = { git = "https://github.com/djc/askama.git", package = "askama_axum" }
|
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"] }
|
axum-extra = { version = "0.4", features = ["spa"] }
|
||||||
bytes = "1.3"
|
bytes = "1.3"
|
||||||
chrono = { version = "0.4", default-features = false, features = ["clock"] }
|
chrono = { version = "0.4", default-features = false, features = ["clock"] }
|
||||||
|
|
|
@ -36,7 +36,6 @@ async fn init() -> Result<()> {
|
||||||
let api_routes = Router::new().route("/trigger", post(routes::trigger));
|
let api_routes = Router::new().route("/trigger", post(routes::trigger));
|
||||||
let routes = Router::new()
|
let routes = Router::new()
|
||||||
.route("/", get(routes::index))
|
.route("/", get(routes::index))
|
||||||
.route("/:id", get(routes::index_id))
|
|
||||||
.nest("/api", api_routes)
|
.nest("/api", api_routes)
|
||||||
.with_state(app_state);
|
.with_state(app_state);
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use askama_axum::IntoResponse;
|
use askama_axum::IntoResponse;
|
||||||
use axum::extract::{Path, State};
|
use axum::extract::{Query, State};
|
||||||
use axum::http::header::HeaderMap;
|
use axum::http::header::HeaderMap;
|
||||||
use axum::response::Response;
|
use axum::response::Response;
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use hmac::{Hmac, Mac};
|
use hmac::{Hmac, Mac};
|
||||||
|
use serde::Deserialize;
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use sha2::Sha256;
|
use sha2::Sha256;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
@ -14,17 +15,20 @@ use tracing::info;
|
||||||
|
|
||||||
use crate::{db, errors, states, templates};
|
use crate::{db, errors, states, templates};
|
||||||
|
|
||||||
pub async fn index(State(db_state): State<Arc<states::DB>>) -> Result<Response, errors::AppError> {
|
#[derive(Deserialize)]
|
||||||
index_id(State(db_state), Path(-1)).await
|
pub struct IndexQuery {
|
||||||
|
id: Option<i32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn index_id(
|
pub async fn index(
|
||||||
State(db_state): State<Arc<states::DB>>,
|
State(db_state): State<Arc<states::DB>>,
|
||||||
Path(id): Path<i32>,
|
query: Query<IndexQuery>,
|
||||||
) -> Result<Response, errors::AppError> {
|
) -> Result<Response, errors::AppError> {
|
||||||
if id == 0 {
|
let id = match query.id {
|
||||||
return Err("id=0 not allowed!".into());
|
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)?;
|
let hook_log = db::get_hook_log(&db_state.pool, id)?;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue