From d14e17d94964291fda976423c1fe1a772d5af60b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vojt=C4=9Bch=20Pej=C5=A1a?= Date: Wed, 27 Mar 2019 09:44:29 +0100 Subject: Add CLI arguments for file uploading. --- src/main.rs | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index fb7e321..f7d0b1b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -44,6 +44,12 @@ pub struct MiniserveConfig { /// Enable random route generation pub random_route: Option, + + /// Enable file upload + pub file_upload: bool, + + /// Enable upload to override existing files + pub override_files: bool, } fn main() { @@ -175,11 +181,12 @@ fn main() { } /// Configures the Actix application -fn configure_app(app: App) -> App { +fn configure_app(mut app: App) -> App { let s = { let path = &app.state().path; let no_symlinks = app.state().no_symlinks; let random_route = app.state().random_route.clone(); + let file_upload = app.state().file_upload.clone(); if path.is_file() { None } else { @@ -188,7 +195,13 @@ fn configure_app(app: App) -> App { .expect("Couldn't create path") .show_files_listing() .files_listing_renderer(move |dir, req| { - listing::directory_listing(dir, req, no_symlinks, random_route.clone()) + listing::directory_listing( + dir, + req, + no_symlinks, + file_upload, + random_route.clone(), + ) }), ) } @@ -198,9 +211,11 @@ fn configure_app(app: App) -> App { let full_route = format!("/{}", random_route); // Allow file upload - let app = app.resource("/upload", |r| { - r.method(Method::POST).f(file_upload::upload_file) - }); + if app.state().file_upload { + app = app.resource("/upload", |r| { + r.method(Method::POST).f(file_upload::upload_file) + }); + } if let Some(s) = s { // Handle directories -- cgit v1.2.3