feat: add ability to put the themes folder on different paths

This commit is contained in:
neon_arch 2023-05-24 17:37:41 +03:00
parent 707bf153cd
commit 29456650f1
4 changed files with 48 additions and 4 deletions

1
src/theme_handler/mod.rs Normal file
View file

@ -0,0 +1 @@
pub mod theme_path_handler;

View file

@ -0,0 +1,31 @@
//! This module provides the functionality to handle theme folder present on different paths and
//! provide one appropriate path on which it is present and can be used.
use std::io::Error;
use std::path::Path;
// ------- Constants --------
static THEME_DIRECTORY_NAME: &str = "public";
/// A function which returns an appropriate theme directory path checking if the theme
/// directory exists on that path.
///
/// # Error
///
/// Returns a `Theme (public) folder not found!!` error if the theme folder is not present under following
/// paths which are:
/// 1. `/opt/websurfx` if it not present here then it fallbacks to the next one (2)
/// 2. Under project folder ( or codebase in other words) if it is not present
/// here then it returns an error as mentioned above.
pub fn handle_different_theme_path() -> Result<String, Error> {
if Path::new(format!("/opt/websurfx/{}/", THEME_DIRECTORY_NAME).as_str()).exists() {
Ok(format!("/opt/websurfx/{}", THEME_DIRECTORY_NAME))
} else if Path::new(format!("./{}/", THEME_DIRECTORY_NAME).as_str()).exists() {
Ok(format!("./{}", THEME_DIRECTORY_NAME))
} else {
Err(Error::new(
std::io::ErrorKind::NotFound,
"Themes (public) folder not found!!",
))
}
}