mirror of
https://git.asonix.dog/asonix/pict-rs.git
synced 2024-11-25 02:51:17 +00:00
Update cli flags
This commit is contained in:
parent
3fe66129be
commit
9559a8b202
3 changed files with 21 additions and 23 deletions
|
@ -26,7 +26,10 @@ OPTIONS:
|
|||
--api-key <api-key>
|
||||
An optional string to be checked on requests to privileged endpoints [env: PICTRS_API_KEY=]
|
||||
|
||||
-f, --format <format>
|
||||
-f, --filters <filters>...
|
||||
An optional list of filters to permit, supports 'identity', 'thumbnail', 'resize', 'crop', and 'blur' [env:
|
||||
PICTRS_ALLOWED_FILTERS=]
|
||||
-i, --image-format <image-format>
|
||||
An optional image format to convert all uploaded files into, supports 'jpg', 'png', and 'webp' [env:
|
||||
PICTRS_FORMAT=]
|
||||
-m, --max-file-size <max-file-size>
|
||||
|
@ -42,9 +45,6 @@ OPTIONS:
|
|||
Enable OpenTelemetry Tracing exports to the given OpenTelemetry collector [env: PICTRS_OPENTELEMETRY_URL=]
|
||||
|
||||
-p, --path <path> The path to the data directory, e.g. data/ [env: PICTRS_PATH=]
|
||||
-w, --whitelist <whitelist>...
|
||||
An optional list of filters to whitelist, supports 'identity', 'thumbnail', and 'blur' [env:
|
||||
PICTRS_FILTER_WHITELIST=]
|
||||
```
|
||||
|
||||
#### Example:
|
||||
|
|
|
@ -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<Format>,
|
||||
image_format: Option<Format>,
|
||||
|
||||
#[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<Vec<String>>,
|
||||
filters: Option<Vec<String>>,
|
||||
|
||||
#[structopt(
|
||||
short,
|
||||
|
@ -94,13 +94,11 @@ impl Config {
|
|||
}
|
||||
|
||||
pub(crate) fn format(&self) -> Option<Format> {
|
||||
self.format.clone()
|
||||
self.image_format.clone()
|
||||
}
|
||||
|
||||
pub(crate) fn filter_whitelist(&self) -> Option<HashSet<String>> {
|
||||
self.whitelist
|
||||
.as_ref()
|
||||
.map(|wl| wl.iter().cloned().collect())
|
||||
pub(crate) fn allowed_filters(&self) -> Option<HashSet<String>> {
|
||||
self.filters.as_ref().map(|wl| wl.iter().cloned().collect())
|
||||
}
|
||||
|
||||
pub(crate) fn validate_imports(&self) -> bool {
|
||||
|
|
20
src/main.rs
20
src/main.rs
|
@ -408,7 +408,7 @@ async fn prepare_process(
|
|||
query: web::Query<ProcessQuery>,
|
||||
ext: &str,
|
||||
manager: &UploadManager,
|
||||
whitelist: &Option<HashSet<String>>,
|
||||
filters: &Option<HashSet<String>>,
|
||||
) -> Result<(Format, String, PathBuf, Vec<String>), 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<ProcessQuery>,
|
||||
ext: web::Path<String>,
|
||||
manager: web::Data<UploadManager>,
|
||||
whitelist: web::Data<Option<HashSet<String>>>,
|
||||
filters: web::Data<Option<HashSet<String>>>,
|
||||
) -> Result<HttpResponse, Error> {
|
||||
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<range::RangeHeader>,
|
||||
query: web::Query<ProcessQuery>,
|
||||
ext: web::Path<String>,
|
||||
manager: web::Data<UploadManager>,
|
||||
whitelist: web::Data<Option<HashSet<String>>>,
|
||||
filters: web::Data<Option<HashSet<String>>>,
|
||||
) -> Result<HttpResponse, Error> {
|
||||
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(
|
||||
|
|
Loading…
Reference in a new issue