From be81eaefa526fa80e04166e86978e3a95263b4e3 Mon Sep 17 00:00:00 2001 From: Alec Di Vito Date: Thu, 6 Jun 2024 18:42:20 -0400 Subject: feat: Added HTML and Javascript progress bar when uploading files --- src/args.rs | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/args.rs') diff --git a/src/args.rs b/src/args.rs index 95c8bff..a58504b 100644 --- a/src/args.rs +++ b/src/args.rs @@ -165,6 +165,14 @@ pub struct CliArgs { /// When specified via environment variable, a path always neesd to the specified. #[arg(short = 'u', long = "upload-files", value_hint = ValueHint::FilePath, num_args(0..=1), value_delimiter(','), env = "MINISERVE_ALLOWED_UPLOAD_DIR")] pub allowed_upload_dir: Option>, + + /// Configure amount of concurrent uploads when visiting the website. Must have + /// upload-files option enabled for this setting to matter. + /// + /// For example, a value of 4 would mean that the web browser will only upload + /// 4 files at a time to the web server when using the web browser interface. + #[arg(long = "web-upload-files-concurrency", env = "MINISERVE_WEB_UPLOAD_CONCURRENCY", default_value = "0")] + pub web_upload_concurrency: usize, /// Enable creating directories #[arg( -- cgit v1.2.3 From 1d8b6d8f1f45047e2908506c490d175a8c0a65aa Mon Sep 17 00:00:00 2001 From: Alec Di Vito Date: Thu, 6 Jun 2024 19:08:47 -0400 Subject: chore: clean up --- src/args.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/args.rs') diff --git a/src/args.rs b/src/args.rs index a58504b..70ad208 100644 --- a/src/args.rs +++ b/src/args.rs @@ -162,7 +162,7 @@ pub struct CliArgs { /// The provided path is not a physical file system path. Instead, it's relative to the serve /// dir. For instance, if the serve dir is '/home/hello', set this to '/upload' to allow /// uploading to '/home/hello/upload'. - /// When specified via environment variable, a path always neesd to the specified. + /// When specified via environment variable, a path always needs to the specified. #[arg(short = 'u', long = "upload-files", value_hint = ValueHint::FilePath, num_args(0..=1), value_delimiter(','), env = "MINISERVE_ALLOWED_UPLOAD_DIR")] pub allowed_upload_dir: Option>, -- cgit v1.2.3 From 413a63a60307bdf60229670b0f858963604d62a3 Mon Sep 17 00:00:00 2001 From: Alec Di Vito Date: Sun, 16 Feb 2025 23:35:26 -0500 Subject: feat: implement temporary file uploads and tweak mobile design --- src/args.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/args.rs') diff --git a/src/args.rs b/src/args.rs index f117b1c..17f6c84 100644 --- a/src/args.rs +++ b/src/args.rs @@ -165,13 +165,17 @@ pub struct CliArgs { /// When specified via environment variable, a path always needs to be specified. #[arg(short = 'u', long = "upload-files", value_hint = ValueHint::FilePath, num_args(0..=1), value_delimiter(','), env = "MINISERVE_ALLOWED_UPLOAD_DIR")] pub allowed_upload_dir: Option>, - + /// Configure amount of concurrent uploads when visiting the website. Must have /// upload-files option enabled for this setting to matter. - /// + /// /// For example, a value of 4 would mean that the web browser will only upload /// 4 files at a time to the web server when using the web browser interface. - #[arg(long = "web-upload-files-concurrency", env = "MINISERVE_WEB_UPLOAD_CONCURRENCY", default_value = "0")] + #[arg( + long = "web-upload-files-concurrency", + env = "MINISERVE_WEB_UPLOAD_CONCURRENCY", + default_value = "0" + )] pub web_upload_concurrency: usize, /// Enable creating directories -- cgit v1.2.3 From 577044ddbd70f5f128512c1a021329fb4c7e7eb3 Mon Sep 17 00:00:00 2001 From: Alec Di Vito Date: Sat, 22 Feb 2025 13:44:16 -0500 Subject: feat: address comments; add in new argument (`temp-directory`); add comments to upload code; add tests --- src/args.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/args.rs') diff --git a/src/args.rs b/src/args.rs index 17f6c84..e9243f5 100644 --- a/src/args.rs +++ b/src/args.rs @@ -26,6 +26,20 @@ pub struct CliArgs { #[arg(value_hint = ValueHint::AnyPath, env = "MINISERVE_PATH")] pub path: Option, + /// The path to where file uploads will be written to before being moved to their + /// correct location. It's wise to make sure that this directory will be written to + /// disk and not into memory. + /// + /// This value will only be used **IF** file uploading is enabled. If this option is + /// not set, the operating system default temporary directory will be used. + #[arg( + long = "temp-directory", + value_hint = ValueHint::FilePath, + requires = "allowed_upload_dir", + env = "MINISERVER_TEMP_UPLOAD_DIRECTORY") + ] + pub temp_upload_directory: Option, + /// The name of a directory index file to serve, like "index.html" /// /// Normally, when miniserve serves a directory, it creates a listing for that directory. @@ -171,6 +185,14 @@ pub struct CliArgs { /// /// For example, a value of 4 would mean that the web browser will only upload /// 4 files at a time to the web server when using the web browser interface. + /// + /// When the value is kept at 0, it attempts to resolve all the uploads at once + /// in the web browser. + /// + /// NOTE: Web pages have a limit of how many active HTTP connections that they + /// can make at one time, so even though you might set a concurrency limit of + /// 100, the browser might only make progress on the max amount of connections + /// it allows the web page to have open. #[arg( long = "web-upload-files-concurrency", env = "MINISERVE_WEB_UPLOAD_CONCURRENCY", -- cgit v1.2.3 From 33c79837f1e113a1ce83a461413acf474e973c63 Mon Sep 17 00:00:00 2001 From: Alec Di Vito Date: Sun, 2 Mar 2025 14:46:10 -0500 Subject: feat: validate temp dir exists through `value_parser` and fixed clippy issues --- src/args.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/args.rs') diff --git a/src/args.rs b/src/args.rs index e9243f5..72ade7b 100644 --- a/src/args.rs +++ b/src/args.rs @@ -36,6 +36,7 @@ pub struct CliArgs { long = "temp-directory", value_hint = ValueHint::FilePath, requires = "allowed_upload_dir", + value_parser(validate_is_dir_and_exists), env = "MINISERVER_TEMP_UPLOAD_DIRECTORY") ] pub temp_upload_directory: Option, @@ -356,6 +357,20 @@ fn parse_interface(src: &str) -> Result { src.parse::() } +/// Validate that a path passed in is a directory and it exists. +fn validate_is_dir_and_exists(s: &str) -> Result { + let path = PathBuf::from(s); + if path.exists() && path.is_dir() { + Ok(path) + } else { + Err(format!( + "Upload temporary directory must exist and be a directory. \ + Validate that path {:?} meets those requirements.", + path + )) + } +} + #[derive(Clone, Debug, thiserror::Error)] pub enum AuthParseError { /// Might occur if the HTTP credential string does not respect the expected format -- cgit v1.2.3