Get info from status page json
This commit is contained in:
parent
d024280878
commit
dbe196f388
8 changed files with 113 additions and 30 deletions
4
src/status_page/mod.rs
Normal file
4
src/status_page/mod.rs
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
pub mod model;
|
||||
pub mod parser;
|
||||
pub use model::StatusPageResponse;
|
||||
pub use parser::parse_response;
|
||||
61
src/status_page/model.rs
Normal file
61
src/status_page/model.rs
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::i18n::t;
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
pub struct StatusPageConfig {
|
||||
pub slug: String,
|
||||
pub title: String,
|
||||
#[serde(default)]
|
||||
pub description: Option<String>,
|
||||
pub icon: String,
|
||||
#[serde(rename = "autoRefreshInterval")]
|
||||
pub auto_refresh_interval: u32,
|
||||
pub theme: String,
|
||||
pub published: bool,
|
||||
#[serde(rename = "showTags")]
|
||||
pub show_tags: bool,
|
||||
#[serde(rename = "customCSS")]
|
||||
pub custon_css: String,
|
||||
#[serde(rename = "footerText", default)]
|
||||
pub footer_text: Option<String>,
|
||||
#[serde(rename = "showPoweredBy")]
|
||||
pub show_powered_by: bool,
|
||||
#[serde(rename = "googleAnalyticsId", default)]
|
||||
pub google_analytics_id: Option<String>,
|
||||
#[serde(rename = "showCertificateExpiry")]
|
||||
pub show_certificate_expiry: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
pub struct MonitorInfo {
|
||||
pub id: u64,
|
||||
pub name: String,
|
||||
#[serde(rename = "sendUrl")]
|
||||
pub send_url: u8,
|
||||
#[serde(rename = "type")]
|
||||
pub monitor_type: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
pub struct StatusPageGroup {
|
||||
pub id: u64,
|
||||
pub name: String,
|
||||
pub weight: u32,
|
||||
#[serde(rename = "monitorList")]
|
||||
pub monitor_list: Vec<MonitorInfo>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
pub struct StatusPageResponse {
|
||||
pub config: StatusPageConfig,
|
||||
#[serde(skip, default)]
|
||||
pub incident: Option<String>,
|
||||
#[serde(rename = "publicGroupList")]
|
||||
pub public_group_list: Vec<StatusPageGroup>,
|
||||
#[serde(rename = "maintenanceList", skip)]
|
||||
pub maintenance_list: Vec<String>,
|
||||
}
|
||||
8
src/status_page/parser.rs
Normal file
8
src/status_page/parser.rs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
use super::model::StatusPageResponse;
|
||||
use crate::i18n::t;
|
||||
use anyhow::{Context, Ok, Result};
|
||||
|
||||
pub fn parse_response(json_text: &str) -> Result<StatusPageResponse> {
|
||||
let mut response: StatusPageResponse = serde_json::from_str(json_text)?; //.with_context(|| t("invalid-json-status-page"))?;
|
||||
Ok(response)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue