1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
use crate::models::profiles::Profile;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Clone, Default, Debug)]
pub struct WebFingerLink {
pub rel: String,
#[serde(rename = "type")]
#[serde(skip_serializing_if = "Option::is_none")]
pub kind: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub href: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub template: Option<String>,
}
#[derive(Serialize, Deserialize, Clone, Default, Debug)]
pub struct WebFinger {
pub subject: String,
pub aliases: Option<Vec<String>>,
pub links: Vec<WebFingerLink>,
}
impl From<Profile> for WebFinger {
fn from(profile: Profile) -> Self {
let server_url = &*crate::SERVER_URL;
let server_name = &*crate::SERVER_NAME;
WebFinger {
subject: format!("acct:{}@{}", profile.username, server_name),
aliases: Option::from(vec![
format!("{}/@{}", server_url, profile.username),
format!("{}/user/{}", server_url, profile.username),
]),
links: vec![
WebFingerLink {
rel: "http://webfinger.net/rel/profile-page".to_string(),
kind: Option::from("text/html".to_string()),
href: Option::from(format!("{}/@{}", server_url, profile.username)),
..Default::default()
},
WebFingerLink {
rel: "self".to_string(),
kind: Option::from("application/activity+json".to_string()),
href: Option::from(format!("{}/user/{}", server_url, profile.username)),
..Default::default()
},
// WebFingerLink {
// rel: "self".to_string(),
// kind: Option::from(
// "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\""
// .to_string(),
// ),
// href: Option::from(format!("{}/user/{}", server_url, profile.username)),
// ..Default::default()
// },
// WebFingerLink {
// rel: "http://ostatus.org/schema/1.0/subscribe".to_string(),
// kind: Option::None,
// href: Option::None,
// template: Option::from(format!(
// "{server_url}/authorize_interaction?uri={{uri}}"
// )),
// },
],
}
}
}