2
0
Fork 0
mirror of https://git.asonix.dog/asonix/pict-rs synced 2024-11-20 03:11:14 +00:00

Make max file count configurable

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]]
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",

View file

@ -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 }

View file

@ -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

View file

@ -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

View file

@ -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<String>,
#[serde(skip_serializing_if = "std::ops::Not::not")]
read_only: bool,
#[serde(skip_serializing_if = "Option::is_none")]
max_file_count: Option<u32>,
}
#[derive(Debug, Default, serde::Serialize)]
@ -719,6 +723,12 @@ struct Run {
#[arg(long)]
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.
///
/// All still images will be put through these steps before saving

View file

@ -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,
}
}
}

View file

@ -99,6 +99,8 @@ pub(crate) struct Server {
pub(crate) api_key: Option<String>,
pub(crate) read_only: bool,
pub(crate) max_file_count: u32,
}
#[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();
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<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
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<R: FullRepo, S: Store + 'static> FormData for BackgroundedUpload<R, S> {
.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(