diff --git a/acrate-nodeinfo/src/lib.rs b/acrate-nodeinfo/src/lib.rs index 0fbf5e4..fe8ea02 100644 --- a/acrate-nodeinfo/src/lib.rs +++ b/acrate-nodeinfo/src/lib.rs @@ -2,8 +2,6 @@ //! //! > NodeInfo is an effort to create a standardized way of exposing metadata about a server running one of the distributed social networks. -use std::collections::HashMap; - use serde::Deserialize; /// A variant of a NodeInfo document. @@ -163,6 +161,13 @@ pub struct NodeInfo2Instance { } impl NodeInfo { + /// Well-known path for NodeInfo documents. + /// + /// ## Specification + /// + /// - https://github.com/jhass/nodeinfo/blob/main/PROTOCOL.md#discovery + pub const WELLKNOWN_NODEINFO_PATH: &str = "/.well-known/nodeinfo"; + /// Discover and get the latest NodeInfo version available given a certain base URL. /// /// ## Examples @@ -186,13 +191,16 @@ impl NodeInfo { /// /// assert_eq!(version, "2.0"); /// # }) - pub async fn get_latest_wellknown(client: &reqwest::Client, url: reqwest::Url) -> Result { + pub async fn get_latest_wellknown(client: &reqwest::Client, mut base: reqwest::Url) -> Result { use NodeInfoGetWellknownError::*; - log::debug!("Getting well-known NodeInfo document at base: {url}"); + log::debug!("Getting well-known NodeInfo document at base: {base}"); + + log::trace!("Setting URL path to the well-known NodeInfo value..."); + base.set_path(Self::WELLKNOWN_NODEINFO_PATH); log::trace!("Discovering NodeInfo document locations..."); - let discovery = acrate_hostmeta::ResourceDescriptor::discover(client, url) + let discovery = acrate_hostmeta::ResourceDescriptor::discover(client, base) .await .map_err(Discovery)?; @@ -286,45 +294,13 @@ impl NodeInfo { }, }; - log::trace!("Successfully retrieved latest NodeInfo: {nodeinfo:#?}") + log::trace!("Successfully retrieved latest NodeInfo: {nodeinfo:#?}"); return Ok(nodeinfo); } log::warn!("Ran out of possible NodeInfo sources, returning an Unsupported error."); Err(Unsupported) } - - /// Well-known path for NodeInfo documents. - /// - /// ## Specification - /// - /// - https://github.com/jhass/nodeinfo/blob/main/PROTOCOL.md#discovery - pub const WELLKNOWN_NODEINFO_PATH: &str = "/.well-known/nodeinfo"; - - /// Attempt to discover a NodeInfo document at the given base URL. - /// - /// ## Examples - /// - /// ``` - /// # tokio_test::block_on(async { - /// use acrate_hostmeta::ResourceDescriptor; - /// - /// let client = reqwest::Client::new(); - /// let base: reqwest::Url = "https://junimo.party".parse() - /// .expect("URL to be valid"); - /// - /// let rd = NodeInfo::discover(&client, base) - /// .await - /// .expect("NodeInfo to be discovered correctly"); - /// # }) - /// ``` - /// - pub async fn discover(client: &reqwest::Client, mut base: reqwest::Url) -> Result { - base.set_path(Self::WELLKNOWN_NODEINFO_PATH); - - Self::get_latest_wellknown(client, base) - .await - } } /// An error occurred during [`NodeInfo::get_latest_wellknown`].