From 1aff4389bdcc85f788b254da634ee074ca56e183 Mon Sep 17 00:00:00 2001 From: _ <> Date: Sun, 20 Dec 2020 18:10:11 +0000 Subject: [PATCH] :recycle: refactor: move file server runtime state into file_server --- crates/ptth_file_server_bin/src/main.rs | 12 +++--------- crates/ptth_server/src/file_server/mod.rs | 7 +++++++ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/crates/ptth_file_server_bin/src/main.rs b/crates/ptth_file_server_bin/src/main.rs index 006ca74..6cce5cb 100644 --- a/crates/ptth_file_server_bin/src/main.rs +++ b/crates/ptth_file_server_bin/src/main.rs @@ -28,18 +28,12 @@ use ptth_server::{ file_server::{ self, metrics, + State, }, load_toml, }; -struct ServerState <'a> { - config: file_server::Config, - handlebars: handlebars::Handlebars <'a>, - instance_metrics: metrics::Startup, - hidden_path: Option , -} - -async fn handle_all (req: Request , state: Arc >) +async fn handle_all (req: Request , state: Arc >) -> Result , anyhow::Error> { use std::str::FromStr; @@ -106,7 +100,7 @@ async fn main () -> Result <(), anyhow::Error> { debug! ("{:?}", instance_metrics); - let state = Arc::new (ServerState { + let state = Arc::new (State { config: file_server::Config { file_server_root: config_file.file_server_root, }, diff --git a/crates/ptth_server/src/file_server/mod.rs b/crates/ptth_server/src/file_server/mod.rs index 3c51859..5252534 100644 --- a/crates/ptth_server/src/file_server/mod.rs +++ b/crates/ptth_server/src/file_server/mod.rs @@ -61,6 +61,13 @@ pub struct Config { pub file_server_root: Option , } +pub struct State <'a> { + pub config: Config, + pub handlebars: handlebars::Handlebars <'a>, + pub instance_metrics: metrics::Startup, + pub hidden_path: Option , +} + #[derive (Serialize)] struct DirEntryJson { name: String,