From a9ee18dcbbf837225f05d4dd0186fc989a319c63 Mon Sep 17 00:00:00 2001 From: Johannes May Date: Sat, 12 Mar 2022 22:12:35 +0100 Subject: Allow to set the accept input attribute to arbitrary values --- src/config.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src/config.rs') diff --git a/src/config.rs b/src/config.rs index 73fcec2..1bb8e08 100644 --- a/src/config.rs +++ b/src/config.rs @@ -13,7 +13,10 @@ use http::HeaderMap; #[cfg(feature = "tls")] use rustls_pemfile as pemfile; -use crate::{args::CliArgs, auth::RequiredAuth}; +use crate::{ + args::{CliArgs, MediaType}, + auth::RequiredAuth, +}; /// Possible characters for random routes const ROUTE_ALPHABET: [char; 16] = [ @@ -81,6 +84,9 @@ pub struct MiniserveConfig { /// Enable file upload pub file_upload: bool, + /// HTML accept attribute value + pub uploadable_media_type: Option, + /// Enable upload to override existing files pub overwrite_files: bool, @@ -188,6 +194,20 @@ impl MiniserveConfig { #[cfg(not(feature = "tls"))] let tls_rustls_server_config = None; + let uploadable_media_type = args.media_type_raw.or_else(|| { + args.media_type.map(|types| { + types + .into_iter() + .map(|t| match t { + MediaType::Audio => "audio/*", + MediaType::Image => "image/*", + MediaType::Video => "video/*", + }) + .collect::>() + .join(",") + }) + }); + Ok(MiniserveConfig { verbose: args.verbose, path: args.path.unwrap_or_else(|| PathBuf::from(".")), @@ -207,6 +227,7 @@ impl MiniserveConfig { overwrite_files: args.overwrite_files, show_qrcode: args.qrcode, file_upload: args.file_upload, + uploadable_media_type, tar_enabled: args.enable_tar, tar_gz_enabled: args.enable_tar_gz, zip_enabled: args.enable_zip, -- cgit v1.2.3