backup info and read

This commit is contained in:
2025-01-22 22:21:54 +01:00
parent 8cc967cf68
commit 88be5951a6
9 changed files with 131 additions and 29 deletions

View File

@@ -51,6 +51,12 @@ pub struct TestPump {
pump: usize,
}
#[derive(Serialize, Deserialize, PartialEq, Debug)]
pub struct WebBackupHeader{
timestamp: std::string::String,
size: usize
}
fn write_time(
request: &mut Request<&mut EspHttpConnection>,
) -> Result<Option<std::string::String>, anyhow::Error> {
@@ -159,6 +165,26 @@ fn get_backup_config(
anyhow::Ok(Some(json))
}
fn backup_info(
_request: &mut Request<&mut EspHttpConnection>,
) -> Result<Option<std::string::String>, anyhow::Error> {
let mut board = BOARD_ACCESS.lock().unwrap();
let header = board.get_backup_info();
let json = match header {
Ok(h) => {
let timestamp = DateTime::from_timestamp_millis(h.timestamp).unwrap();
let wbh = WebBackupHeader{
timestamp: timestamp.to_rfc3339(),
size: h.size,
};
serde_json::to_string(&wbh)?
},
Err(_) => "{\"error\":\"Header could not be parsed\"".to_owned()
};
anyhow::Ok(Some(json))
}
fn set_config(
request: &mut Request<&mut EspHttpConnection>,
) -> Result<Option<std::string::String>, anyhow::Error> {
@@ -392,6 +418,11 @@ pub fn httpd(reboot_now: Arc<AtomicBool>) -> Box<EspHttpServer<'static>> {
handle_error_to500(request, backup_config)
})
.unwrap();
server
.fn_handler("/backup_info", Method::Get, move |request| {
handle_error_to500(request, backup_info)
})
.unwrap();
server
.fn_handler("/files", Method::Get, move |request| {
handle_error_to500(request, list_files)