Make max file count configurable
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
asonix 2023-07-18 20:32:17 -05:00
parent eeac900d7e
commit 127dd6cdad
8 changed files with 26 additions and 6 deletions

4
Cargo.lock generated
View file

@ -21,9 +21,9 @@ dependencies = [
[[package]] [[package]]
name = "actix-form-data" 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" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7e62838cdaf64f86c52548b0ed5382ffcb990f588f9a389afce4fe225c705960" checksum = "a2163627f82eef55c4551f3e58ba0da92d733fa3afe8d0c13986a9ba00d1f9f7"
dependencies = [ dependencies = [
"actix-multipart", "actix-multipart",
"actix-rt", "actix-rt",

View file

@ -19,7 +19,7 @@ io-uring = [
] ]
[dependencies] [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-rt = { version = "2.7.0", default-features = false }
actix-server = "2.0.0" actix-server = "2.0.0"
actix-web = { version = "4.0.0", default-features = false } actix-web = { version = "4.0.0", default-features = false }

View file

@ -2,6 +2,7 @@
address = "0.0.0.0:8080" address = "0.0.0.0:8080"
worker_id = "pict-rs-1" worker_id = "pict-rs-1"
read_only = false read_only = false
max_file_count = 1
[client] [client]
pool_size = 100 pool_size = 100

View file

@ -20,6 +20,11 @@ worker_id = 'pict-rs-1'
# Not specifying api_key disables internal endpoints # Not specifying api_key disables internal endpoints
api_key = 'API_KEY' 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 configuration
[client] [client]
## Optional: connection pool size for internal http client ## Optional: connection pool size for internal http client

View file

@ -88,6 +88,7 @@ impl Args {
media_video_quality_2160, media_video_quality_2160,
media_filters, media_filters,
read_only, read_only,
max_file_count,
store, store,
}) => { }) => {
let server = Server { let server = Server {
@ -95,6 +96,7 @@ impl Args {
api_key, api_key,
worker_id, worker_id,
read_only, read_only,
max_file_count,
}; };
let client = Client { let client = Client {
@ -363,6 +365,8 @@ struct Server {
api_key: Option<String>, api_key: Option<String>,
#[serde(skip_serializing_if = "std::ops::Not::not")] #[serde(skip_serializing_if = "std::ops::Not::not")]
read_only: bool, read_only: bool,
#[serde(skip_serializing_if = "Option::is_none")]
max_file_count: Option<u32>,
} }
#[derive(Debug, Default, serde::Serialize)] #[derive(Debug, Default, serde::Serialize)]
@ -719,6 +723,12 @@ struct Run {
#[arg(long)] #[arg(long)]
client_timeout: Option<u64>, client_timeout: Option<u64>,
/// How many files are allowed to be uploaded per-request
///
/// This number defaults to 1
#[arg(long)]
max_file_count: Option<u32>,
/// Optional pre-processing steps for uploaded media. /// Optional pre-processing steps for uploaded media.
/// ///
/// All still images will be put through these steps before saving /// All still images will be put through these steps before saving

View file

@ -23,6 +23,7 @@ struct ServerDefaults {
address: SocketAddr, address: SocketAddr,
worker_id: String, worker_id: String,
read_only: bool, read_only: bool,
max_file_count: u32,
} }
#[derive(Clone, Debug, serde::Serialize)] #[derive(Clone, Debug, serde::Serialize)]
@ -175,6 +176,7 @@ impl Default for ServerDefaults {
address: "0.0.0.0:8080".parse().expect("Valid address string"), address: "0.0.0.0:8080".parse().expect("Valid address string"),
worker_id: String::from("pict-rs-1"), worker_id: String::from("pict-rs-1"),
read_only: false, read_only: false,
max_file_count: 1,
} }
} }
} }

View file

@ -99,6 +99,8 @@ pub(crate) struct Server {
pub(crate) api_key: Option<String>, pub(crate) api_key: Option<String>,
pub(crate) read_only: bool, pub(crate) read_only: bool,
pub(crate) max_file_count: u32,
} }
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)] #[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]

View file

@ -161,7 +161,7 @@ impl<R: FullRepo, S: Store + 'static> FormData for Upload<R, S> {
.clone(); .clone();
Form::new() Form::new()
.max_files(10) .max_files(CONFIG.server.max_file_count)
.max_file_size(CONFIG.media.max_file_size * MEGABYTES) .max_file_size(CONFIG.media.max_file_size * MEGABYTES)
.transform_error(transform_error) .transform_error(transform_error)
.field( .field(
@ -213,7 +213,7 @@ impl<R: FullRepo, S: Store + 'static> FormData for Import<R, S> {
// //
// This form is expecting a single array field, 'images' with at most 10 files in it // This form is expecting a single array field, 'images' with at most 10 files in it
Form::new() Form::new()
.max_files(10) .max_files(CONFIG.server.max_file_count)
.max_file_size(CONFIG.media.max_file_size * MEGABYTES) .max_file_size(CONFIG.media.max_file_size * MEGABYTES)
.transform_error(transform_error) .transform_error(transform_error)
.field( .field(
@ -339,7 +339,7 @@ impl<R: FullRepo, S: Store + 'static> FormData for BackgroundedUpload<R, S> {
.clone(); .clone();
Form::new() Form::new()
.max_files(10) .max_files(CONFIG.server.max_file_count)
.max_file_size(CONFIG.media.max_file_size * MEGABYTES) .max_file_size(CONFIG.media.max_file_size * MEGABYTES)
.transform_error(transform_error) .transform_error(transform_error)
.field( .field(