2024-11-05 20:39:21 +00:00
|
|
|
use std::sync::OnceLock;
|
|
|
|
use rocket::get;
|
2025-04-03 12:25:45 +00:00
|
|
|
use sys_locale::get_locale;
|
2024-11-05 20:39:21 +00:00
|
|
|
use crate::api_token::APIToken;
|
|
|
|
|
|
|
|
/// The data directory where the application stores its data.
|
|
|
|
pub static DATA_DIRECTORY: OnceLock<String> = OnceLock::new();
|
|
|
|
|
|
|
|
/// The config directory where the application stores its configuration.
|
|
|
|
pub static CONFIG_DIRECTORY: OnceLock<String> = OnceLock::new();
|
|
|
|
|
|
|
|
/// Returns the config directory.
|
|
|
|
#[get("/system/directories/config")]
|
|
|
|
pub fn get_config_directory(_token: APIToken) -> String {
|
|
|
|
match CONFIG_DIRECTORY.get() {
|
|
|
|
Some(config_directory) => config_directory.clone(),
|
|
|
|
None => String::from(""),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the data directory.
|
|
|
|
#[get("/system/directories/data")]
|
|
|
|
pub fn get_data_directory(_token: APIToken) -> String {
|
|
|
|
match DATA_DIRECTORY.get() {
|
|
|
|
Some(data_directory) => data_directory.clone(),
|
|
|
|
None => String::from(""),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns true if the application is running in development mode.
|
|
|
|
pub fn is_dev() -> bool {
|
|
|
|
cfg!(debug_assertions)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns true if the application is running in production mode.
|
|
|
|
pub fn is_prod() -> bool {
|
|
|
|
!is_dev()
|
2025-04-03 12:25:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[get("/system/language")]
|
|
|
|
pub fn read_user_language(_token: APIToken) -> String {
|
|
|
|
get_locale().unwrap_or_else(|| {
|
|
|
|
log::warn!("Could not determine the system language. Use default 'en-US'.");
|
|
|
|
String::from("en-US")
|
|
|
|
})
|
2024-11-05 20:39:21 +00:00
|
|
|
}
|