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 default_yml = read_default_yml()?;
|
||||||
let db = default_yml
|
let db = default_yml
|
||||||
.get("db")
|
.get("db")
|
||||||
.map(|db| db.as_hash())
|
.and_then(|db| db.as_hash())
|
||||||
.flatten()
|
|
||||||
.ok_or(Error::InvalidConfig("`db` is missing"))?;
|
.ok_or(Error::InvalidConfig("`db` is missing"))?;
|
||||||
|
|
||||||
let meta = read_meta_table(
|
let meta = read_meta_table(
|
||||||
db.get(&Yaml::String("host".to_string()))
|
db.get(&Yaml::String("host".to_string()))
|
||||||
.map(|v| v.as_str())
|
.and_then(|v| v.as_str())
|
||||||
.flatten()
|
|
||||||
.ok_or(Error::InvalidConfig("db.host"))?,
|
.ok_or(Error::InvalidConfig("db.host"))?,
|
||||||
db.get(&Yaml::String("port".to_string()))
|
db.get(&Yaml::String("port".to_string()))
|
||||||
.map(|v| v.as_i64())
|
.and_then(|v| v.as_i64())
|
||||||
.flatten()
|
|
||||||
.ok_or(Error::InvalidConfig("db.port"))? as u16,
|
.ok_or(Error::InvalidConfig("db.port"))? as u16,
|
||||||
db.get(&Yaml::String("user".to_string()))
|
db.get(&Yaml::String("user".to_string()))
|
||||||
.map(|v| v.as_str())
|
.and_then(|v| v.as_str())
|
||||||
.flatten()
|
|
||||||
.ok_or(Error::InvalidConfig("db.user"))?,
|
.ok_or(Error::InvalidConfig("db.user"))?,
|
||||||
db.get(&Yaml::String("pass".to_string()))
|
db.get(&Yaml::String("pass".to_string()))
|
||||||
.map(|v| v.as_str())
|
.and_then(|v| v.as_str())
|
||||||
.flatten()
|
|
||||||
.ok_or(Error::InvalidConfig("db.pass"))?,
|
.ok_or(Error::InvalidConfig("db.pass"))?,
|
||||||
db.get(&Yaml::String("db".to_string()))
|
db.get(&Yaml::String("db".to_string()))
|
||||||
.map(|v| v.as_str())
|
.and_then(|v| v.as_str())
|
||||||
.flatten()
|
|
||||||
.ok_or(Error::InvalidConfig("db.db"))?,
|
.ok_or(Error::InvalidConfig("db.db"))?,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
@ -220,20 +214,17 @@ fn create_new_server_config(
|
||||||
) -> Result<server::Config, Error> {
|
) -> Result<server::Config, Error> {
|
||||||
let db = default_yml
|
let db = default_yml
|
||||||
.get("db")
|
.get("db")
|
||||||
.map(|db| db.as_hash())
|
.and_then(|db| db.as_hash())
|
||||||
.flatten()
|
|
||||||
.ok_or(Error::InvalidConfig("`db` is missing"))?;
|
.ok_or(Error::InvalidConfig("`db` is missing"))?;
|
||||||
|
|
||||||
let redis = default_yml
|
let redis = default_yml
|
||||||
.get("redis")
|
.get("redis")
|
||||||
.map(|redis| redis.as_hash())
|
.and_then(|redis| redis.as_hash())
|
||||||
.flatten()
|
|
||||||
.ok_or(Error::InvalidConfig("`redis` is missing"))?;
|
.ok_or(Error::InvalidConfig("`redis` is missing"))?;
|
||||||
|
|
||||||
let server_url = default_yml
|
let server_url = default_yml
|
||||||
.get("url")
|
.get("url")
|
||||||
.map(|url| url.as_str())
|
.and_then(|url| url.as_str())
|
||||||
.flatten()
|
|
||||||
.ok_or(Error::InvalidConfig("`url` is missing"))?;
|
.ok_or(Error::InvalidConfig("`url` is missing"))?;
|
||||||
|
|
||||||
let parsed_server_url = Url::parse(server_url)?;
|
let parsed_server_url = Url::parse(server_url)?;
|
||||||
|
@ -285,52 +276,44 @@ fn create_new_server_config(
|
||||||
host,
|
host,
|
||||||
port: default_yml
|
port: default_yml
|
||||||
.get("port")
|
.get("port")
|
||||||
.map(|v| v.as_i64())
|
.and_then(|v| v.as_i64())
|
||||||
.flatten()
|
|
||||||
.ok_or(Error::InvalidConfig("port"))? as u16,
|
.ok_or(Error::InvalidConfig("port"))? as u16,
|
||||||
},
|
},
|
||||||
database: server::Database {
|
database: server::Database {
|
||||||
host: db
|
host: db
|
||||||
.get(&Yaml::String("host".to_string()))
|
.get(&Yaml::String("host".to_string()))
|
||||||
.map(|v| v.as_str())
|
.and_then(|v| v.as_str())
|
||||||
.flatten()
|
|
||||||
.ok_or(Error::InvalidConfig("db.host"))?
|
.ok_or(Error::InvalidConfig("db.host"))?
|
||||||
.to_string(),
|
.to_string(),
|
||||||
port: db
|
port: db
|
||||||
.get(&Yaml::String("port".to_string()))
|
.get(&Yaml::String("port".to_string()))
|
||||||
.map(|v| v.as_i64())
|
.and_then(|v| v.as_i64())
|
||||||
.flatten()
|
|
||||||
.ok_or(Error::InvalidConfig("db.port"))? as u16,
|
.ok_or(Error::InvalidConfig("db.port"))? as u16,
|
||||||
user: db
|
user: db
|
||||||
.get(&Yaml::String("user".to_string()))
|
.get(&Yaml::String("user".to_string()))
|
||||||
.map(|v| v.as_str())
|
.and_then(|v| v.as_str())
|
||||||
.flatten()
|
|
||||||
.ok_or(Error::InvalidConfig("db.user"))?
|
.ok_or(Error::InvalidConfig("db.user"))?
|
||||||
.to_string(),
|
.to_string(),
|
||||||
password: db
|
password: db
|
||||||
.get(&Yaml::String("pass".to_string()))
|
.get(&Yaml::String("pass".to_string()))
|
||||||
.map(|v| v.as_str())
|
.and_then(|v| v.as_str())
|
||||||
.flatten()
|
|
||||||
.ok_or(Error::InvalidConfig("db.pass"))?
|
.ok_or(Error::InvalidConfig("db.pass"))?
|
||||||
.to_string(),
|
.to_string(),
|
||||||
name: db
|
name: db
|
||||||
.get(&Yaml::String("db".to_string()))
|
.get(&Yaml::String("db".to_string()))
|
||||||
.map(|v| v.as_str())
|
.and_then(|v| v.as_str())
|
||||||
.flatten()
|
|
||||||
.ok_or(Error::InvalidConfig("db.db"))?
|
.ok_or(Error::InvalidConfig("db.db"))?
|
||||||
.to_string(),
|
.to_string(),
|
||||||
},
|
},
|
||||||
cache_server: server::CacheServer {
|
cache_server: server::CacheServer {
|
||||||
host: redis
|
host: redis
|
||||||
.get(&Yaml::String("host".to_string()))
|
.get(&Yaml::String("host".to_string()))
|
||||||
.map(|v| v.as_str())
|
.and_then(|v| v.as_str())
|
||||||
.flatten()
|
|
||||||
.ok_or(Error::InvalidConfig("redis.host"))?
|
.ok_or(Error::InvalidConfig("redis.host"))?
|
||||||
.to_string(),
|
.to_string(),
|
||||||
port: redis
|
port: redis
|
||||||
.get(&Yaml::String("port".to_string()))
|
.get(&Yaml::String("port".to_string()))
|
||||||
.map(|v| v.as_i64())
|
.and_then(|v| v.as_i64())
|
||||||
.flatten()
|
|
||||||
.ok_or(Error::InvalidConfig("redis.port"))? as u16,
|
.ok_or(Error::InvalidConfig("redis.port"))? as u16,
|
||||||
user: match redis.get(&Yaml::String("user".to_string())) {
|
user: match redis.get(&Yaml::String("user".to_string())) {
|
||||||
Some(user) => Some(
|
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 {
|
config.image = Some(client::Image {
|
||||||
|
logo: meta.logo_image_url,
|
||||||
icon: meta.icon_url,
|
icon: meta.icon_url,
|
||||||
banner: meta.banner_url,
|
banner: meta.banner_url,
|
||||||
background: meta.background_image_url,
|
background: meta.background_image_url,
|
||||||
|
error: meta.error_image_url,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,12 +28,16 @@ pub struct Theme {
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Validate, Debug)]
|
#[derive(Deserialize, Serialize, Validate, Debug)]
|
||||||
pub struct Image {
|
pub struct Image {
|
||||||
|
#[validate(url)]
|
||||||
|
pub logo: Option<String>,
|
||||||
#[validate(url)]
|
#[validate(url)]
|
||||||
pub icon: Option<String>,
|
pub icon: Option<String>,
|
||||||
#[validate(url)]
|
#[validate(url)]
|
||||||
pub banner: Option<String>,
|
pub banner: Option<String>,
|
||||||
#[validate(url)]
|
#[validate(url)]
|
||||||
pub background: Option<String>,
|
pub background: Option<String>,
|
||||||
|
#[validate(url)]
|
||||||
|
pub error: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Validate, Debug)]
|
#[derive(Deserialize, Serialize, Validate, Debug)]
|
||||||
|
|
Loading…
Reference in a new issue