Can delete uploaded disk images
This commit is contained in:
@ -5,7 +5,7 @@ use crate::utils::file_disks_utils::DiskFileInfo;
|
||||
use crate::utils::files_utils;
|
||||
use actix_multipart::form::MultipartForm;
|
||||
use actix_multipart::form::tempfile::TempFile;
|
||||
use actix_web::HttpResponse;
|
||||
use actix_web::{HttpResponse, web};
|
||||
|
||||
#[derive(Debug, MultipartForm)]
|
||||
pub struct UploadDiskImageForm {
|
||||
@ -67,3 +67,27 @@ pub async fn get_list() -> HttpResult {
|
||||
|
||||
Ok(HttpResponse::Ok().json(list))
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
pub struct DiskFilePath {
|
||||
filename: String,
|
||||
}
|
||||
|
||||
/// Delete a disk image
|
||||
pub async fn delete(p: web::Path<DiskFilePath>) -> HttpResult {
|
||||
if !files_utils::check_file_name(&p.filename) {
|
||||
return Ok(HttpResponse::BadRequest().json("Invalid file name!"));
|
||||
}
|
||||
|
||||
let file_path = AppConfig::get()
|
||||
.disk_images_storage_path()
|
||||
.join(&p.filename);
|
||||
|
||||
if !file_path.exists() {
|
||||
return Ok(HttpResponse::NotFound().json("Disk image does not exists!"));
|
||||
}
|
||||
|
||||
std::fs::remove_file(file_path)?;
|
||||
|
||||
Ok(HttpResponse::Accepted().finish())
|
||||
}
|
||||
|
Reference in New Issue
Block a user