From 127dd6cdade1056c96f616c1ec9cf15fc8d354af Mon Sep 17 00:00:00 2001 From: asonix Date: Tue, 18 Jul 2023 20:32:17 -0500 Subject: [PATCH] Make max file count configurable --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- defaults.toml | 1 + pict-rs.toml | 5 +++++ src/config/commandline.rs | 10 ++++++++++ src/config/defaults.rs | 2 ++ src/config/file.rs | 2 ++ src/lib.rs | 6 +++--- 8 files changed, 26 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 195dfd5..18d7d97 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -21,9 +21,9 @@ dependencies = [ [[package]] name = "actix-form-data" -version = "0.7.0-beta.3" +version = "0.7.0-beta.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e62838cdaf64f86c52548b0ed5382ffcb990f588f9a389afce4fe225c705960" +checksum = "a2163627f82eef55c4551f3e58ba0da92d733fa3afe8d0c13986a9ba00d1f9f7" dependencies = [ "actix-multipart", "actix-rt", diff --git a/Cargo.toml b/Cargo.toml index 0dbd5a8..5a1aaa9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ io-uring = [ ] [dependencies] -actix-form-data = "0.7.0-beta.3" +actix-form-data = "0.7.0-beta.4" actix-rt = { version = "2.7.0", default-features = false } actix-server = "2.0.0" actix-web = { version = "4.0.0", default-features = false } diff --git a/defaults.toml b/defaults.toml index 918bfbd..9a0be3c 100644 --- a/defaults.toml +++ b/defaults.toml @@ -2,6 +2,7 @@ address = "0.0.0.0:8080" worker_id = "pict-rs-1" read_only = false +max_file_count = 1 [client] pool_size = 100 diff --git a/pict-rs.toml b/pict-rs.toml index 1f53623..978335e 100644 --- a/pict-rs.toml +++ b/pict-rs.toml @@ -20,6 +20,11 @@ worker_id = 'pict-rs-1' # Not specifying api_key disables internal endpoints api_key = 'API_KEY' +## Optional: How many files are allowed to be uploaded per request +# environment variable: PICTRS__SERVER__MAX_FILE_COUNT +# default: 1 +max_file_count = 1 + ## Client configuration [client] ## Optional: connection pool size for internal http client diff --git a/src/config/commandline.rs b/src/config/commandline.rs index a0f45db..d7ce4c1 100644 --- a/src/config/commandline.rs +++ b/src/config/commandline.rs @@ -88,6 +88,7 @@ impl Args { media_video_quality_2160, media_filters, read_only, + max_file_count, store, }) => { let server = Server { @@ -95,6 +96,7 @@ impl Args { api_key, worker_id, read_only, + max_file_count, }; let client = Client { @@ -363,6 +365,8 @@ struct Server { api_key: Option, #[serde(skip_serializing_if = "std::ops::Not::not")] read_only: bool, + #[serde(skip_serializing_if = "Option::is_none")] + max_file_count: Option, } #[derive(Debug, Default, serde::Serialize)] @@ -719,6 +723,12 @@ struct Run { #[arg(long)] client_timeout: Option, + /// How many files are allowed to be uploaded per-request + /// + /// This number defaults to 1 + #[arg(long)] + max_file_count: Option, + /// Optional pre-processing steps for uploaded media. /// /// All still images will be put through these steps before saving diff --git a/src/config/defaults.rs b/src/config/defaults.rs index b5ae42b..af8e364 100644 --- a/src/config/defaults.rs +++ b/src/config/defaults.rs @@ -23,6 +23,7 @@ struct ServerDefaults { address: SocketAddr, worker_id: String, read_only: bool, + max_file_count: u32, } #[derive(Clone, Debug, serde::Serialize)] @@ -175,6 +176,7 @@ impl Default for ServerDefaults { address: "0.0.0.0:8080".parse().expect("Valid address string"), worker_id: String::from("pict-rs-1"), read_only: false, + max_file_count: 1, } } } diff --git a/src/config/file.rs b/src/config/file.rs index abd9bdb..774c278 100644 --- a/src/config/file.rs +++ b/src/config/file.rs @@ -99,6 +99,8 @@ pub(crate) struct Server { pub(crate) api_key: Option, pub(crate) read_only: bool, + + pub(crate) max_file_count: u32, } #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] diff --git a/src/lib.rs b/src/lib.rs index dacc8a1..4993061 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -161,7 +161,7 @@ impl FormData for Upload { .clone(); Form::new() - .max_files(10) + .max_files(CONFIG.server.max_file_count) .max_file_size(CONFIG.media.max_file_size * MEGABYTES) .transform_error(transform_error) .field( @@ -213,7 +213,7 @@ impl FormData for Import { // // This form is expecting a single array field, 'images' with at most 10 files in it Form::new() - .max_files(10) + .max_files(CONFIG.server.max_file_count) .max_file_size(CONFIG.media.max_file_size * MEGABYTES) .transform_error(transform_error) .field( @@ -339,7 +339,7 @@ impl FormData for BackgroundedUpload { .clone(); Form::new() - .max_files(10) + .max_files(CONFIG.server.max_file_count) .max_file_size(CONFIG.media.max_file_size * MEGABYTES) .transform_error(transform_error) .field(