webfinger
: Handle not found and redirects
This commit is contained in:
parent
7f392bef36
commit
0498e45b59
1 changed files with 28 additions and 1 deletions
|
@ -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)?;
|
||||
|
|
Loading…
Reference in a new issue