diff options
Diffstat (limited to 'src/routes')
-rw-r--r-- | src/routes/mod.rs | 1 | ||||
-rw-r--r-- | src/routes/start.rs | 29 |
2 files changed, 30 insertions, 0 deletions
diff --git a/src/routes/mod.rs b/src/routes/mod.rs new file mode 100644 index 0000000..78d4375 --- /dev/null +++ b/src/routes/mod.rs | |||
@@ -0,0 +1 @@ | |||
pub mod start; \ No newline at end of file | |||
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 @@ | |||
1 | use axum::headers::HeaderMap; | ||
2 | use axum::Json; | ||
3 | use serde::{Deserialize, Serialize}; | ||
4 | use serde_json::{json, Value}; | ||
5 | use crate::auth::auth; | ||
6 | |||
7 | pub async fn start(headers: HeaderMap, Json(payload): Json<StartPayload>) -> Json<Value> { | ||
8 | let mut res = StartResponse { id: payload.id, boot: false }; | ||
9 | if let Some(secret) = headers.get("authorization") { | ||
10 | if !auth(secret.to_str().unwrap()) { Json(json!(res)) } else { | ||
11 | res.boot = true; | ||
12 | Json(json!(res)) | ||
13 | } | ||
14 | } else { | ||
15 | Json(json!(res)) | ||
16 | } | ||
17 | } | ||
18 | |||
19 | #[derive(Deserialize)] | ||
20 | pub struct StartPayload { | ||
21 | id: String, | ||
22 | _test: Option<bool>, | ||
23 | } | ||
24 | |||
25 | #[derive(Serialize)] | ||
26 | struct StartResponse { | ||
27 | id: String, | ||
28 | boot: bool, | ||
29 | } | ||