fix
This commit is contained in:
parent
2e55e6ce09
commit
d0623e3282
@ -1,5 +1,5 @@
|
|||||||
use config::{Config, ConfigError, Environment, File};
|
use config::{Config, ConfigError, Environment, File};
|
||||||
use serde::Deserialize;
|
use serde::{Deserialize, Deserializer};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
#[derive(Debug, Clone, Deserialize)]
|
||||||
@ -32,6 +32,7 @@ pub struct Settings {
|
|||||||
pub card_master_url: String,
|
pub card_master_url: String,
|
||||||
|
|
||||||
// File paths
|
// File paths
|
||||||
|
#[serde(deserialize_with = "deserialize_pathbuf")]
|
||||||
pub config_dir: PathBuf,
|
pub config_dir: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,7 +75,7 @@ impl Settings {
|
|||||||
.set_default("card_master_url", "https://git.syui.ai/ai/ai/raw/branch/main/ai.json")?;
|
.set_default("card_master_url", "https://git.syui.ai/ai/ai/raw/branch/main/ai.json")?;
|
||||||
|
|
||||||
// Load from config file if it exists
|
// Load from config file if it exists
|
||||||
let config_file = config_dir.join("config.toml");
|
let config_file = config_dir.join("config.json");
|
||||||
if config_file.exists() {
|
if config_file.exists() {
|
||||||
builder = builder.add_source(File::from(config_file));
|
builder = builder.add_source(File::from(config_file));
|
||||||
}
|
}
|
||||||
@ -124,4 +125,12 @@ impl GachaConfig {
|
|||||||
(self.prob_normal, crate::models::CardRarity::Normal),
|
(self.prob_normal, crate::models::CardRarity::Normal),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn deserialize_pathbuf<'de, D>(deserializer: D) -> Result<PathBuf, D::Error>
|
||||||
|
where
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
|
let s = String::deserialize(deserializer)?;
|
||||||
|
Ok(PathBuf::from(s))
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user