2 use crate::db::community::Community;
9 pub fn config(cfg: &mut web::ServiceConfig) {
11 ".well-known/webfinger",
12 web::get().to(get_webfinger_response),
17 static ref WEBFINGER_COMMUNITY_REGEX: Regex = Regex::new(&format!(
18 "^group:([a-z0-9_]{{3, 20}})@{}$",
19 Settings::get().hostname
24 /// Responds to webfinger requests of the following format. There isn't any real documentation for
25 /// this, but it described in this blog post:
26 /// https://mastodon.social/.well-known/webfinger?resource=acct:gargron@mastodon.social
28 /// You can also view the webfinger response that Mastodon sends:
29 /// https://radical.town/.well-known/webfinger?resource=acct:felix@radical.town
30 async fn get_webfinger_response(
32 db: web::Data<Pool<ConnectionManager<PgConnection>>>,
33 ) -> Result<HttpResponse, Error> {
34 let res = web::block(move || {
37 let regex_parsed = WEBFINGER_COMMUNITY_REGEX
38 .captures(&info.resource)
40 // TODO: replace this with .flatten() once we are running rust 1.40
41 let regex_parsed_flattened = match regex_parsed {
45 let community_name = match regex_parsed_flattened {
46 Some(c) => c.as_str(),
47 None => return Err(format_err!("not_found")),
50 // Make sure the requested community exists.
51 let community = match Community::read_from_name(&conn, community_name.to_string()) {
53 Err(_) => return Err(format_err!("not_found")),
56 let community_url = community.get_url();
59 "subject": info.resource,
65 "rel": "http://webfinger.net/rel/profile-page",
71 "type": "application/activity+json",
72 // Yes this is correct, this link doesn't include the `.json` extension
75 // TODO: this also needs to return the subscribe link once that's implemented
77 // "rel": "http://ostatus.org/schema/1.0/subscribe",
78 // "template": "https://my_instance.com/authorize_interaction?uri={uri}"
84 .map(|json| HttpResponse::Ok().json(json))
85 .map_err(ErrorBadRequest)?;