summaryrefslogtreecommitdiff
path: root/src/routes/start.rs
blob: cda6352e0f838ea90767bff0ec1d4714acd4e781 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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<StartPayload>) -> Json<Value> {
    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<bool>,
}

#[derive(Serialize)]
struct StartResponse {
    id: String,
    boot: bool,
}