remove: eliminate file management and LittleFS-based filesystem, implement savegame management for JSON config slots with wear-leveling
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
//offer ota and config mode
|
||||
|
||||
mod backup_manager;
|
||||
mod file_manager;
|
||||
mod get_json;
|
||||
mod get_log;
|
||||
mod get_static;
|
||||
@@ -10,10 +9,9 @@ mod post_json;
|
||||
|
||||
use crate::fat_error::{FatError, FatResult};
|
||||
use crate::webserver::backup_manager::{backup_config, backup_info, get_backup_config};
|
||||
use crate::webserver::file_manager::{file_operations, list_files};
|
||||
use crate::webserver::get_json::{
|
||||
get_battery_state, get_config, get_live_moisture, get_log_localization_config, get_solar_state,
|
||||
get_time, get_timezones, get_version_web, tank_info,
|
||||
delete_save, get_time, get_timezones, get_version_web, list_saves, tank_info,
|
||||
};
|
||||
use crate::webserver::get_log::get_log;
|
||||
use crate::webserver::get_static::{serve_bundle, serve_favicon, serve_index};
|
||||
@@ -60,10 +58,7 @@ impl Handler for HTTPRequestRouter {
|
||||
let method = headers.method;
|
||||
let path = headers.path;
|
||||
|
||||
let prefix = "/file?filename=";
|
||||
let status = if path.starts_with(prefix) {
|
||||
file_operations(conn, method, &path, &prefix).await?
|
||||
} else if path == "/ota" {
|
||||
let status = if path == "/ota" {
|
||||
ota_operations(conn, method).await.map_err(|e| {
|
||||
error!("Error handling ota: {e}");
|
||||
e
|
||||
@@ -82,13 +77,20 @@ impl Handler for HTTPRequestRouter {
|
||||
"/time" => Some(get_time(conn).await),
|
||||
"/battery" => Some(get_battery_state(conn).await),
|
||||
"/solar" => Some(get_solar_state(conn).await),
|
||||
"/get_config" => Some(get_config(conn).await),
|
||||
"/files" => Some(list_files(conn).await),
|
||||
"/log_localization" => Some(get_log_localization_config(conn).await),
|
||||
"/tank" => Some(tank_info(conn).await),
|
||||
"/backup_info" => Some(backup_info(conn).await),
|
||||
"/timezones" => Some(get_timezones().await),
|
||||
"/moisture" => Some(get_live_moisture(conn).await),
|
||||
"/list_saves" => Some(list_saves(conn).await),
|
||||
// /get_config accepts an optional ?saveidx=N query parameter
|
||||
p if p == "/get_config" || p.starts_with("/get_config?") => {
|
||||
let saveidx: Option<usize> = p
|
||||
.find("saveidx=")
|
||||
.and_then(|pos| p[pos + 8..].split('&').next())
|
||||
.and_then(|s| s.parse().ok());
|
||||
Some(get_config(conn, saveidx).await)
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
match json {
|
||||
@@ -127,7 +129,26 @@ impl Handler for HTTPRequestRouter {
|
||||
Some(json) => Some(handle_json(conn, json).await?),
|
||||
}
|
||||
}
|
||||
Method::Options | Method::Delete | Method::Head | Method::Put => None,
|
||||
Method::Delete => {
|
||||
// DELETE /delete_save?idx=N
|
||||
let json = if path == "/delete_save" || path.starts_with("/delete_save?") {
|
||||
let idx: Option<usize> = path
|
||||
.find("idx=")
|
||||
.and_then(|pos| path[pos + 4..].split('&').next())
|
||||
.and_then(|s| s.parse().ok());
|
||||
match idx {
|
||||
Some(idx) => Some(delete_save(conn, idx).await),
|
||||
None => Some(Err(FatError::String { error: "missing idx parameter".into() })),
|
||||
}
|
||||
} else {
|
||||
None
|
||||
};
|
||||
match json {
|
||||
None => None,
|
||||
Some(json) => Some(handle_json(conn, json).await?),
|
||||
}
|
||||
}
|
||||
Method::Options | Method::Head | Method::Put => None,
|
||||
_ => None,
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user