mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-12-23 11:21:32 +00:00
So that it is easier to parse for other software
This commit is contained in:
parent
cd5c79527a
commit
675353d4e9
2 changed files with 13 additions and 4 deletions
|
@ -7,6 +7,7 @@ use lemmy_db_schema::{
|
||||||
};
|
};
|
||||||
use lemmy_utils::{error::LemmyError, location_info, WebfingerLink, WebfingerResponse};
|
use lemmy_utils::{error::LemmyError, location_info, WebfingerLink, WebfingerResponse};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
use std::collections::HashMap;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
@ -53,8 +54,8 @@ async fn get_webfinger_response(
|
||||||
// Mastodon seems to prioritize the last webfinger item in case of duplicates. Put
|
// Mastodon seems to prioritize the last webfinger item in case of duplicates. Put
|
||||||
// community last so that it gets prioritized. For Lemmy the order doesnt matter.
|
// community last so that it gets prioritized. For Lemmy the order doesnt matter.
|
||||||
let links = vec![
|
let links = vec![
|
||||||
webfinger_link_for_actor(user_id),
|
webfinger_link_for_actor(user_id, "Person"),
|
||||||
webfinger_link_for_actor(community_id),
|
webfinger_link_for_actor(community_id, "Group"),
|
||||||
]
|
]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.flatten()
|
.flatten()
|
||||||
|
@ -68,18 +69,25 @@ async fn get_webfinger_response(
|
||||||
Ok(HttpResponse::Ok().json(json))
|
Ok(HttpResponse::Ok().json(json))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn webfinger_link_for_actor(url: Option<Url>) -> Vec<WebfingerLink> {
|
fn webfinger_link_for_actor(url: Option<Url>, kind: &str) -> Vec<WebfingerLink> {
|
||||||
if let Some(url) = url {
|
if let Some(url) = url {
|
||||||
|
let mut properties = HashMap::new();
|
||||||
|
properties.insert(
|
||||||
|
"https://www.w3.org/ns/activitystreams#type".to_string(),
|
||||||
|
kind.to_string(),
|
||||||
|
);
|
||||||
vec![
|
vec![
|
||||||
WebfingerLink {
|
WebfingerLink {
|
||||||
rel: Some("http://webfinger.net/rel/profile-page".to_string()),
|
rel: Some("http://webfinger.net/rel/profile-page".to_string()),
|
||||||
kind: Some("text/html".to_string()),
|
kind: Some("text/html".to_string()),
|
||||||
href: Some(url.clone()),
|
href: Some(url.clone()),
|
||||||
|
properties: Default::default(),
|
||||||
},
|
},
|
||||||
WebfingerLink {
|
WebfingerLink {
|
||||||
rel: Some("self".to_string()),
|
rel: Some("self".to_string()),
|
||||||
kind: Some("application/activity+json".to_string()),
|
kind: Some("application/activity+json".to_string()),
|
||||||
href: Some(url),
|
href: Some(url),
|
||||||
|
properties,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -15,7 +15,7 @@ pub mod utils;
|
||||||
pub mod version;
|
pub mod version;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{fmt, time::Duration};
|
use std::{collections::HashMap, fmt, time::Duration};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
pub type ConnectionId = usize;
|
pub type ConnectionId = usize;
|
||||||
|
@ -37,6 +37,7 @@ pub struct WebfingerLink {
|
||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
pub kind: Option<String>,
|
pub kind: Option<String>,
|
||||||
pub href: Option<Url>,
|
pub href: Option<Url>,
|
||||||
|
pub properties: HashMap<String, String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
|
Loading…
Reference in a new issue