blob: 202948a8369e0c627fc6c3b92cc925527b244254 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
/*
This file is part of jellything (https://codeberg.org/metamuffin/jellything)
which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
Copyright (C) 2025 metamuffin <metamuffin.org>
*/
use anyhow::{anyhow, Context, Result};
use serde::Deserialize;
use std::env::{args, var};
use tokio::fs::read_to_string;
#[derive(Debug, Deserialize)]
struct Config {
transcoder: jellytranscoder::Config,
ui: jellyui::Config,
stream: jellystream::Config,
cache: jellycache::Config,
server: crate::Config,
base: jellyimport::asset_token::Config,
logic: jellylogic::Config,
import: jellyimport::Config,
}
pub async fn load_config() -> Result<()> {
let path = args()
.nth(1)
.or_else(|| var("JELLYTHING_CONFIG").ok())
.ok_or(anyhow!(
"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_yml::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::asset_token::CONF_PRELOAD.lock().unwrap() = Some(config.base);
*jellyimport::CONF_PRELOAD.lock().unwrap() = Some(config.import);
*crate::CONF_PRELOAD.lock().unwrap() = Some(config.server);
*jellyui::CONF_PRELOAD.lock().unwrap() = Some(config.ui);
Ok(())
}
|