Display the list of ISO files
This commit is contained in:
@ -8,6 +8,7 @@ use actix_web::{web, HttpResponse};
|
||||
use futures_util::StreamExt;
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
use std::os::unix::fs::MetadataExt;
|
||||
|
||||
#[derive(Debug, MultipartForm)]
|
||||
pub struct UploadIsoForm {
|
||||
@ -105,3 +106,23 @@ pub async fn upload_from_url(req: web::Json<DownloadFromURLReq>) -> HttpResult {
|
||||
|
||||
Ok(HttpResponse::Accepted().finish())
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize)]
|
||||
struct IsoFile {
|
||||
filename: String,
|
||||
size: u64,
|
||||
}
|
||||
|
||||
/// Get ISO files list
|
||||
pub async fn get_list() -> HttpResult {
|
||||
let mut list = vec![];
|
||||
for entry in AppConfig::get().iso_storage_path().read_dir()? {
|
||||
let entry = entry?;
|
||||
list.push(IsoFile {
|
||||
filename: entry.file_name().to_string_lossy().to_string(),
|
||||
size: entry.path().metadata()?.size(),
|
||||
})
|
||||
}
|
||||
|
||||
Ok(HttpResponse::Ok().json(list))
|
||||
}
|
||||
|
@ -108,6 +108,7 @@ async fn main() -> std::io::Result<()> {
|
||||
"/api/iso/upload_from_url",
|
||||
web::post().to(iso_controller::upload_from_url),
|
||||
)
|
||||
.route("/api/iso/list", web::get().to(iso_controller::get_list))
|
||||
})
|
||||
.bind(&AppConfig::get().listen_address)?
|
||||
.run()
|
||||
|
Reference in New Issue
Block a user