fuhh
This commit is contained in:
1 parent
fc6548e15c
commit
af0682a1f0
7 files changed
+51
-55
No files matched your search
+12
-6
@@ -53,13 +53,19 @@ impl From<NUDState> for ipjs_neigh::NUDState {
|
||||
}
|
||||
|
||||
impl From<NeighborItem> for IpNeighLine {
|
||||
fn from(item: NeighborItem) -> Self {
|
||||
fn from(
|
||||
NeighborItem {
|
||||
ip,
|
||||
dev,
|
||||
mac,
|
||||
state,
|
||||
}: NeighborItem,
|
||||
) -> Self {
|
||||
IpNeighLine {
|
||||
ip: item.ip,
|
||||
dev: Some(item.dev),
|
||||
mac: item.mac,
|
||||
state: item
|
||||
.state
|
||||
ip,
|
||||
dev,
|
||||
mac,
|
||||
state: state
|
||||
.first()
|
||||
.copied()
|
||||
.map(Into::into)
|
||||
|
||||
+20
-30
@@ -50,45 +50,35 @@ pub struct Filters {
|
||||
pub async fn get_status_json(
|
||||
Query(DeviceQuery {
|
||||
name,
|
||||
filter:
|
||||
Filters {
|
||||
ips,
|
||||
devs,
|
||||
nuds,
|
||||
macs,
|
||||
},
|
||||
filter: filters,
|
||||
..
|
||||
}): Query<DeviceQuery>,
|
||||
) -> impl IntoResponse {
|
||||
match get_macs(
|
||||
&name.iter().collect::<Vec<_>>(),
|
||||
&ips,
|
||||
&devs.iter().collect::<Vec<_>>(),
|
||||
&nuds,
|
||||
&macs,
|
||||
name.as_slice(),
|
||||
&filters.ips,
|
||||
&filters.devs,
|
||||
&filters.nuds,
|
||||
&filters.macs,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(table) => {
|
||||
let filters = Filters {
|
||||
ips,
|
||||
devs,
|
||||
nuds,
|
||||
macs,
|
||||
};
|
||||
(
|
||||
StatusCode::OK,
|
||||
Json(Status {
|
||||
name,
|
||||
table,
|
||||
filters,
|
||||
}),
|
||||
)
|
||||
.into_response()
|
||||
}
|
||||
Ok(table) => (
|
||||
StatusCode::OK,
|
||||
Json(Status {
|
||||
name,
|
||||
table,
|
||||
filters,
|
||||
}),
|
||||
)
|
||||
.into_response(),
|
||||
Err(error) => ApiError {
|
||||
code: StatusCode::BAD_GATEWAY,
|
||||
error: error.to_string(),
|
||||
error: error
|
||||
.chain()
|
||||
.map(ToString::to_string)
|
||||
.collect::<Vec<_>>()
|
||||
.join(": "),
|
||||
}
|
||||
.into_response(),
|
||||
}
|
||||
|
||||
+1
-14
@@ -107,20 +107,7 @@ pub async fn get_mac(
|
||||
.await
|
||||
.context("Calling ip -j neigh failed")?;
|
||||
|
||||
let lines = items
|
||||
.into_iter()
|
||||
.map(|item| IpNeighLine {
|
||||
ip: item.ip,
|
||||
dev: Some(item.dev),
|
||||
mac: item.mac,
|
||||
state: item
|
||||
.state
|
||||
.first()
|
||||
.copied()
|
||||
.map(Into::into)
|
||||
.unwrap_or(NUDState::None),
|
||||
})
|
||||
.collect();
|
||||
let lines = items.into_iter().map(Into::into).collect();
|
||||
|
||||
Ok(lines)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user