Can download disk images
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				continuous-integration/drone/push Build is passing
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	continuous-integration/drone/push Build is passing
				
			This commit is contained in:
		@@ -3,9 +3,10 @@ use crate::constants;
 | 
			
		||||
use crate::controllers::HttpResult;
 | 
			
		||||
use crate::utils::file_disks_utils::DiskFileInfo;
 | 
			
		||||
use crate::utils::files_utils;
 | 
			
		||||
use actix_files::NamedFile;
 | 
			
		||||
use actix_multipart::form::MultipartForm;
 | 
			
		||||
use actix_multipart::form::tempfile::TempFile;
 | 
			
		||||
use actix_web::{HttpResponse, web};
 | 
			
		||||
use actix_web::{HttpRequest, HttpResponse, web};
 | 
			
		||||
 | 
			
		||||
#[derive(Debug, MultipartForm)]
 | 
			
		||||
pub struct UploadDiskImageForm {
 | 
			
		||||
@@ -73,6 +74,23 @@ pub struct DiskFilePath {
 | 
			
		||||
    filename: String,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Download disk image
 | 
			
		||||
pub async fn download(p: web::Path<DiskFilePath>, req: HttpRequest) -> 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!"));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    Ok(NamedFile::open(file_path)?.into_response(&req))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Delete a disk image
 | 
			
		||||
pub async fn delete(p: web::Path<DiskFilePath>) -> HttpResult {
 | 
			
		||||
    if !files_utils::check_file_name(&p.filename) {
 | 
			
		||||
 
 | 
			
		||||
@@ -345,6 +345,10 @@ async fn main() -> std::io::Result<()> {
 | 
			
		||||
                "/api/disk_images/list",
 | 
			
		||||
                web::get().to(disk_images_controller::get_list),
 | 
			
		||||
            )
 | 
			
		||||
            .route(
 | 
			
		||||
                "/api/disk_images/{filename}",
 | 
			
		||||
                web::get().to(disk_images_controller::download),
 | 
			
		||||
            )
 | 
			
		||||
            .route(
 | 
			
		||||
                "/api/disk_images/{filename}",
 | 
			
		||||
                web::delete().to(disk_images_controller::delete),
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user