diff --git a/acrate-webfinger/src/route.rs b/acrate-webfinger/src/route.rs index 1ae9cef..13a7d7d 100644 --- a/acrate-webfinger/src/route.rs +++ b/acrate-webfinger/src/route.rs @@ -5,7 +5,7 @@ use axum_extra::extract::Query; use serde::Deserialize; use acrate_core::diesel::GroupedBy; use acrate_core::diesel_async::{AsyncConnection, AsyncPgConnection}; -use acrate_core::meta::{MetaAlias, MetaLink, MetaLinkProperty, MetaLinkTitle, MetaProperty}; +use acrate_core::meta::{MetaAlias, MetaLink, MetaLinkProperty, MetaLinkTitle, MetaProperty, MetaSubject}; use acrate_hostmeta::jrd::ResourceDescriptorLinkJRD; use acrate_hostmeta::xrd::{ResourceDescriptorLinkXRD, ResourceDescriptorPropertyXRD, ResourceDescriptorTitleXRD}; use crate::config; @@ -47,6 +47,33 @@ pub async fn webfinger_handler( .await .map_err(|_| StatusCode::BAD_GATEWAY)?; + let subjects = MetaSubject::query_matching(&mut conn, WEBFINGER_DOC, &resource) + .await + .map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?; + + let subject = subjects.first() + .ok_or(StatusCode::NOT_FOUND)?; + + if subject.redirect.is_some() { + { + let headers = response.headers_mut(); + headers.insert( + "Location", + subject.redirect + .as_ref() + .expect("redirect not to have become suddenly None") + .parse() + .map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)? + ); + } + { + let status = response.status_mut(); + *status = StatusCode::FOUND; + } + + return Ok(response); + } + let aliases = MetaAlias::query_matching(&mut conn, WEBFINGER_DOC, &resource) .await .map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;