aboutsummaryrefslogtreecommitdiff
path: root/src/routes/start.rs
diff options
context:
space:
mode:
authorfx <[email protected]>2023-10-25 12:53:31 +0200
committerfx <[email protected]>2023-10-25 12:53:31 +0200
commit00dd8a9abee6b9f0cfc37c6f20f30f0d99dfe91a (patch)
tree7906b5836f3ca24686b1b7418c2128b93c33a398 /src/routes/start.rs
parentf9224ff02e688dec819ab81893320a0611f2a198 (diff)
downloadwebol-00dd8a9abee6b9f0cfc37c6f20f30f0d99dfe91a.tar
webol-00dd8a9abee6b9f0cfc37c6f20f30f0d99dfe91a.tar.gz
webol-00dd8a9abee6b9f0cfc37c6f20f30f0d99dfe91a.zip
runs, no error handling
Diffstat (limited to 'src/routes/start.rs')
-rw-r--r--src/routes/start.rs24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/routes/start.rs b/src/routes/start.rs
index 863ef16..45e7ec8 100644
--- a/src/routes/start.rs
+++ b/src/routes/start.rs
@@ -4,15 +4,18 @@ use serde::{Deserialize, Serialize};
4use std::sync::Arc; 4use std::sync::Arc;
5use axum::extract::State; 5use axum::extract::State;
6use serde_json::{json, Value}; 6use serde_json::{json, Value};
7use tracing::{debug, info}; 7use tracing::{debug, info, warn};
8use uuid::Uuid;
8use crate::auth::auth; 9use crate::auth::auth;
9use crate::config::SETTINGS; 10use crate::config::SETTINGS;
10use crate::wol::{create_buffer, send_packet}; 11use crate::wol::{create_buffer, send_packet};
11use crate::db::Device; 12use crate::db::Device;
12use crate::error::WebolError; 13use crate::error::WebolError;
13 14
15#[axum_macros::debug_handler]
14pub async fn start(State(state): State<Arc<crate::AppState>>, headers: HeaderMap, Json(payload): Json<StartPayload>) -> Result<Json<Value>, WebolError> { 16pub async fn start(State(state): State<Arc<crate::AppState>>, headers: HeaderMap, Json(payload): Json<StartPayload>) -> Result<Json<Value>, WebolError> {
15 info!("POST request"); 17 info!("POST request");
18 warn!("{:?}", state.ping_map);
16 let secret = headers.get("authorization"); 19 let secret = headers.get("authorization");
17 let authorized = auth(secret).map_err(WebolError::Auth)?; 20 let authorized = auth(secret).map_err(WebolError::Auth)?;
18 if authorized { 21 if authorized {
@@ -38,14 +41,20 @@ pub async fn start(State(state): State<Arc<crate::AppState>>, headers: HeaderMap
38 create_buffer(&device.mac)? 41 create_buffer(&device.mac)?
39 )?; 42 )?;
40 43
41 if payload.ping.is_some_and(|ping| ping) { 44 let uuid = if payload.ping.is_some_and(|ping| ping) {
42 debug!("ping true"); 45 let uuid_gen = Uuid::new_v4().to_string();
43 tokio::spawn(async move { 46 let uuid_genc = uuid_gen.clone();
47 tokio::spawn(async move{
44 debug!("Init ping service"); 48 debug!("Init ping service");
45 crate::services::ping::spawn(state.ping_send.clone()).await 49 state.ping_map.lock().await.insert(uuid_gen, ("192.168.178.94".to_string(), false));
50
51 warn!("{:?}", state.ping_map);
52
53 crate::services::ping::spawn(state.ping_send.clone(), "192.168.178.94".to_string()).await;
46 }); 54 });
47 }; 55 Some(uuid_genc)
48 Ok(Json(json!(StartResponse { id: device.id, boot: true }))) 56 } else { None };
57 Ok(Json(json!(StartResponse { id: device.id, boot: true, uuid })))
49 } else { 58 } else {
50 Err(WebolError::Generic) 59 Err(WebolError::Generic)
51 } 60 }
@@ -61,4 +70,5 @@ pub struct StartPayload {
61struct StartResponse { 70struct StartResponse {
62 id: String, 71 id: String,
63 boot: bool, 72 boot: bool,
73 uuid: Option<String>,
64} 74}