diff --git a/crates/ptth_file_server_bin/src/main.rs b/crates/ptth_file_server_bin/src/main.rs index affc7c1..5921497 100644 --- a/crates/ptth_file_server_bin/src/main.rs +++ b/crates/ptth_file_server_bin/src/main.rs @@ -27,7 +27,7 @@ use ptth_core::{ use ptth_server::{ file_server::{ self, - metrics::InstanceMetrics, + metrics, }, load_toml, }; @@ -40,7 +40,7 @@ pub struct Config { struct ServerState <'a> { config: Config, handlebars: handlebars::Handlebars <'a>, - instance_metrics: InstanceMetrics, + instance_metrics: metrics::PerInstance, hidden_path: Option , } @@ -105,7 +105,7 @@ async fn main () -> Result <(), anyhow::Error> { let handlebars = file_server::load_templates (&PathBuf::new ())?; - let instance_metrics = InstanceMetrics::new ( + let instance_metrics = metrics::PerInstance::new ( config_file.name.unwrap_or_else (|| "PTTH File Server".to_string ()) ); diff --git a/crates/ptth_server/src/file_server/metrics.rs b/crates/ptth_server/src/file_server/metrics.rs index 6c74d3f..e760843 100644 --- a/crates/ptth_server/src/file_server/metrics.rs +++ b/crates/ptth_server/src/file_server/metrics.rs @@ -12,7 +12,7 @@ fn serialize_ulid (t: &Ulid, s: S) // They don't change after that. #[derive (Debug, serde::Serialize)] -pub struct InstanceMetrics { +pub struct PerInstance { // D-Bus machine ID, if we're on Linux pub machine_id: Option , @@ -49,7 +49,7 @@ fn get_machine_id () -> Option { Some (s) } -impl InstanceMetrics { +impl PerInstance { #[must_use] pub fn new (server_name: String) -> Self { @@ -69,8 +69,8 @@ mod tests { #[test] fn ulid_null () { - let a = InstanceMetrics::new ("bogus".to_string ()); - let b = InstanceMetrics::new ("bogus".to_string ()); + let a = PerInstance::new ("bogus".to_string ()); + let b = PerInstance::new ("bogus".to_string ()); assert_ne! (a.instance_id, b.instance_id); } diff --git a/crates/ptth_server/src/file_server/mod.rs b/crates/ptth_server/src/file_server/mod.rs index 019fc98..37ee6a0 100644 --- a/crates/ptth_server/src/file_server/mod.rs +++ b/crates/ptth_server/src/file_server/mod.rs @@ -44,7 +44,6 @@ mod markdown; mod range; use errors::FileServerError; -use metrics::InstanceMetrics; mod emoji { pub const VIDEO: &str = "\u{1f39e}\u{fe0f}"; @@ -90,7 +89,7 @@ struct DirEntryHtml { #[derive (Serialize)] struct DirHtml <'a> { #[serde (flatten)] - instance_metrics: &'a InstanceMetrics, + instance_metrics: &'a metrics::PerInstance, path: Cow <'a, str>, entries: Vec , @@ -188,7 +187,7 @@ async fn read_dir_entry_json (entry: DirEntry) -> Option async fn serve_root ( handlebars: &Handlebars <'static>, - instance_metrics: &InstanceMetrics + instance_metrics: &metrics::PerInstance ) -> Result { let s = handlebars.render ("file_server_root", &instance_metrics)?; @@ -233,7 +232,7 @@ async fn serve_dir_json ( #[instrument (level = "debug", skip (handlebars, instance_metrics, dir))] async fn serve_dir_html ( handlebars: &Handlebars <'static>, - instance_metrics: &InstanceMetrics, + instance_metrics: &metrics::PerInstance, path: Cow <'_, str>, mut dir: ReadDir ) -> Result @@ -359,7 +358,7 @@ async fn serve_file ( #[instrument (level = "debug", skip (handlebars, headers, instance_metrics))] pub async fn serve_all ( handlebars: &Handlebars <'static>, - instance_metrics: &InstanceMetrics, + instance_metrics: &metrics::PerInstance, root: &Path, method: Method, uri: &str, diff --git a/crates/ptth_server/src/lib.rs b/crates/ptth_server/src/lib.rs index 3fed368..a5a8173 100644 --- a/crates/ptth_server/src/lib.rs +++ b/crates/ptth_server/src/lib.rs @@ -51,7 +51,7 @@ pub fn password_is_bad (mut password: String) -> bool { struct ServerState { config: Config, handlebars: Handlebars <'static>, - instance_metrics: file_server::metrics::InstanceMetrics, + instance_metrics: file_server::metrics::PerInstance, client: Client, hidden_path: Option , } @@ -201,7 +201,7 @@ pub async fn run_server ( .build ().map_err (ServerError::CantBuildHttpClient)?; let handlebars = file_server::load_templates (&asset_root)?; - let instance_metrics = file_server::metrics::InstanceMetrics::new (config_file.name); + let instance_metrics = file_server::metrics::PerInstance::new (config_file.name); let state = Arc::new (ServerState { config: Config {