Can delete uploaded ISO files
This commit is contained in:
		@@ -126,3 +126,25 @@ pub async fn get_list() -> HttpResult {
 | 
			
		||||
 | 
			
		||||
    Ok(HttpResponse::Ok().json(list))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(serde::Deserialize)]
 | 
			
		||||
pub struct DeleteFilePath {
 | 
			
		||||
    filename: String,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Delete ISO file
 | 
			
		||||
pub async fn delete_file(p: web::Path<DeleteFilePath>) -> HttpResult {
 | 
			
		||||
    if !files_utils::check_file_name(&p.filename) {
 | 
			
		||||
        return Ok(HttpResponse::BadRequest().json("Invalid file name!"));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    let file_path = AppConfig::get().iso_storage_path().join(&p.filename);
 | 
			
		||||
 | 
			
		||||
    if !file_path.exists() {
 | 
			
		||||
        return Ok(HttpResponse::NotFound().json("File does not exists!"));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    std::fs::remove_file(file_path)?;
 | 
			
		||||
 | 
			
		||||
    Ok(HttpResponse::Accepted().finish())
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -109,6 +109,10 @@ async fn main() -> std::io::Result<()> {
 | 
			
		||||
                web::post().to(iso_controller::upload_from_url),
 | 
			
		||||
            )
 | 
			
		||||
            .route("/api/iso/list", web::get().to(iso_controller::get_list))
 | 
			
		||||
            .route(
 | 
			
		||||
                "/api/iso/{filename}",
 | 
			
		||||
                web::delete().to(iso_controller::delete_file),
 | 
			
		||||
            )
 | 
			
		||||
    })
 | 
			
		||||
    .bind(&AppConfig::get().listen_address)?
 | 
			
		||||
    .run()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user