Create webfinger
crate #5
1 changed files with 28 additions and 1 deletions
|
@ -5,7 +5,7 @@ use axum_extra::extract::Query;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use acrate_core::diesel::GroupedBy;
|
use acrate_core::diesel::GroupedBy;
|
||||||
use acrate_core::diesel_async::{AsyncConnection, AsyncPgConnection};
|
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::jrd::ResourceDescriptorLinkJRD;
|
||||||
use acrate_hostmeta::xrd::{ResourceDescriptorLinkXRD, ResourceDescriptorPropertyXRD, ResourceDescriptorTitleXRD};
|
use acrate_hostmeta::xrd::{ResourceDescriptorLinkXRD, ResourceDescriptorPropertyXRD, ResourceDescriptorTitleXRD};
|
||||||
use crate::config;
|
use crate::config;
|
||||||
|
@ -47,6 +47,33 @@ pub async fn webfinger_handler(
|
||||||
.await
|
.await
|
||||||
.map_err(|_| StatusCode::BAD_GATEWAY)?;
|
.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)
|
let aliases = MetaAlias::query_matching(&mut conn, WEBFINGER_DOC, &resource)
|
||||||
.await
|
.await
|
||||||
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
|
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
|
||||||
|
|
Loading…
Reference in a new issue