Get the list of OTA updates for a given platform
This commit is contained in:
parent
2feb3f6490
commit
d38040cb98
@ -300,11 +300,14 @@ impl AppConfig {
|
|||||||
self.storage_path().join("ota")
|
self.storage_path().join("ota")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the directory that will store OTA updates for a given platform
|
||||||
|
pub fn ota_platform_dir(&self, platform: OTAPlatform) -> PathBuf {
|
||||||
|
self.ota_dir().join(platform.to_string())
|
||||||
|
}
|
||||||
|
|
||||||
/// Get the path to the file that will contain an OTA update
|
/// Get the path to the file that will contain an OTA update
|
||||||
pub fn path_ota_update(&self, platform: OTAPlatform, version: &semver::Version) -> PathBuf {
|
pub fn path_ota_update(&self, platform: OTAPlatform, version: &semver::Version) -> PathBuf {
|
||||||
self.ota_dir()
|
self.ota_platform_dir(platform).join(version.to_string())
|
||||||
.join(platform.to_string())
|
|
||||||
.join(version.to_string())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
use crate::app_config::AppConfig;
|
use crate::app_config::AppConfig;
|
||||||
use crate::ota::ota_update::OTAPlatform;
|
use crate::ota::ota_update::{OTAPlatform, OTAUpdate};
|
||||||
use crate::utils::files_utils;
|
use crate::utils::files_utils;
|
||||||
|
use std::os::unix::fs::MetadataExt;
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
/// Check out whether a given update exists or not
|
/// Check out whether a given update exists or not
|
||||||
pub fn update_exists(platform: OTAPlatform, version: &semver::Version) -> anyhow::Result<bool> {
|
pub fn update_exists(platform: OTAPlatform, version: &semver::Version) -> anyhow::Result<bool> {
|
||||||
@ -22,3 +24,22 @@ pub fn save_update(
|
|||||||
|
|
||||||
Ok(())
|
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);
|
||||||
|
|
||||||
|
let mut out = Vec::new();
|
||||||
|
|
||||||
|
for e in std::fs::read_dir(ota_path)? {
|
||||||
|
let e = e?;
|
||||||
|
|
||||||
|
out.push(OTAUpdate {
|
||||||
|
platform,
|
||||||
|
version: semver::Version::from_str(e.file_name().to_str().unwrap_or("bad"))?,
|
||||||
|
file_size: e.metadata()?.size(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(out)
|
||||||
|
}
|
||||||
|
@ -16,7 +16,7 @@ impl Display for OTAPlatform {
|
|||||||
/// Single OTA update information
|
/// Single OTA update information
|
||||||
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, Eq, PartialEq)]
|
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, Eq, PartialEq)]
|
||||||
pub struct OTAUpdate {
|
pub struct OTAUpdate {
|
||||||
platform: OTAPlatform,
|
pub platform: OTAPlatform,
|
||||||
version: semver::Version,
|
pub version: semver::Version,
|
||||||
file_size: usize,
|
pub file_size: u64,
|
||||||
}
|
}
|
||||||
|
@ -189,7 +189,11 @@ pub async fn secure_server(energy_actor: EnergyActorAddr) -> anyhow::Result<()>
|
|||||||
"/web_api/ota/{platform}/{version}",
|
"/web_api/ota/{platform}/{version}",
|
||||||
web::post().to(ota_controller::upload_firmware),
|
web::post().to(ota_controller::upload_firmware),
|
||||||
)
|
)
|
||||||
// TODO : list ota software update per platform
|
// TODO : list all ota software updates
|
||||||
|
.route(
|
||||||
|
"/web_api/ota/{platform}",
|
||||||
|
web::get().to(ota_controller::list_updates_platform),
|
||||||
|
)
|
||||||
// TODO : download a OTA file
|
// TODO : download a OTA file
|
||||||
// TODO : delete an OTA file
|
// TODO : delete an OTA file
|
||||||
.route(
|
.route(
|
||||||
|
@ -53,6 +53,18 @@ pub async fn upload_firmware(
|
|||||||
Ok(HttpResponse::Accepted().body("OTA update successfully saved."))
|
Ok(HttpResponse::Accepted().body("OTA update successfully saved."))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(serde::Deserialize)]
|
||||||
|
pub struct ListOTAPath {
|
||||||
|
platform: OTAPlatform,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// List OTA software updates for a given platform
|
||||||
|
pub async fn list_updates_platform(path: web::Path<ListOTAPath>) -> HttpResult {
|
||||||
|
let list = ota_manager::get_ota_updates_for_platform(path.platform)?;
|
||||||
|
|
||||||
|
Ok(HttpResponse::Ok().json(list))
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(serde::Deserialize)]
|
#[derive(serde::Deserialize)]
|
||||||
pub struct SetDesiredDeviceVersion {
|
pub struct SetDesiredDeviceVersion {
|
||||||
devices: Option<Vec<DeviceId>>,
|
devices: Option<Vec<DeviceId>>,
|
||||||
|
Loading…
Reference in New Issue
Block a user