Can delete an OTA update

This commit is contained in:
2024-10-08 22:22:57 +02:00
parent 2e4a2b68dd
commit eafa8e6a4b
5 changed files with 79 additions and 8 deletions

View File

@ -31,6 +31,13 @@ pub fn get_ota_update(platform: OTAPlatform, version: &semver::Version) -> anyho
Ok(std::fs::read(path)?)
}
/// Delete an OTA update
pub fn delete_update(platform: OTAPlatform, version: &semver::Version) -> anyhow::Result<()> {
let path = AppConfig::get().path_ota_update(platform, version);
std::fs::remove_file(path)?;
Ok(())
}
/// Get the list of OTA software updates for a platform
pub fn get_ota_updates_for_platform(platform: OTAPlatform) -> anyhow::Result<Vec<OTAUpdate>> {
let ota_path = AppConfig::get().ota_platform_dir(platform);

View File

@ -195,7 +195,10 @@ pub async fn secure_server(energy_actor: EnergyActorAddr) -> anyhow::Result<()>
"/web_api/ota/{platform}/{version}",
web::get().to(ota_controller::download_firmware),
)
// TODO : delete an OTA file
.route(
"/web_api/ota/{platform}/{version}",
web::delete().to(ota_controller::delete_update),
)
.route("/web_api/ota", web::get().to(ota_controller::list_all_ota))
.route(
"/web_api/ota/{platform}",

View File

@ -74,6 +74,17 @@ pub async fn download_firmware(path: web::Path<SpecificOTAVersionPath>) -> HttpR
.body(firmware))
}
/// Delete an uploaded firmware update
pub async fn delete_update(path: web::Path<SpecificOTAVersionPath>) -> HttpResult {
if !ota_manager::update_exists(path.platform, &path.version)? {
return Ok(HttpResponse::NotFound().json("The requested update was not found!"));
}
ota_manager::delete_update(path.platform, &path.version)?;
Ok(HttpResponse::Accepted().finish())
}
/// Get the list of all OTA updates
pub async fn list_all_ota() -> HttpResult {
Ok(HttpResponse::Ok().json(ota_manager::get_all_ota_updates()?))