[WIP] A simple wake-on-lan service
at main 21 lines 583 B view raw
1use axum::{Json, response::Response}; 2use serde::Deserialize; 3 4use crate::mac::MacAddress; 5 6#[derive(Deserialize)] 7pub struct WakeRequest { 8 #[serde(with = "crate::utils::mac")] 9 mac: MacAddress, 10} 11 12pub async fn main(Json(req): Json<WakeRequest>) -> Result<Json<bool>, Response<String>> { 13 println!("Waking {}", req.mac); 14 req.mac.wake().await.map(|_| Json(true)).map_err(|err| { 15 Response::builder() 16 .status(500) 17 .body(err.to_string()) 18 // unwrap is safe since this will always be a valid respose 19 .unwrap() 20 }) 21}