ferri/ferri-server/src/endpoints/well_known.rs

48 lines
1.6 KiB
Rust
Raw Normal View History

2025-04-11 12:29:29 +01:00
use main::ap;
use rocket::{get, serde::json::Json};
use rocket_db_pools::Connection;
2025-04-12 15:16:40 +01:00
use crate::{
Db,
types::webfinger::{Link, WebfingerResponse},
};
2025-04-11 12:29:29 +01:00
#[get("/.well-known/host-meta")]
pub async fn host_meta() -> &'static str {
r#"
<?xml version="1.0" encoding="UTF-8"?>
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
<Link rel="lrdd" template="https://ferri.amy.mov/.well-known/webfinger?resource={uri}"/>
</XRD>
"#
}
// https://mastodon.social/.well-known/webfinger?resource=acct:gargron@mastodon.social
#[get("/.well-known/webfinger?<resource>")]
pub async fn webfinger(mut db: Connection<Db>, resource: &str) -> Json<WebfingerResponse> {
println!("Webfinger request for {}", resource);
let acct = resource.strip_prefix("acct:").unwrap();
let (user, _) = acct.split_once("@").unwrap();
let user = ap::User::from_username(user, &mut **db).await;
Json(WebfingerResponse {
subject: resource.to_string(),
aliases: vec![
2025-04-12 11:27:03 +01:00
format!("https://ferri.amy.mov/users/{}", user.id()),
2025-04-11 12:29:29 +01:00
format!("https://ferri.amy.mov/@{}", user.username()),
],
links: vec![
Link {
rel: "http://webfinger.net/rel/profile-page".to_string(),
ty: Some("text/html".to_string()),
href: Some(format!("https://ferri.amy.mov/@{}", user.username())),
},
Link {
rel: "self".to_string(),
ty: Some("application/activity+json".to_string()),
2025-04-12 11:27:03 +01:00
href: Some(format!("https://ferri.amy.mov/users/{}", user.id())),
2025-04-11 12:29:29 +01:00
},
],
})
2025-04-12 11:27:03 +01:00
}