diff --git a/src/constants.rs b/src/constants.rs index 156aa8e..92e0d57 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -14,4 +14,10 @@ pub mod database_tables_names { /// User table pub const USERS_TABLE: &str = "utilisateurs"; -} \ No newline at end of file +} + +/// The account image to show for user who do not have any +pub const DEFAULT_ACCOUNT_IMAGE: &str = "avatars/0Reverse.png"; + +/// The account image to show for users who are not allowed to access other users account images +pub const ERROR_ACCOUNT_IMAGE: &str = "avatars/0Red.png"; \ No newline at end of file diff --git a/src/data/user.rs b/src/data/user.rs index c3c411f..8024777 100644 --- a/src/data/user.rs +++ b/src/data/user.rs @@ -1,3 +1,5 @@ +use crate::utils::user_data_utils::user_data_url; + ///! User information ///! ///! @author Pierre Hubert @@ -30,4 +32,18 @@ pub struct User { pub virtual_directory: Option, pub account_image_path: Option, pub account_image_visibility: AccountImageVisibility, +} + +impl User { + + /// Get the URL pointing to the default account image + pub fn default_account_image_url() -> String { + user_data_url(crate::constants::DEFAULT_ACCOUNT_IMAGE) + } + + /// Get the URL pointing to the error account image, when the user is not allowed to see user + /// account image + pub fn error_account_image_url() -> String { + user_data_url(crate::constants::ERROR_ACCOUNT_IMAGE) + } } \ No newline at end of file diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 632812e..ab27a0d 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -2,4 +2,5 @@ //! //! This module contains utilities that can be used anywhere in the code -pub mod crypt_utils; \ No newline at end of file +pub mod crypt_utils; +pub mod user_data_utils; \ No newline at end of file diff --git a/src/utils/user_data_utils.rs b/src/utils/user_data_utils.rs new file mode 100644 index 0000000..a262d4a --- /dev/null +++ b/src/utils/user_data_utils.rs @@ -0,0 +1,12 @@ +//! # User data utilities +//! +//! @author Pierre Hubert + +use crate::data::config::conf; + +/// Get the full URL to a user data file +/// +/// `uri` should contain the path to the target resource +pub fn user_data_url(uri: &str) -> String { + format!("{}{}", conf().storage_url, uri) +} \ No newline at end of file