From 22d45961625a4eceefd2ff4d2f43fb0b768406d4 Mon Sep 17 00:00:00 2001 From: shockrah Date: Tue, 28 Apr 2026 00:55:25 -0700 Subject: [PATCH] Creating blank Monitor objects --- src/api.rs | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/api.rs b/src/api.rs index 8cac291..26d6474 100644 --- a/src/api.rs +++ b/src/api.rs @@ -14,10 +14,18 @@ macro_rules! endpoints { ($slug:expr) => { format!("{}/api/status-page/{}", crate::api::BASE_URL, $slug) } } +#[derive(Debug)] +pub struct HeartBeat { + status: i64, + time: String, + msg: String, +} + #[derive(Debug)] pub struct KumaMonitor { id: i64, name: String, + heartbeats: Option> } #[derive(Debug)] @@ -28,15 +36,23 @@ pub struct KumaStatusPage { monitors: Vec } +impl KumaMonitor { + pub fn blank(val: &Value) -> Self { + Self { + id: val["id"].as_i64().unwrap_or(0), + name: val["name"].to_string(), + heartbeats: None + } + } +} + + impl KumaStatusPage { fn get_monitors(json: &Value) -> Vec { let mut monitors = vec![]; for group in json["publicGroupList"].as_array().unwrap_or(&vec![]) { for monitor in group["monitorList"].as_array().unwrap_or(&vec![]) { - monitors.push(KumaMonitor { - id: monitor["id"].as_i64().unwrap_or(0), - name: monitor["name"].to_string() - }); + monitors.push(KumaMonitor::blank(&monitor)); } } return monitors; @@ -53,3 +69,4 @@ impl KumaStatusPage { }) } } +