From 9559a8b2024d16236bcd7d10274238a7d502ad3e Mon Sep 17 00:00:00 2001 From: "Aode (Lion)" Date: Mon, 18 Oct 2021 23:51:04 -0500 Subject: [PATCH] Update cli flags --- README.md | 8 ++++---- src/config.rs | 16 +++++++--------- src/main.rs | 20 ++++++++++---------- 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 0b00261..6dfd263 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,10 @@ OPTIONS: --api-key An optional string to be checked on requests to privileged endpoints [env: PICTRS_API_KEY=] - -f, --format + -f, --filters ... + An optional list of filters to permit, supports 'identity', 'thumbnail', 'resize', 'crop', and 'blur' [env: + PICTRS_ALLOWED_FILTERS=] + -i, --image-format An optional image format to convert all uploaded files into, supports 'jpg', 'png', and 'webp' [env: PICTRS_FORMAT=] -m, --max-file-size @@ -42,9 +45,6 @@ OPTIONS: Enable OpenTelemetry Tracing exports to the given OpenTelemetry collector [env: PICTRS_OPENTELEMETRY_URL=] -p, --path The path to the data directory, e.g. data/ [env: PICTRS_PATH=] - -w, --whitelist ... - An optional list of filters to whitelist, supports 'identity', 'thumbnail', and 'blur' [env: - PICTRS_FILTER_WHITELIST=] ``` #### Example: diff --git a/src/config.rs b/src/config.rs index a6372e4..814620a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -33,15 +33,15 @@ pub(crate) struct Config { env = "PICTRS_FORMAT", help = "An optional image format to convert all uploaded files into, supports 'jpg', 'png', and 'webp'" )] - format: Option, + image_format: Option, #[structopt( short, long, - env = "PICTRS_FILTER_WHITELIST", - help = "An optional list of filters to whitelist, supports 'identity', 'thumbnail', and 'blur'" + env = "PICTRS_ALLOWED_FILTERS", + help = "An optional list of filters to permit, supports 'identity', 'thumbnail', 'resize', 'crop', and 'blur'" )] - whitelist: Option>, + filters: Option>, #[structopt( short, @@ -94,13 +94,11 @@ impl Config { } pub(crate) fn format(&self) -> Option { - self.format.clone() + self.image_format.clone() } - pub(crate) fn filter_whitelist(&self) -> Option> { - self.whitelist - .as_ref() - .map(|wl| wl.iter().cloned().collect()) + pub(crate) fn allowed_filters(&self) -> Option> { + self.filters.as_ref().map(|wl| wl.iter().cloned().collect()) } pub(crate) fn validate_imports(&self) -> bool { diff --git a/src/main.rs b/src/main.rs index 96f3286..c6b3931 100644 --- a/src/main.rs +++ b/src/main.rs @@ -408,7 +408,7 @@ async fn prepare_process( query: web::Query, ext: &str, manager: &UploadManager, - whitelist: &Option>, + filters: &Option>, ) -> Result<(Format, String, PathBuf, Vec), Error> { let (alias, operations) = query @@ -429,10 +429,10 @@ async fn prepare_process( let name = manager.from_alias(alias).await?; - let operations = if let Some(whitelist) = whitelist.as_ref() { + let operations = if let Some(filters) = filters.as_ref() { operations .into_iter() - .filter(|(k, _)| whitelist.contains(&k.to_lowercase())) + .filter(|(k, _)| filters.contains(&k.to_lowercase())) .collect() } else { operations @@ -450,15 +450,15 @@ async fn prepare_process( Ok((format, name, thumbnail_path, thumbnail_args)) } -#[instrument(name = "Fetching derived details", skip(manager, whitelist))] +#[instrument(name = "Fetching derived details", skip(manager, filters))] async fn process_details( query: web::Query, ext: web::Path, manager: web::Data, - whitelist: web::Data>>, + filters: web::Data>>, ) -> Result { let (_, name, thumbnail_path, _) = - prepare_process(query, ext.as_str(), &manager, &whitelist).await?; + prepare_process(query, ext.as_str(), &manager, &filters).await?; let real_path = manager .variant_path(&thumbnail_path, &name) @@ -473,16 +473,16 @@ async fn process_details( } /// Process files -#[instrument(name = "Serving processed image", skip(manager, whitelist))] +#[instrument(name = "Serving processed image", skip(manager, filters))] async fn process( range: Option, query: web::Query, ext: web::Path, manager: web::Data, - whitelist: web::Data>>, + filters: web::Data>>, ) -> Result { let (format, name, thumbnail_path, thumbnail_args) = - prepare_process(query, ext.as_str(), &manager, &whitelist).await?; + prepare_process(query, ext.as_str(), &manager, &filters).await?; let real_path_opt = manager.variant_path(&thumbnail_path, &name).await?; @@ -948,7 +948,7 @@ async fn main() -> Result<(), anyhow::Error> { .wrap(Deadline) .app_data(web::Data::new(manager.clone())) .app_data(web::Data::new(client)) - .app_data(web::Data::new(CONFIG.filter_whitelist())) + .app_data(web::Data::new(CONFIG.allowed_filters())) .service( web::scope("/image") .service(