Get info from status page json

This commit is contained in:
Marco De Araujo 2025-12-22 11:40:28 -04:00
parent d024280878
commit dbe196f388
8 changed files with 113 additions and 30 deletions

View file

@ -1,28 +1,11 @@
use anyhow::{Context, Ok, Result};
use std::collections::HashMap;
use crate::i18n::t;
use super::HeartbeatResponse;
use crate::i18n::t;
use anyhow::{Context, Ok, Result};
pub fn parse_response(json_text: &str) -> Result<HeartbeatResponse> {
let mut response: HeartbeatResponse = serde_json::from_str(json_text)
.with_context(|| t("invalid-json-heartbeat"))?;
let mut response: HeartbeatResponse =
serde_json::from_str(json_text).with_context(|| t("invalid-json-heartbeat"))?;
response.process()?;
Ok(response)
}
pub fn status_to_string(status: u8) -> String {
match status {
1 => t("up"),
2 => t("down"),
_ => t("unknown"),
}
}
pub fn format_duration(duration_ms:Option<u64>) -> String {
match duration_ms {
Some(ms) if ms < 1000 => format!("{}ms", ms),
Some(ms) => format!("{:.1}s", ms),
None => "N/A".to_string(),
}
}