all bullshit OUT
This commit is contained in:
1 parent
f4fcf7be65
commit
7371d2ae8c
7 files changed
+19
-26
No files matched your search
+9
-6
@@ -1,7 +1,7 @@
|
||||
use std::{fs::read_to_string, io, net::IpAddr};
|
||||
|
||||
use macaddr::MacAddr;
|
||||
use serde::Serializer;
|
||||
use std::io::{self, ErrorKind};
|
||||
use std::net::IpAddr;
|
||||
|
||||
/// A single line from /tmp/dhcp.leases
|
||||
#[derive(Debug, Clone, serde::Serialize)]
|
||||
@@ -34,8 +34,11 @@ pub fn parse_dhcp_lease_line(line: &str) -> Option<DhcpLeaseLine> {
|
||||
})
|
||||
}
|
||||
|
||||
/// Read all leases from /tmp/dhcp.leases
|
||||
pub fn read_dhcp_leases() -> io::Result<Vec<DhcpLeaseLine>> {
|
||||
let file = read_to_string("/tmp/dhcp.leases")?;
|
||||
Ok(file.lines().flat_map(parse_dhcp_lease_line).collect())
|
||||
/// Read all leases from /tmp/dhcp.leases (simple and fast)
|
||||
pub async fn read_dhcp_leases() -> io::Result<Vec<DhcpLeaseLine>> {
|
||||
match tokio::fs::read_to_string("/tmp/dhcp.leases").await {
|
||||
Ok(file) => Ok(file.lines().filter_map(parse_dhcp_lease_line).collect()),
|
||||
Err(e) if e.kind() == ErrorKind::NotFound => Ok(Vec::new()),
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
}
|
||||
@@ -46,7 +46,6 @@ pub fn home_2_route() -> Router {
|
||||
.route("/home_2.js", get(home_2_js)) //js
|
||||
}
|
||||
|
||||
|
||||
pub async fn wake_handler(
|
||||
Query(DeviceQuery { name, .. }): Query<DeviceQuery>,
|
||||
) -> axum::response::Result<impl IntoResponse> {
|
||||
@@ -60,7 +59,6 @@ pub async fn wake_handler(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub async fn _get_status_2(q: Query<DeviceQuery>) -> Html<String> {
|
||||
let name = match q {
|
||||
Query(DeviceQuery {
|
||||
@@ -96,5 +94,3 @@ pub async fn _home() -> Html<String> {
|
||||
// }
|
||||
))
|
||||
}
|
||||
|
||||
|
||||
+3
-11
@@ -55,9 +55,9 @@ pub async fn devs_router() -> Json<Vec<String>> {
|
||||
}
|
||||
|
||||
async fn get_dhcp_leases() -> impl IntoResponse {
|
||||
match tokio::task::spawn_blocking(dhcpparse::read_dhcp_leases).await {
|
||||
Ok(Ok(leases)) => (StatusCode::OK, Json(leases)).into_response(),
|
||||
Ok(Err(e)) => (
|
||||
match dhcpparse::read_dhcp_leases().await {
|
||||
Ok(leases) => (StatusCode::OK, Json(leases)).into_response(),
|
||||
Err(e) => (
|
||||
StatusCode::BAD_GATEWAY,
|
||||
Json(StatusError {
|
||||
name: None,
|
||||
@@ -65,14 +65,6 @@ async fn get_dhcp_leases() -> impl IntoResponse {
|
||||
}),
|
||||
)
|
||||
.into_response(),
|
||||
Err(join_err) => (
|
||||
StatusCode::BAD_GATEWAY,
|
||||
Json(StatusError {
|
||||
name: None,
|
||||
error: join_err.to_string(),
|
||||
}),
|
||||
)
|
||||
.into_response(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user