♻️ refactor: move file server runtime state into file_server

main
_ 2020-12-20 18:10:11 +00:00
parent 31750d30fc
commit 1aff4389bd
2 changed files with 10 additions and 9 deletions

View File

@ -28,18 +28,12 @@ use ptth_server::{
file_server::{ file_server::{
self, self,
metrics, metrics,
State,
}, },
load_toml, load_toml,
}; };
struct ServerState <'a> { async fn handle_all (req: Request <Body>, state: Arc <State <'static>>)
config: file_server::Config,
handlebars: handlebars::Handlebars <'a>,
instance_metrics: metrics::Startup,
hidden_path: Option <PathBuf>,
}
async fn handle_all (req: Request <Body>, state: Arc <ServerState <'static>>)
-> Result <Response <Body>, anyhow::Error> -> Result <Response <Body>, anyhow::Error>
{ {
use std::str::FromStr; use std::str::FromStr;
@ -106,7 +100,7 @@ async fn main () -> Result <(), anyhow::Error> {
debug! ("{:?}", instance_metrics); debug! ("{:?}", instance_metrics);
let state = Arc::new (ServerState { let state = Arc::new (State {
config: file_server::Config { config: file_server::Config {
file_server_root: config_file.file_server_root, file_server_root: config_file.file_server_root,
}, },

View File

@ -61,6 +61,13 @@ pub struct Config {
pub file_server_root: Option <PathBuf>, pub file_server_root: Option <PathBuf>,
} }
pub struct State <'a> {
pub config: Config,
pub handlebars: handlebars::Handlebars <'a>,
pub instance_metrics: metrics::Startup,
pub hidden_path: Option <PathBuf>,
}
#[derive (Serialize)] #[derive (Serialize)]
struct DirEntryJson { struct DirEntryJson {
name: String, name: String,