From 920496c85bdf0d017eaf837cbacd136d7d828669 Mon Sep 17 00:00:00 2001 From: fx Date: Sun, 8 Oct 2023 23:28:10 +0200 Subject: base web server --- src/routes/start.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/routes/start.rs (limited to 'src/routes/start.rs') diff --git a/src/routes/start.rs b/src/routes/start.rs new file mode 100644 index 0000000..cda6352 --- /dev/null +++ b/src/routes/start.rs @@ -0,0 +1,29 @@ +use axum::headers::HeaderMap; +use axum::Json; +use serde::{Deserialize, Serialize}; +use serde_json::{json, Value}; +use crate::auth::auth; + +pub async fn start(headers: HeaderMap, Json(payload): Json) -> Json { + let mut res = StartResponse { id: payload.id, boot: false }; + if let Some(secret) = headers.get("authorization") { + if !auth(secret.to_str().unwrap()) { Json(json!(res)) } else { + res.boot = true; + Json(json!(res)) + } + } else { + Json(json!(res)) + } +} + +#[derive(Deserialize)] +pub struct StartPayload { + id: String, + _test: Option, +} + +#[derive(Serialize)] +struct StartResponse { + id: String, + boot: bool, +} -- cgit v1.2.3