diff --git a/ui/src/conf.rs b/ui/src/conf.rs index 503abd2a..93fe3c65 100644 --- a/ui/src/conf.rs +++ b/ui/src/conf.rs @@ -148,13 +148,15 @@ impl FolderConf { } } +use crate::conf::deserializers::extra_settings; #[derive(Debug, Clone, Default, Serialize, Deserialize)] pub struct FileAccount { root_folder: String, format: String, identity: String, #[serde(flatten)] - pub extra: HashMap, + #[serde(deserialize_with = "extra_settings")] + pub extra: HashMap, /* use custom deserializer to convert any given value (eg bool, number, etc) to string */ #[serde(default = "none")] display_name: Option, @@ -489,6 +491,37 @@ mod deserializers { Ok(Some(s)) } } + + use toml::Value; + fn any_of<'de, D>(deserializer: D) -> std::result::Result + where + D: Deserializer<'de>, + { + let v: Value = Deserialize::deserialize(deserializer)?; + let mut ret = v.to_string(); + if ret.starts_with('"') && ret.ends_with('"') { + ret.drain(0..1).count(); + ret.drain(ret.len() - 1..).count(); + } + Ok(ret) + } + + use std::collections::HashMap; + pub(in crate::conf) fn extra_settings<'de, D>( + deserializer: D, + ) -> std::result::Result, D::Error> + where + D: Deserializer<'de>, + { + /* Why is this needed? If the user gives a configuration value such as key = true, the + * parsing will fail since it expects string values. We want to accept key = true as well + * as key = "true". */ + #[derive(Deserialize)] + struct Wrapper(#[serde(deserialize_with = "any_of")] String); + + let v = >::deserialize(deserializer)?; + Ok(v.into_iter().map(|(k, Wrapper(v))| (k, v)).collect()) + } } impl<'de> Deserialize<'de> for IndexStyle {