From d3cf93fb6c9b7e0faf9b7907328f0a042009e164 Mon Sep 17 00:00:00 2001 From: FxQnLr Date: Mon, 15 Apr 2024 20:33:32 +0200 Subject: Closes #35. Entry of Ip optional, error on ping request without saved ip --- src/routes/start.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/routes/start.rs') diff --git a/src/routes/start.rs b/src/routes/start.rs index bbc6ab8..192a54a 100644 --- a/src/routes/start.rs +++ b/src/routes/start.rs @@ -69,6 +69,9 @@ fn send_wol( let dev_id = device.id.clone(); let uuid = if let Some(pl) = payload { if pl.ping.is_some_and(|ping| ping) { + if device.ip.is_none() { + return Err(Error::NoIpOnPing); + } Some(setup_ping(state, device)) } else { None @@ -86,8 +89,10 @@ fn send_wol( fn setup_ping(state: Arc, device: Device) -> String { let mut uuid: Option = None; + // Safe: Only called when ip is set + let ip = device.ip.unwrap(); for (key, value) in state.ping_map.clone() { - if value.ip == device.ip { + if value.ip == ip { debug!("service already exists"); uuid = Some(key); break; @@ -103,7 +108,7 @@ fn setup_ping(state: Arc, device: Device) -> String { state.ping_map.insert( uuid_gen.clone(), PingValue { - ip: device.ip, + ip, eta: get_eta(device.clone().times), online: false, }, -- cgit v1.2.3