From 891e871b47a4c61200e40ff5b0284461aae7d9ba Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Sat, 29 Jun 2024 14:07:44 -0400 Subject: [PATCH] Simplify get_login_status and get_world_status --- src/bin/kawari-frontier.rs | 34 +++++++--------------------------- 1 file changed, 7 insertions(+), 27 deletions(-) diff --git a/src/bin/kawari-frontier.rs b/src/bin/kawari-frontier.rs index 121f0cf..dff4ce9 100644 --- a/src/bin/kawari-frontier.rs +++ b/src/bin/kawari-frontier.rs @@ -5,7 +5,7 @@ use axum::{ Router, routing::get, }; use serde::{Deserialize, Serialize}; -use kawari::config::Config; +use kawari::config::{Config, get_config}; #[derive(Debug, Clone, Serialize, Deserialize)] struct GateStatus { @@ -13,40 +13,20 @@ struct GateStatus { } async fn get_login_status() -> Json { - tracing::info!("Requesting gate status..."); - - let mut is_open = 0; - - // read config - if let Ok(data) = std::fs::read_to_string("config.json") { - let config: Config = serde_json::from_str(&data).expect("Failed to parse"); - - if config.login_open { - is_open = 1; - } - } + tracing::info!("Requesting login status..."); + let config = get_config(); Json(GateStatus { - status: is_open + status: config.login_open.into() }) } async fn get_world_status() -> Json { - tracing::info!("Requesting gate status..."); - - let mut is_open = 0; - - // read config - if let Ok(data) = std::fs::read_to_string("config.json") { - let config: Config = serde_json::from_str(&data).expect("Failed to parse"); - - if config.worlds_open { - is_open = 1; - } - } + tracing::info!("Requesting world status..."); + let config = get_config(); Json(GateStatus { - status: is_open + status: config.login_open.into() }) }