Can download ISO files
This commit is contained in:
@ -2,9 +2,10 @@ use crate::app_config::AppConfig;
|
||||
use crate::constants;
|
||||
use crate::controllers::HttpResult;
|
||||
use crate::utils::files_utils;
|
||||
use actix_files::NamedFile;
|
||||
use actix_multipart::form::tempfile::TempFile;
|
||||
use actix_multipart::form::MultipartForm;
|
||||
use actix_web::{web, HttpResponse};
|
||||
use actix_web::{web, HttpRequest, HttpResponse};
|
||||
use futures_util::StreamExt;
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
@ -128,12 +129,27 @@ pub async fn get_list() -> HttpResult {
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
pub struct DeleteFilePath {
|
||||
pub struct DownloadFilePath {
|
||||
filename: String,
|
||||
}
|
||||
|
||||
/// Download ISO file
|
||||
pub async fn download_file(p: web::Path<DownloadFilePath>, req: HttpRequest) -> 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!"));
|
||||
}
|
||||
|
||||
Ok(NamedFile::open(file_path)?.into_response(&req))
|
||||
}
|
||||
|
||||
/// Delete ISO file
|
||||
pub async fn delete_file(p: web::Path<DeleteFilePath>) -> HttpResult {
|
||||
pub async fn delete_file(p: web::Path<DownloadFilePath>) -> HttpResult {
|
||||
if !files_utils::check_file_name(&p.filename) {
|
||||
return Ok(HttpResponse::BadRequest().json("Invalid file name!"));
|
||||
}
|
||||
|
Reference in New Issue
Block a user