49 lines
1.3 KiB
Rust
49 lines
1.3 KiB
Rust
use anyhow::{Error};
|
|
use serde_json::Value;
|
|
use chrono::{Local, TimeZone};
|
|
|
|
pub fn strip_server_file_expenstion(name: &str) -> String {
|
|
|
|
if name.ends_with(".didx") || name.ends_with(".fidx") || name.ends_with(".blob") {
|
|
name[..name.len()-5].to_owned()
|
|
} else {
|
|
name.to_owned() // should not happen
|
|
}
|
|
}
|
|
|
|
pub fn render_backup_file_list(files: &[String]) -> String {
|
|
let mut files: Vec<String> = files.iter()
|
|
.map(|v| strip_server_file_expenstion(&v))
|
|
.collect();
|
|
|
|
files.sort();
|
|
|
|
super::join(&files, ' ')
|
|
}
|
|
|
|
pub fn render_epoch(value: &Value, _record: &Value) -> Result<String, Error> {
|
|
if value.is_null() { return Ok(String::new()); }
|
|
let text = match value.as_i64() {
|
|
Some(epoch) => {
|
|
Local.timestamp(epoch, 0).format("%c").to_string()
|
|
}
|
|
None => {
|
|
value.to_string()
|
|
}
|
|
};
|
|
Ok(text)
|
|
}
|
|
|
|
pub fn render_task_status(value: &Value, record: &Value) -> Result<String, Error> {
|
|
if record["endtime"].is_null() {
|
|
Ok(value.as_str().unwrap_or("running").to_string())
|
|
} else {
|
|
Ok(value.as_str().unwrap_or("unknown").to_string())
|
|
}
|
|
}
|
|
|
|
pub fn render_bool_with_default_true(value: &Value, _record: &Value) -> Result<String, Error> {
|
|
let value = value.as_bool().unwrap_or(true);
|
|
Ok((if value { "1" } else { "0" }).to_string())
|
|
}
|