diff options
author | Sven-Hendrik Haase <svenstaro@gmail.com> | 2021-03-20 22:31:38 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-20 22:31:38 +0000 |
commit | 9da7de7fffcb68c1c600efbee2ccb14e2f5df7b6 (patch) | |
tree | e196f4f9b87df39800569d08af57ab6c9bc79939 /src | |
parent | Bump deps (diff) | |
parent | Add negative test for hidden directories (diff) | |
download | miniserve-9da7de7fffcb68c1c600efbee2ccb14e2f5df7b6.tar.gz miniserve-9da7de7fffcb68c1c600efbee2ccb14e2f5df7b6.zip |
Merge pull request #471 from svenstaro/show-hidden
Show hidden
Diffstat (limited to 'src')
-rw-r--r-- | src/args.rs | 5 | ||||
-rw-r--r-- | src/listing.rs | 3 | ||||
-rw-r--r-- | src/main.rs | 60 |
3 files changed, 43 insertions, 25 deletions
diff --git a/src/args.rs b/src/args.rs index 7467b59..909a88f 100644 --- a/src/args.rs +++ b/src/args.rs @@ -69,6 +69,10 @@ struct CliArgs { #[structopt(short = "P", long = "no-symlinks")] no_symlinks: bool, + /// Show hidden files + #[structopt(short = "H", long = "hidden")] + hidden: bool, + /// Default color scheme #[structopt( short = "c", @@ -242,6 +246,7 @@ pub fn parse_args() -> crate::MiniserveConfig { auth: args.auth, path_explicitly_chosen, no_symlinks: args.no_symlinks, + show_hidden: args.hidden, random_route, favicon_route, css_route, diff --git a/src/listing.rs b/src/listing.rs index b46dded..66aea6b 100644 --- a/src/listing.rs +++ b/src/listing.rs @@ -148,6 +148,7 @@ pub fn directory_listing( dir: &actix_files::Directory, req: &HttpRequest, skip_symlinks: bool, + show_hidden: bool, file_upload: bool, random_route: Option<String>, favicon_route: String, @@ -248,7 +249,7 @@ pub fn directory_listing( let mut entries: Vec<Entry> = Vec::new(); for entry in dir.path.read_dir()? { - if dir.is_visible(&entry) { + if dir.is_visible(&entry) || show_hidden { let entry = entry?; let p = match entry.path().strip_prefix(&dir.path) { Ok(p) => base.join(p), diff --git a/src/main.rs b/src/main.rs index eac6449..17ab204 100644 --- a/src/main.rs +++ b/src/main.rs @@ -48,6 +48,9 @@ pub struct MiniserveConfig { /// Enable symlink resolution pub no_symlinks: bool, + /// Show hidden files + pub show_hidden: bool, + /// Enable random route generation pub random_route: Option<String>, @@ -311,6 +314,7 @@ fn configure_app(app: &mut web::ServiceConfig, conf: &MiniserveConfig) { let serve_path = { let path = &conf.path; let no_symlinks = conf.no_symlinks; + let show_hidden = conf.show_hidden; let random_route = conf.random_route.clone(); let favicon_route = conf.favicon_route.clone(); let css_route = conf.css_route.clone(); @@ -336,31 +340,39 @@ fn configure_app(app: &mut web::ServiceConfig, conf: &MiniserveConfig) { ) } else { let u_r = upload_route.clone(); - Some( - actix_files::Files::new(&full_route, path) + let files; + if show_hidden { + files = actix_files::Files::new(&full_route, path) .show_files_listing() - .files_listing_renderer(move |dir, req| { - listing::directory_listing( - dir, - req, - no_symlinks, - file_upload, - random_route.clone(), - favicon_route.clone(), - css_route.clone(), - &default_color_scheme, - &default_color_scheme_dark, - show_qrcode, - u_r.clone(), - tar_enabled, - zip_enabled, - dirs_first, - hide_version_footer, - title.clone(), - ) - }) - .default_handler(web::to(error_404)), - ) + .use_hidden_files(); + } else { + files = actix_files::Files::new(&full_route, path).show_files_listing(); + } + + let files = files + .files_listing_renderer(move |dir, req| { + listing::directory_listing( + dir, + req, + no_symlinks, + show_hidden, + file_upload, + random_route.clone(), + favicon_route.clone(), + css_route.clone(), + &default_color_scheme, + &default_color_scheme_dark, + show_qrcode, + u_r.clone(), + tar_enabled, + zip_enabled, + dirs_first, + hide_version_footer, + title.clone(), + ) + }) + .default_handler(web::to(error_404)); + Some(files) } }; |