chatgpt tech

This commit is contained in:
lda
2025-12-08 23:02:33 +07:00 Unverified
parent af0682a1f0
commit 940614e14a
4 changed files with 35 additions and 16 deletions
+19 -3
View File
@@ -16,9 +16,13 @@ use crate::route::status::get_status_json;
use crate::route::wake::wake_multi;
use axum::Json;
use axum::response::IntoResponse;
use axum::routing::post;
use axum::{Router, http::header, response::Html, routing::get};
use axum::Router;
use axum::body::Body;
use axum::http::{Request, header};
use axum::middleware::{self, Next};
use axum::response::{Html, IntoResponse, Response};
use axum::routing::{get, post};
use std::time::Instant;
use crate::utils::route::serve_js;
@@ -51,6 +55,17 @@ pub fn home_2_route() -> Router {
.route("/home_2/dom.js", get(|| serve_js(home_2::DOM_JS)))
}
async fn add_performance_header(req: Request<Body>, next: Next) -> Response {
let start = Instant::now();
let mut response = next.run(req).await;
let elapsed = start.elapsed();
if let Ok(val) = format!("work-time={}us", elapsed.as_micros()).parse() {
response.headers_mut().insert("Lda-Performance", val);
}
response
}
pub fn api_router() -> Router {
Router::new()
.route("/status/{name}", get(status_redirect))
@@ -69,4 +84,5 @@ pub fn api_router() -> Router {
}
}),
)
.layer(middleware::from_fn(add_performance_header))
}
+6 -8
View File
@@ -10,35 +10,33 @@ pub struct DhcpLeaseOut {
#[serde(flatten)]
pub lease_line: DhcpLeaseLine,
pub nud_state: Option<NUDState>,
pub rank: Option<u8>,
}
/// Enrich DHCP leases with NUD state and rank using get_macs
pub async fn enrich_leases_with_nud_state(leases: Vec<DhcpLeaseLine>) -> Vec<DhcpLeaseOut> {
let ips: Vec<IpAddr> = leases.iter().map(|l| l.ip).collect();
let mut map: std::collections::HashMap<IpAddr, (NUDState, u8)> =
std::collections::HashMap::new();
let mut map: std::collections::HashMap<IpAddr, NUDState> = std::collections::HashMap::new();
if let Ok(rows) = get_macs(&[] as &[&str], &ips, &[] as &[&str], &[], &[]).await {
for row in rows {
let state = row.state;
let r = state.rank();
map.entry(row.ip)
.and_modify(|e| {
if r > e.1 {
*e = (state, r)
let er = e.rank();
if r > er {
*e = state
}
})
.or_insert((state, r));
.or_insert(state);
}
}
leases
.into_iter()
.map(|lease_line| {
let (nud_state, rank) = map.get(&lease_line.ip).copied().unzip();
let nud_state = map.get(&lease_line.ip).copied();
DhcpLeaseOut {
lease_line,
nud_state,
rank,
}
})
.collect()
+1 -1
View File
@@ -1,4 +1,4 @@
import { filter_array } from "./status.js";
// import { filter_array } from "./status.js";
export const qs = new URLSearchParams(location.search);
+6 -1
View File
@@ -1,4 +1,5 @@
import { elLeases } from "./dom.js";
import { rankState } from "./utils.js";
/**
*
@@ -36,7 +37,11 @@ export function renderLeases(leases) {
let dotClass = "dot ok";
if (expired) {
dotClass = "dot bad";
} /* rank from NUDState */ else if (typeof l?.rank === "number") {
} else if (l?.nud_state) {
if (rankState(l.nud_state) >= 5) dotClass = "dot ok";
else if (rankState(l.nud_state) >= 2) dotClass = "dot warn";
else dotClass = "dot bad";
} else if (typeof l?.rank === "number") {
if (l.rank >= 5) dotClass = "dot ok";
else if (l.rank >= 2) dotClass = "dot warn";
else dotClass = "dot bad";