[WIP] A simple wake-on-lan service

add `info` config value to configure title and links planned design for WOL is also included in the commit

vielle.dev a3171f4f 68f41167

verified
+64 -2
design.webp

This is a binary file and will not be displayed.

+27 -1
src/config.rs
··· 14 14 binding: String, 15 15 #[serde(default = "default_theme")] 16 16 theme: Theme, 17 + #[serde(default = "default_info")] 18 + info: Info, 17 19 pinned: Option<Vec<String>>, 18 20 targets: HashMap<String, Target>, 19 21 } ··· 42 44 pub url: Option<String>, 43 45 } 44 46 47 + #[derive(Deserialize, Serialize, Debug, Clone)] 48 + pub struct Info { 49 + title: String, 50 + links: Vec<(String, String)>, 51 + icon: Option<PathBuf>, 52 + } 53 + 45 54 fn default_binding() -> String { 46 - "0.0.0.0:3000".to_string() 55 + String::from("0.0.0.0:3000") 47 56 } 48 57 49 58 fn default_theme() -> Theme { ··· 58 67 link_visited: (202, 158, 230), 59 68 highlight: (148, 156, 187), 60 69 highlight_opacity: 64, 70 + } 71 + } 72 + 73 + fn default_info() -> Info { 74 + Info { 75 + title: "WOL".into(), 76 + links: vec![ 77 + ( 78 + String::from("https://tangled.org/vielle.dev/wol/"), 79 + String::from("vielle.dev/wol"), 80 + ), 81 + ( 82 + String::from("https://tangled.org/vielle.dev/wol/tree/main/docs/README.md"), 83 + String::from("docs"), 84 + ), 85 + ], 86 + icon: None, 61 87 } 62 88 } 63 89
+26
src/utils.rs
··· 15 15 { 16 16 se.serialize_str(ip.to_string().as_str()) 17 17 } 18 + 19 + pub mod option { 20 + use super::*; 21 + 22 + pub fn deserialize<'de, D>(de: D) -> Result<Option<IpAddr>, D::Error> 23 + where 24 + D: Deserializer<'de>, 25 + { 26 + if let Some(str) = Option::<String>::deserialize(de)? { 27 + Ok(Some(IpAddr::from_str(&str).map_err(Error::custom)?)) 28 + } else { 29 + Ok(None) 30 + } 31 + } 32 + 33 + pub fn serialize<S>(ip: &Option<IpAddr>, se: S) -> Result<S::Ok, S::Error> 34 + where 35 + S: Serializer, 36 + { 37 + if let Some(ref ip) = *ip { 38 + se.serialize_str(ip.to_string().as_str()) 39 + } else { 40 + se.serialize_none() 41 + } 42 + } 43 + } 18 44 } 19 45 20 46 pub mod mac {
+6 -1
web/src/App.svelte
··· 20 20 21 21 <ThemeProvider /> 22 22 <main> 23 - <h1>Wake on Lan</h1> 23 + <h1>{config.info.title}</h1> 24 24 <ul> 25 25 {#each targets as [name, { mac, ip, url }]} 26 26 <li> 27 27 <Power {name} {mac} {ip} {url} /> 28 28 </li> 29 + {/each} 30 + </ul> 31 + <ul> 32 + {#each config.info.links as [href, text]} 33 + <li><a {href}>{text}</a></li> 29 34 {/each} 30 35 </ul> 31 36 </main>
+5
web/src/lib/api.ts
··· 78 78 highlight: colour, 79 79 highlight_opacity: u8, 80 80 }), 81 + info: z.object({ 82 + title: z.string(), 83 + links: z.array(z.tuple([z.string(), z.string()])), 84 + icon: z.string().nullable(), 85 + }), 81 86 pinned: z.array(z.string()).nullable(), 82 87 targets: z.record( 83 88 z.string(),