👕 refactor: merge the servers' config file and runtime representations
parent
b43106393a
commit
bf8e483d16
|
@ -78,6 +78,7 @@ pub mod file {
|
|||
|
||||
#[derive (Deserialize)]
|
||||
pub struct Server {
|
||||
// This is duplicated in the hashmap, but it's not a problem
|
||||
pub name: String,
|
||||
pub tripcode: BlakeHashWrapper,
|
||||
pub display_name: Option <String>,
|
||||
|
@ -106,33 +107,17 @@ pub mod file {
|
|||
|
||||
// Stuff we actually need at runtime
|
||||
|
||||
pub struct Server {
|
||||
pub tripcode: blake3::Hash,
|
||||
pub display_name: Option <String>,
|
||||
}
|
||||
|
||||
pub struct Config {
|
||||
pub servers: HashMap <String, Server>,
|
||||
pub servers: HashMap <String, file::Server>,
|
||||
pub iso: file::Isomorphic,
|
||||
}
|
||||
|
||||
impl TryFrom <file::Server> for Server {
|
||||
type Error = ConfigError;
|
||||
|
||||
fn try_from (f: file::Server) -> Result <Self, Self::Error> {
|
||||
Ok (Self {
|
||||
tripcode: *f.tripcode,
|
||||
display_name: f.display_name,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom <file::Config> for Config {
|
||||
type Error = ConfigError;
|
||||
|
||||
fn try_from (f: file::Config) -> Result <Self, Self::Error> {
|
||||
let servers = f.servers.into_iter ()
|
||||
.map (|server| Ok::<_, ConfigError> ((server.name.clone (), server.try_into ()?)));
|
||||
.map (|server| Ok::<_, ConfigError> ((server.name.clone (), server)));
|
||||
|
||||
let servers = itertools::process_results (servers, |i| HashMap::from_iter (i))?;
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ pub async fn handle_listen (
|
|||
error! ("Denied http_listen for non-existent server name {}", watcher_code);
|
||||
return trip_error ();
|
||||
},
|
||||
Some (x) => (*x).tripcode,
|
||||
Some (x) => *(*x).tripcode,
|
||||
}
|
||||
};
|
||||
let actual_tripcode = blake3::hash (api_key);
|
||||
|
|
Loading…
Reference in New Issue