Display the list of OTA updates in the frontend

This commit is contained in:
2024-10-08 21:53:21 +02:00
parent 2924d14281
commit 6cf7c2cae1
8 changed files with 113 additions and 5 deletions

View File

@ -49,3 +49,14 @@ pub fn get_ota_updates_for_platform(platform: OTAPlatform) -> anyhow::Result<Vec
Ok(out)
}
/// Get all the available OTA updates
pub fn get_all_ota_updates() -> anyhow::Result<Vec<OTAUpdate>> {
let mut out = vec![];
for p in OTAPlatform::supported_platforms() {
out.append(&mut get_ota_updates_for_platform(*p)?)
}
Ok(out)
}

View File

@ -7,6 +7,13 @@ pub enum OTAPlatform {
Wt32Eth01,
}
impl OTAPlatform {
/// Get the list of supported platforms
pub fn supported_platforms() -> &'static [Self] {
&[OTAPlatform::Wt32Eth01]
}
}
impl Display for OTAPlatform {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let s = serde_json::to_string(&self).unwrap().replace('"', "");

View File

@ -191,7 +191,7 @@ pub async fn secure_server(energy_actor: EnergyActorAddr) -> anyhow::Result<()>
"/web_api/ota/{platform}/{version}",
web::post().to(ota_controller::upload_firmware),
)
// TODO : list all ota software updates
.route("/web_api/ota", web::get().to(ota_controller::list_all_ota))
.route(
"/web_api/ota/{platform}",
web::get().to(ota_controller::list_updates_platform),

View File

@ -10,7 +10,7 @@ use actix_multipart::form::MultipartForm;
use actix_web::{web, HttpResponse};
pub async fn supported_platforms() -> HttpResult {
Ok(HttpResponse::Ok().json(vec![OTAPlatform::Wt32Eth01]))
Ok(HttpResponse::Ok().json(OTAPlatform::supported_platforms()))
}
#[derive(Debug, MultipartForm)]
@ -53,6 +53,11 @@ pub async fn upload_firmware(
Ok(HttpResponse::Accepted().body("OTA update successfully saved."))
}
/// Get the list of all OTA updates
pub async fn list_all_ota() -> HttpResult {
Ok(HttpResponse::Ok().json(ota_manager::get_all_ota_updates()?))
}
#[derive(serde::Deserialize)]
pub struct ListOTAPath {
platform: OTAPlatform,