44 lines
924 B
Rust
44 lines
924 B
Rust
use std::{
|
|
fs::File,
|
|
io::Read,
|
|
path::{Path, PathBuf},
|
|
};
|
|
|
|
use serde::Deserialize;
|
|
|
|
use crate::Result;
|
|
|
|
#[derive(Deserialize, Clone)]
|
|
pub struct Config {
|
|
admin_password: String,
|
|
site_password: Option<String>,
|
|
files_dir: std::path::PathBuf,
|
|
database_connection: String,
|
|
}
|
|
|
|
impl Config {
|
|
pub fn from_file(path: &str) -> Result<Self> {
|
|
let path = PathBuf::from(path);
|
|
let mut config = String::new();
|
|
File::open(path)?.read_to_string(&mut config)?;
|
|
let config: Config = toml::from_str(&config)?;
|
|
Ok(config)
|
|
}
|
|
|
|
pub fn admin_password(&self) -> &str {
|
|
&self.admin_password
|
|
}
|
|
|
|
pub fn site_password(&self) -> Option<&str> {
|
|
self.site_password.as_deref()
|
|
}
|
|
|
|
pub fn files_dir(&self) -> &Path {
|
|
self.files_dir.as_path()
|
|
}
|
|
|
|
pub fn database_connection(&self) -> &str {
|
|
&self.database_connection
|
|
}
|
|
}
|