diff options
Diffstat (limited to 'server/src/config.rs')
| -rw-r--r-- | server/src/config.rs | 53 |
1 files changed, 32 insertions, 21 deletions
diff --git a/server/src/config.rs b/server/src/config.rs index f552306..73d6b73 100644 --- a/server/src/config.rs +++ b/server/src/config.rs @@ -6,20 +6,33 @@ use anyhow::{Context, Result, anyhow}; use jellycache::init_cache; -use jellylogic::init_database; use serde::Deserialize; -use std::env::{args, var}; +use std::{ + env::{args, var}, + path::PathBuf, + sync::{LazyLock, Mutex}, +}; use tokio::fs::read_to_string; +static CONF_PRELOAD: Mutex<Option<AllConfigs>> = Mutex::new(None); +pub static CONF: LazyLock<AllConfigs> = + LazyLock::new(|| CONF_PRELOAD.lock().unwrap().take().unwrap()); + +pub struct AllConfigs { + pub ui: jellyui::Config, + pub transcoder: jellytranscoder::Config, + pub stream: jellystream::Config, + pub cache: jellycache::Config, + pub import: jellyimport::Config, + pub server: Config, +} + #[derive(Debug, Deserialize)] -struct Config { - transcoder: jellytranscoder::Config, - ui: jellyui::Config, - stream: jellystream::Config, - cache: jellycache::Config, - server: crate::Config, - logic: jellylogic::Config, - import: jellyimport::Config, +pub struct Config { + pub asset_path: PathBuf, + pub cookie_key: Option<String>, + pub tls: bool, + pub hostname: String, } pub async fn load_config() -> Result<()> { @@ -30,19 +43,17 @@ pub async fn load_config() -> Result<()> { "No config supplied. Use first argument or JELLYTHING_CONFIG environment variable." ))?; - let config_raw = read_to_string(path).await.context("reading main config")?; - let config: Config = serde_yaml_ng::from_str(&config_raw).context("parsing main config")?; - - *jellystream::CONF_PRELOAD.lock().unwrap() = Some(config.stream); - *jellytranscoder::CONF_PRELOAD.lock().unwrap() = Some(config.transcoder); - *jellycache::CONF_PRELOAD.lock().unwrap() = Some(config.cache); - *jellylogic::CONF_PRELOAD.lock().unwrap() = Some(config.logic); - *jellyimport::CONF_PRELOAD.lock().unwrap() = Some(config.import); - *crate::CONF_PRELOAD.lock().unwrap() = Some(config.server); - *jellyui::CONF_PRELOAD.lock().unwrap() = Some(config.ui); + let config = read_to_string(path).await.context("reading main config")?; + *CONF_PRELOAD.lock().unwrap() = Some(AllConfigs { + ui: serde_yaml_ng::from_str(&config).context("ui config")?, + transcoder: serde_yaml_ng::from_str(&config).context("transcoder config")?, + stream: serde_yaml_ng::from_str(&config).context("stream config")?, + cache: serde_yaml_ng::from_str(&config).context("cache config")?, + import: serde_yaml_ng::from_str(&config).context("import config")?, + server: serde_yaml_ng::from_str(&config).context("server config")?, + }); init_cache()?; - init_database()?; Ok(()) } |