const VALUE_UNKNOWN: &str = "-";
#[cached(size = 1, time = 10)]
-fn get_valheim_executable_information_cached(world_path: String) -> Option<valheim_controller::ValheimExe> {
- valheim_controller::get_valheim_executable_information(&world_path)
+fn get_valheim_executable_information_cached(world_path: String, backup_path: String) -> Option<valheim_controller::ValheimExe> {
+ valheim_controller::get_valheim_executable_information(&world_path, &backup_path)
}
#[get("/")]
async fn main_page(config_shared: web::Data<Mutex<Config>>) -> 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 :)"),
use sysinfo::{ ProcessExt, SystemExt };\r
-use chrono::{ DateTime, Datelike, Timelike, Utc };\r
+\r
+use std::{ fs, time::SystemTime };\r
+\r
+use chrono::{ DateTime, offset::Local };\r
\r
#[cfg(target_os = "unix")]\r
use systemd::journal;\r
uptime: u64, // [s].\r
world_size: u64, // [B].\r
nb_of_players: u32,\r
- last_backup: DateTime,\r
+ last_backup: Option<SystemTime>,\r
}\r
\r
impl ValheimExe {\r
}\r
\r
pub fn format_last_backup(&self) -> String {\r
- string::from("")\r
+ match self.last_backup {\r
+ Some(t) => {\r
+ let datetime: DateTime<Local> = t.into();\r
+ datetime.format("%d/%m/%Y %T").to_string()\r
+ },\r
+ None => String::from("?")\r
+ }\r
}\r
}\r
\r
0\r
}\r
\r
-fn get_last_backup_datetime(backup_path: &str) -> DateTime {\r
+fn get_last_backup_datetime(backup_path: &str) -> Option<SystemTime> {\r
+ let mut times =\r
+ fs::read_dir(backup_path).ok()?.filter_map(\r
+ |e| {\r
+ let dir = e.ok()?;\r
+ if dir.path().is_file() { Some(dir.metadata().ok()?.created().ok()?) } else { None }\r
+ }\r
+ )\r
+ .collect::<Vec<SystemTime>>();\r
+\r
+ times.sort();\r
\r
+ Some(times.last()?.clone())\r
}\r
\r
pub fn get_valheim_executable_information(world_path: &str, backup_path: &str) -> Option<ValheimExe> {\r
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 {