diff --git a/liveman/src/route/node.rs b/liveman/src/route/node.rs index fd73c55..a0d1b62 100644 --- a/liveman/src/route/node.rs +++ b/liveman/src/route/node.rs @@ -1,6 +1,8 @@ use axum::{extract::State, Json}; use serde::{Deserialize, Serialize}; +use api::strategy::Strategy; + use crate::{result::Result, AppState}; #[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)] @@ -14,30 +16,32 @@ pub enum NodeState { #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] pub struct Node { - pub alias: String, - pub url: String, - pub pub_max: u16, - pub sub_max: u16, - pub status: NodeState, + alias: String, + url: String, + status: NodeState, + strategy: Strategy, + duration: String, } pub async fn index(State(mut state): State) -> Result>> { - let map_info = state.storage.info_raw_all().await.unwrap(); - + state.storage.nodes().await; Ok(Json( state .storage - .get_cluster() + .get_map_nodes() .into_iter() - .map(|x| Node { - alias: x.alias.clone(), - url: x.url, - pub_max: x.pub_max, - sub_max: x.sub_max, - status: match map_info.get(&x.alias) { + .map(|(alias, node)| Node { + alias, + url: node.url, + status: match node.strategy { Some(_) => NodeState::Running, None => NodeState::Stopped, }, + strategy: node.strategy.unwrap_or_default(), + duration: match node.duration { + Some(s) => format!("{}", s.as_millis()), + None => Default::default(), + }, }) .collect(), )) diff --git a/liveman/src/store.rs b/liveman/src/store.rs index 7ce6770..9b65c33 100644 --- a/liveman/src/store.rs +++ b/liveman/src/store.rs @@ -32,8 +32,8 @@ pub struct Node { pub url: String, streams: Vec, - strategy: Option, - duration: Option, + pub strategy: Option, + pub duration: Option, } impl Node { diff --git a/web/liveman/api.ts b/web/liveman/api.ts index abc6b8c..bc0154b 100644 --- a/web/liveman/api.ts +++ b/web/liveman/api.ts @@ -23,8 +23,8 @@ export function login(username: string, password: string) { export interface Node { alias: string; url: string; - pub_max: number; - sub_max: number; + duration: string; + strategy: Record, status: 'running' | 'stopped'; } diff --git a/web/liveman/components/nodes-table.tsx b/web/liveman/components/nodes-table.tsx index 563924a..ce09711 100644 --- a/web/liveman/components/nodes-table.tsx +++ b/web/liveman/components/nodes-table.tsx @@ -1,7 +1,7 @@ import { useRefreshTimer } from '../../shared/hooks/use-refresh-timer'; import { StyledCheckbox } from '../../shared/components/styled-checkbox'; -import { getNodes } from '../api'; +import { type Node, getNodes } from '../api'; async function getNodesSorted() { const nodes = await getNodes(); @@ -24,8 +24,8 @@ export function NodesTable() { Alias Status - Max Publish Cnt. - Max subscribe Cnt. + Delay + Strategy API URL @@ -34,8 +34,10 @@ export function NodesTable() { {n.alias} {n.status} - {n.pub_max} - {n.sub_max} + {n.duration}ms + + + {n.url} ))} @@ -45,3 +47,22 @@ export function NodesTable() { ); } + +type NodeStrategyTableProps = Pick; + +function NodeStrategyTable({ strategy }: NodeStrategyTableProps) { + return ( +
+ + + {Object.entries(strategy).map(([k, v]) => ( + + + + + ))} + +
{k}{`${v}`}
+
+ ); +}