Add route to download firmware on device

This commit is contained in:
2024-10-05 20:00:57 +02:00
parent 37844ae5fa
commit aa262879f0
4 changed files with 35 additions and 1 deletions

View File

@ -0,0 +1,21 @@
use crate::ota::ota_manager;
use crate::ota::ota_update::OTAPlatform;
use crate::server::custom_error::HttpResult;
use actix_web::{web, HttpResponse};
#[derive(serde::Deserialize)]
pub struct FirmwarePath {
platform: OTAPlatform,
version: semver::Version,
}
/// Download firmware update
pub async fn retrieve_firmware(path: web::Path<FirmwarePath>) -> HttpResult {
if !ota_manager::update_exists(path.platform, &path.version)? {
return Ok(HttpResponse::NotFound().json("The requested firmware was not found!"));
}
let firmware = ota_manager::get_ota_update(path.platform, &path.version)?;
Ok(HttpResponse::Ok().body(firmware))
}