From: Greg Burri Date: Wed, 17 Mar 2021 20:50:39 +0000 (+0100) Subject: Add the date and time of the latest backup. X-Git-Url: http://git.euphorik.ch/index.cgi?a=commitdiff_plain;h=28dede5779342bac9b4767d61badac099b1595c2;p=valheim_web.git Add the date and time of the latest backup. --- diff --git a/backend/src/main.rs b/backend/src/main.rs index a2201d4..8ea0819 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -28,15 +28,15 @@ struct MainTemplate { const VALUE_UNKNOWN: &str = "-"; #[cached(size = 1, time = 10)] -fn get_valheim_executable_information_cached(world_path: String) -> Option { - valheim_controller::get_valheim_executable_information(&world_path) +fn get_valheim_executable_information_cached(world_path: String, backup_path: String) -> Option { + valheim_controller::get_valheim_executable_information(&world_path, &backup_path) } #[get("/")] async fn main_page(config_shared: web::Data>) -> impl Responder { let config = config_shared.lock().unwrap(); - match get_valheim_executable_information_cached(config.world_path.clone()) { + match get_valheim_executable_information_cached(config.world_path.clone(), config.backup_path.clone()) { Some(info) => MainTemplate { text_status: String::from("Valheim server is up and running :)"), diff --git a/backend/src/valheim_controller.rs b/backend/src/valheim_controller.rs index 3d99033..04f75a4 100644 --- a/backend/src/valheim_controller.rs +++ b/backend/src/valheim_controller.rs @@ -1,5 +1,8 @@ use sysinfo::{ ProcessExt, SystemExt }; -use chrono::{ DateTime, Datelike, Timelike, Utc }; + +use std::{ fs, time::SystemTime }; + +use chrono::{ DateTime, offset::Local }; #[cfg(target_os = "unix")] use systemd::journal; @@ -11,7 +14,7 @@ pub struct ValheimExe { uptime: u64, // [s]. world_size: u64, // [B]. nb_of_players: u32, - last_backup: DateTime, + last_backup: Option, } impl ValheimExe { @@ -39,7 +42,13 @@ impl ValheimExe { } pub fn format_last_backup(&self) -> String { - string::from("") + match self.last_backup { + Some(t) => { + let datetime: DateTime = t.into(); + datetime.format("%d/%m/%Y %T").to_string() + }, + None => String::from("?") + } } } @@ -96,8 +105,19 @@ fn get_number_of_players() -> u32 { 0 } -fn get_last_backup_datetime(backup_path: &str) -> DateTime { +fn get_last_backup_datetime(backup_path: &str) -> Option { + let mut times = + fs::read_dir(backup_path).ok()?.filter_map( + |e| { + let dir = e.ok()?; + if dir.path().is_file() { Some(dir.metadata().ok()?.created().ok()?) } else { None } + } + ) + .collect::>(); + + times.sort(); + Some(times.last()?.clone()) } pub fn get_valheim_executable_information(world_path: &str, backup_path: &str) -> Option { diff --git a/backend/style.scss b/backend/style.scss index 1ae90bd..99db66f 100644 --- a/backend/style.scss +++ b/backend/style.scss @@ -5,10 +5,10 @@ body { font-family: Fira Code, Helvetica Neue, Helvetica, Arial, sans-serif; - text-shadow: 2px 2px 2px #DDD; + text-shadow: 2px 2px 2px rgb(112, 112, 112); text-align: center; - color: #ededed; - background-color: #5b5b5b; + color: #bdbdbd; + background-color: #252525; } h1 {