i lied and i did it now
This commit is contained in:
parent
9fb2fd3b0a
commit
b46a995c09
1 changed files with 14 additions and 38 deletions
|
@ -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.
|
//! > 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;
|
use serde::Deserialize;
|
||||||
|
|
||||||
/// A variant of a NodeInfo document.
|
/// A variant of a NodeInfo document.
|
||||||
|
@ -163,6 +161,13 @@ pub struct NodeInfo2Instance {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NodeInfo {
|
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.
|
/// Discover and get the latest NodeInfo version available given a certain base URL.
|
||||||
///
|
///
|
||||||
/// ## Examples
|
/// ## Examples
|
||||||
|
@ -186,13 +191,16 @@ impl NodeInfo {
|
||||||
///
|
///
|
||||||
/// assert_eq!(version, "2.0");
|
/// assert_eq!(version, "2.0");
|
||||||
/// # })
|
/// # })
|
||||||
pub async fn get_latest_wellknown(client: &reqwest::Client, url: reqwest::Url) -> Result<Self, NodeInfoGetWellknownError> {
|
pub async fn get_latest_wellknown(client: &reqwest::Client, mut base: reqwest::Url) -> Result<Self, NodeInfoGetWellknownError> {
|
||||||
use NodeInfoGetWellknownError::*;
|
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...");
|
log::trace!("Discovering NodeInfo document locations...");
|
||||||
let discovery = acrate_hostmeta::ResourceDescriptor::discover(client, url)
|
let discovery = acrate_hostmeta::ResourceDescriptor::discover(client, base)
|
||||||
.await
|
.await
|
||||||
.map_err(Discovery)?;
|
.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);
|
return Ok(nodeinfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
log::warn!("Ran out of possible NodeInfo sources, returning an Unsupported error.");
|
log::warn!("Ran out of possible NodeInfo sources, returning an Unsupported error.");
|
||||||
Err(Unsupported)
|
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<Self, NodeInfoGetWellknownError> {
|
|
||||||
base.set_path(Self::WELLKNOWN_NODEINFO_PATH);
|
|
||||||
|
|
||||||
Self::get_latest_wellknown(client, base)
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An error occurred during [`NodeInfo::get_latest_wellknown`].
|
/// An error occurred during [`NodeInfo::get_latest_wellknown`].
|
||||||
|
|
Loading…
Reference in a new issue