diff options
author | FxQnLr <[email protected]> | 2024-02-15 17:17:30 +0100 |
---|---|---|
committer | FxQnLr <[email protected]> | 2024-02-15 17:17:30 +0100 |
commit | 3bc7cf8ed36016ca3da9438a98f4fe8b8e6f9e61 (patch) | |
tree | 48a38a52ebfc41fadab439b9a87fae3d43f78790 /src/routes/start.rs | |
parent | c663810817183c8f92a4279236ca84d271365088 (diff) | |
download | webol-3bc7cf8ed36016ca3da9438a98f4fe8b8e6f9e61.tar webol-3bc7cf8ed36016ca3da9438a98f4fe8b8e6f9e61.tar.gz webol-3bc7cf8ed36016ca3da9438a98f4fe8b8e6f9e61.zip |
Closes #10 & #12. Added `thiserror` crate and changed to `IntoSocketAddr` for easier usage and error handling
Diffstat (limited to 'src/routes/start.rs')
-rw-r--r-- | src/routes/start.rs | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/src/routes/start.rs b/src/routes/start.rs index ce95bf3..66b7cb4 100644 --- a/src/routes/start.rs +++ b/src/routes/start.rs | |||
@@ -20,7 +20,7 @@ pub async fn start( | |||
20 | ) -> Result<Json<Value>, Error> { | 20 | ) -> Result<Json<Value>, Error> { |
21 | info!("POST request"); | 21 | info!("POST request"); |
22 | let secret = headers.get("authorization"); | 22 | let secret = headers.get("authorization"); |
23 | let authorized = auth(&state.config, secret).map_err(Error::Auth)?; | 23 | let authorized = auth(&state.config, secret)?; |
24 | if authorized { | 24 | if authorized { |
25 | let device = sqlx::query_as!( | 25 | let device = sqlx::query_as!( |
26 | Device, | 26 | Device, |
@@ -32,16 +32,15 @@ pub async fn start( | |||
32 | payload.id | 32 | payload.id |
33 | ) | 33 | ) |
34 | .fetch_one(&state.db) | 34 | .fetch_one(&state.db) |
35 | .await | 35 | .await?; |
36 | .map_err(Error::DB)?; | ||
37 | 36 | ||
38 | info!("starting {}", device.id); | 37 | info!("starting {}", device.id); |
39 | 38 | ||
40 | let bind_addr = "0.0.0.0:0"; | 39 | let bind_addr = "0.0.0.0:0"; |
41 | 40 | ||
42 | let _ = send_packet( | 41 | let _ = send_packet( |
43 | &bind_addr.parse().map_err(Error::IpParse)?, | 42 | bind_addr, |
44 | &device.broadcast_addr.parse().map_err(Error::IpParse)?, | 43 | &device.broadcast_addr, |
45 | &create_buffer(&device.mac)?, | 44 | &create_buffer(&device.mac)?, |
46 | )?; | 45 | )?; |
47 | let dev_id = device.id.clone(); | 46 | let dev_id = device.id.clone(); |