WIP
This commit is contained in:
parent
33575178d9
commit
80b66fb7ca
2 changed files with 29 additions and 35 deletions
|
@ -183,30 +183,24 @@ async fn read_old_config() -> Result<(HashMap<String, Yaml>, Meta), Error> {
|
|||
let default_yml = read_default_yml()?;
|
||||
let db = default_yml
|
||||
.get("db")
|
||||
.map(|db| db.as_hash())
|
||||
.flatten()
|
||||
.and_then(|db| db.as_hash())
|
||||
.ok_or(Error::InvalidConfig("`db` is missing"))?;
|
||||
|
||||
let meta = read_meta_table(
|
||||
db.get(&Yaml::String("host".to_string()))
|
||||
.map(|v| v.as_str())
|
||||
.flatten()
|
||||
.and_then(|v| v.as_str())
|
||||
.ok_or(Error::InvalidConfig("db.host"))?,
|
||||
db.get(&Yaml::String("port".to_string()))
|
||||
.map(|v| v.as_i64())
|
||||
.flatten()
|
||||
.and_then(|v| v.as_i64())
|
||||
.ok_or(Error::InvalidConfig("db.port"))? as u16,
|
||||
db.get(&Yaml::String("user".to_string()))
|
||||
.map(|v| v.as_str())
|
||||
.flatten()
|
||||
.and_then(|v| v.as_str())
|
||||
.ok_or(Error::InvalidConfig("db.user"))?,
|
||||
db.get(&Yaml::String("pass".to_string()))
|
||||
.map(|v| v.as_str())
|
||||
.flatten()
|
||||
.and_then(|v| v.as_str())
|
||||
.ok_or(Error::InvalidConfig("db.pass"))?,
|
||||
db.get(&Yaml::String("db".to_string()))
|
||||
.map(|v| v.as_str())
|
||||
.flatten()
|
||||
.and_then(|v| v.as_str())
|
||||
.ok_or(Error::InvalidConfig("db.db"))?,
|
||||
)
|
||||
.await?;
|
||||
|
@ -220,20 +214,17 @@ fn create_new_server_config(
|
|||
) -> Result<server::Config, Error> {
|
||||
let db = default_yml
|
||||
.get("db")
|
||||
.map(|db| db.as_hash())
|
||||
.flatten()
|
||||
.and_then(|db| db.as_hash())
|
||||
.ok_or(Error::InvalidConfig("`db` is missing"))?;
|
||||
|
||||
let redis = default_yml
|
||||
.get("redis")
|
||||
.map(|redis| redis.as_hash())
|
||||
.flatten()
|
||||
.and_then(|redis| redis.as_hash())
|
||||
.ok_or(Error::InvalidConfig("`redis` is missing"))?;
|
||||
|
||||
let server_url = default_yml
|
||||
.get("url")
|
||||
.map(|url| url.as_str())
|
||||
.flatten()
|
||||
.and_then(|url| url.as_str())
|
||||
.ok_or(Error::InvalidConfig("`url` is missing"))?;
|
||||
|
||||
let parsed_server_url = Url::parse(server_url)?;
|
||||
|
@ -285,52 +276,44 @@ fn create_new_server_config(
|
|||
host,
|
||||
port: default_yml
|
||||
.get("port")
|
||||
.map(|v| v.as_i64())
|
||||
.flatten()
|
||||
.and_then(|v| v.as_i64())
|
||||
.ok_or(Error::InvalidConfig("port"))? as u16,
|
||||
},
|
||||
database: server::Database {
|
||||
host: db
|
||||
.get(&Yaml::String("host".to_string()))
|
||||
.map(|v| v.as_str())
|
||||
.flatten()
|
||||
.and_then(|v| v.as_str())
|
||||
.ok_or(Error::InvalidConfig("db.host"))?
|
||||
.to_string(),
|
||||
port: db
|
||||
.get(&Yaml::String("port".to_string()))
|
||||
.map(|v| v.as_i64())
|
||||
.flatten()
|
||||
.and_then(|v| v.as_i64())
|
||||
.ok_or(Error::InvalidConfig("db.port"))? as u16,
|
||||
user: db
|
||||
.get(&Yaml::String("user".to_string()))
|
||||
.map(|v| v.as_str())
|
||||
.flatten()
|
||||
.and_then(|v| v.as_str())
|
||||
.ok_or(Error::InvalidConfig("db.user"))?
|
||||
.to_string(),
|
||||
password: db
|
||||
.get(&Yaml::String("pass".to_string()))
|
||||
.map(|v| v.as_str())
|
||||
.flatten()
|
||||
.and_then(|v| v.as_str())
|
||||
.ok_or(Error::InvalidConfig("db.pass"))?
|
||||
.to_string(),
|
||||
name: db
|
||||
.get(&Yaml::String("db".to_string()))
|
||||
.map(|v| v.as_str())
|
||||
.flatten()
|
||||
.and_then(|v| v.as_str())
|
||||
.ok_or(Error::InvalidConfig("db.db"))?
|
||||
.to_string(),
|
||||
},
|
||||
cache_server: server::CacheServer {
|
||||
host: redis
|
||||
.get(&Yaml::String("host".to_string()))
|
||||
.map(|v| v.as_str())
|
||||
.flatten()
|
||||
.and_then(|v| v.as_str())
|
||||
.ok_or(Error::InvalidConfig("redis.host"))?
|
||||
.to_string(),
|
||||
port: redis
|
||||
.get(&Yaml::String("port".to_string()))
|
||||
.map(|v| v.as_i64())
|
||||
.flatten()
|
||||
.and_then(|v| v.as_i64())
|
||||
.ok_or(Error::InvalidConfig("redis.port"))? as u16,
|
||||
user: match redis.get(&Yaml::String("user".to_string())) {
|
||||
Some(user) => Some(
|
||||
|
@ -406,11 +389,18 @@ fn create_new_client_config(meta: Meta) -> Result<client::Config, Error> {
|
|||
});
|
||||
}
|
||||
|
||||
if meta.icon_url.is_some() || meta.banner_url.is_some() || meta.background_image_url.is_some() {
|
||||
if meta.logo_image_url.is_some()
|
||||
|| meta.icon_url.is_some()
|
||||
|| meta.banner_url.is_some()
|
||||
|| meta.background_image_url.is_some()
|
||||
|| meta.error_image_url.is_some()
|
||||
{
|
||||
config.image = Some(client::Image {
|
||||
logo: meta.logo_image_url,
|
||||
icon: meta.icon_url,
|
||||
banner: meta.banner_url,
|
||||
background: meta.background_image_url,
|
||||
error: meta.error_image_url,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -28,12 +28,16 @@ pub struct Theme {
|
|||
|
||||
#[derive(Deserialize, Serialize, Validate, Debug)]
|
||||
pub struct Image {
|
||||
#[validate(url)]
|
||||
pub logo: Option<String>,
|
||||
#[validate(url)]
|
||||
pub icon: Option<String>,
|
||||
#[validate(url)]
|
||||
pub banner: Option<String>,
|
||||
#[validate(url)]
|
||||
pub background: Option<String>,
|
||||
#[validate(url)]
|
||||
pub error: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, Validate, Debug)]
|
||||
|
|
Loading…
Reference in a new issue