Add support for building webfinger for multiple URLs with type

Update `build_webfinger_response` to accept `Vec<(Url, Option<&str>)>`
where `Url` is the ActivityPub ID and `&str` is the optional type.
This commit is contained in:
Grafcube 2023-03-31 21:06:02 +05:30
parent c56f526914
commit 3f70586e63
No known key found for this signature in database
GPG key ID: E383688F2878A440

View file

@ -95,23 +95,35 @@ where
/// build_webfinger_response(subject, url); /// build_webfinger_response(subject, url);
/// # Ok::<(), anyhow::Error>(()) /// # Ok::<(), anyhow::Error>(())
/// ``` /// ```
pub fn build_webfinger_response(subject: String, url: Url) -> Webfinger { pub fn build_webfinger_response(subject: String, url: Vec<(Url, Option<&str>)>) -> Webfinger {
Webfinger { Webfinger {
subject, subject,
links: vec![ links: url.iter().fold(vec![], |mut acc, (url, kind)| {
WebfingerLink { acc.extend(vec![
rel: Some("http://webfinger.net/rel/profile-page".to_string()), WebfingerLink {
kind: Some("text/html".to_string()), rel: Some("http://webfinger.net/rel/profile-page".to_string()),
href: Some(url.clone()), kind: Some("text/html".to_string()),
properties: Default::default(), href: Some(url.clone()),
}, properties: Default::default(),
WebfingerLink { },
rel: Some("self".to_string()), WebfingerLink {
kind: Some(FEDERATION_CONTENT_TYPE.to_string()), rel: Some("self".to_string()),
href: Some(url), kind: Some(FEDERATION_CONTENT_TYPE.to_string()),
properties: Default::default(), href: Some(url.clone()),
}, properties: kind
], .map(|kind| {
HashMap::from([(
"https://www.w3.org/ns/activitystreams#type"
.parse::<Url>()
.expect("parse url"),
kind.to_string(),
)])
})
.unwrap_or_default(),
},
]);
acc
}),
aliases: vec![], aliases: vec![],
properties: Default::default(), properties: Default::default(),
} }