diff --git a/filed/config/filed.toml.example b/filed/config/filed.toml.example index a5df269..c92639d 100644 --- a/filed/config/filed.toml.example +++ b/filed/config/filed.toml.example @@ -93,3 +93,14 @@ upload=false # Whether curlapi is enabled # curl {url}/curlapi/help for more info curlapi=true + +# Resources section + +# Define your resources like this: +# [resources."org.name.logo"] + +# Make sure that this path exists within the fileD filesystem +# path="/some/place" + +# https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types +# mime="image/webp" \ No newline at end of file diff --git a/filed/src/config/resource/types.rs b/filed/src/config/resource/types.rs index 383c159..407f75f 100644 --- a/filed/src/config/resource/types.rs +++ b/filed/src/config/resource/types.rs @@ -19,6 +19,10 @@ impl ResourceCollection { } Ok(()) } + + pub fn get>(self: &Self, key: T) -> Option<&Resource> { + self.0.get(&key.into()) + } } #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/filed/src/config/types.rs b/filed/src/config/types.rs index feffa1a..0ad2722 100644 --- a/filed/src/config/types.rs +++ b/filed/src/config/types.rs @@ -148,11 +148,14 @@ impl FilesPolicy { } impl Branding { - fn validate(self: &Self) -> Result<(), String> { - if let Some(logo_path) = self.custom_logo.clone() { - let logo_path = Path::new(&logo_path); - if ! logo_path.is_file() { - return Err("Config parameter branding.custom_logo is not a file. It must be a valid path that should be accessible from fileD's filesystem".into()) + fn validate(self: &Self, conf: &Config) -> Result<(), String> { + if let Some(logo_id) = self.custom_logo.clone() { + if let Some(ref resources) = conf.resources { + if resources.get(&logo_id).is_none() { + return Err(format!("Brand logo is set to a non existant resource ({logo_id})")); + } + } else { + return Err("Brand logo specified but no resources found".into()) } } Ok(()) @@ -177,11 +180,11 @@ impl Config { pub fn validate(self: &Self) -> Result<(), String> { self.files.validate()?; - self.brand.validate()?; self.api .validate()?; if let Some(resources) = self.resources.clone() { resources.validate()?; } + self.brand.validate(self)?; Ok(()) }