From ed3a1fbfe98e9b2fb2351e872792c94a10dc59b8 Mon Sep 17 00:00:00 2001 From: Eren AY Date: Tue, 28 May 2024 14:10:01 +0200 Subject: [PATCH] Fixes for requested changes and url rewrite logic now handled by JS since trailing slash is more related to HTML rendering --- src/main.rs | 10 +++------- templates/index.html.tera | 7 ++++++- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index d220ba6..9b1ef12 100644 --- a/src/main.rs +++ b/src/main.rs @@ -78,7 +78,6 @@ enum FileView { #[derive(Serialize)] struct FileViewItem { - parent: String, path: String, size: String, size_bytes: u64, @@ -107,7 +106,7 @@ async fn index(path: PathBuf) -> Result { We try first to retrieve list an object as a file. If we fail, we fallback to retrieving the equivalent folder. */ - + if let Ok(result) = s3_serve_file(&path).await { Ok(result) } else { @@ -176,7 +175,6 @@ async fn s3_fileview(path: &PathBuf) -> Result, Error> { let folders = list.common_prefixes.iter().flatten().map(|dir| { let path = dir.prefix.strip_prefix(&prefix); path.map(|path| FileViewItem { - parent:s3_folder_path.clone(), path: path.to_owned(), size_bytes: 0, size: "[DIR]".to_owned(), @@ -187,7 +185,6 @@ async fn s3_fileview(path: &PathBuf) -> Result, Error> { let files = list.contents.iter().map(|obj| { let path = obj.key.strip_prefix(&prefix); path.map(|path| FileViewItem { - parent:s3_folder_path.clone(), path: path.to_owned(), size_bytes: obj.size, size: size_bytes_to_human(obj.size), @@ -246,9 +243,8 @@ fn rocket() -> _ { #[cfg(test)] mod tests { - use rstest::rstest; - // Note this useful idiom: importing names from outer (for mod tests) scope. use super::*; + use rstest::rstest; #[rstest] #[case(1024, "1.024 kB")] @@ -260,7 +256,7 @@ mod tests { #[case(u64::MIN, format!("{:.3} B",u64::MIN as f64))] fn test_size_bytes_to_human(#[case] bytes: u64, #[case] expected: String) { - println!("{}",size_bytes_to_human(bytes)); + println!("{}", size_bytes_to_human(bytes)); assert_eq!(size_bytes_to_human(bytes), expected); } } diff --git a/templates/index.html.tera b/templates/index.html.tera index bd7a080..efa5b6b 100644 --- a/templates/index.html.tera +++ b/templates/index.html.tera @@ -5,6 +5,11 @@ --> +