Can manually download an OTA update

This commit is contained in:
2024-10-08 22:13:36 +02:00
parent 6cf7c2cae1
commit 2e4a2b68dd
4 changed files with 53 additions and 8 deletions

View File

@ -20,14 +20,15 @@ pub struct UploadForm {
}
#[derive(serde::Deserialize)]
pub struct UploadPath {
pub struct SpecificOTAVersionPath {
platform: OTAPlatform,
version: semver::Version,
}
/// Upload a new firmware update
pub async fn upload_firmware(
MultipartForm(form): MultipartForm<UploadForm>,
path: web::Path<UploadPath>,
path: web::Path<SpecificOTAVersionPath>,
) -> HttpResult {
if ota_manager::update_exists(path.platform, &path.version)? {
return Ok(HttpResponse::Conflict()
@ -53,6 +54,26 @@ pub async fn upload_firmware(
Ok(HttpResponse::Accepted().body("OTA update successfully saved."))
}
/// Download a firmware update
pub async fn download_firmware(path: web::Path<SpecificOTAVersionPath>) -> 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()
.content_type("application/octet-stream")
.append_header((
"content-disposition",
format!(
"attachment; filename=\"{}-{}.bin\"",
path.platform, path.version
),
))
.body(firmware))
}
/// Get the list of all OTA updates
pub async fn list_all_ota() -> HttpResult {
Ok(HttpResponse::Ok().json(ota_manager::get_all_ota_updates()?))