diff options
author | Sven-Hendrik Haase <svenstaro@gmail.com> | 2025-03-03 03:54:51 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-03 03:54:51 +0000 |
commit | c26b74c8a9f47f86b39a687b20d769e3b349fd8d (patch) | |
tree | 1c562da6fbcba9900ce85e300cc9298a0ddf23c8 /src/args.rs | |
parent | Merge pull request #1478 from svenstaro/dependabot/cargo/all-dependencies-65d... (diff) | |
parent | feat: validate temp dir exists through `value_parser` and fixed clippy issues (diff) | |
download | miniserve-c26b74c8a9f47f86b39a687b20d769e3b349fd8d.tar.gz miniserve-c26b74c8a9f47f86b39a687b20d769e3b349fd8d.zip |
Merge pull request #1431 from AlecDivito/upload-progress-bar
feat: Added HTML and Javascript progress bar when uploading files
Diffstat (limited to 'src/args.rs')
-rw-r--r-- | src/args.rs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/args.rs b/src/args.rs index 922e78b..72ade7b 100644 --- a/src/args.rs +++ b/src/args.rs @@ -26,6 +26,21 @@ pub struct CliArgs { #[arg(value_hint = ValueHint::AnyPath, env = "MINISERVE_PATH")] pub path: Option<PathBuf>, + /// 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", + value_parser(validate_is_dir_and_exists), + env = "MINISERVER_TEMP_UPLOAD_DIRECTORY") + ] + pub temp_upload_directory: Option<PathBuf>, + /// 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. @@ -166,6 +181,26 @@ pub struct CliArgs { #[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<Vec<PathBuf>>, + /// 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. + /// + /// 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", + default_value = "0" + )] + pub web_upload_concurrency: usize, + /// Enable creating directories #[arg( short = 'U', @@ -322,6 +357,20 @@ fn parse_interface(src: &str) -> Result<IpAddr, std::net::AddrParseError> { src.parse::<IpAddr>() } +/// Validate that a path passed in is a directory and it exists. +fn validate_is_dir_and_exists(s: &str) -> Result<PathBuf, String> { + 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 |