Compare commits

..

3 commits

4 changed files with 13 additions and 7 deletions

View file

@ -2,8 +2,14 @@ CREATE TABLE IF NOT EXISTS meta_subjects (
id UUID DEFAULT gen_random_uuid(), id UUID DEFAULT gen_random_uuid(),
document BPCHAR NOT NULL, document BPCHAR NOT NULL,
pattern BPCHAR NOT NULL, pattern BPCHAR NOT NULL,
subject BPCHAR,
redirect BPCHAR, redirect BPCHAR,
CONSTRAINT either_subject_or_redirect_not_null CHECK (
(subject IS NOT NULL AND redirect IS NULL)
OR
(subject IS NULL AND redirect IS NOT NULL)
),
PRIMARY KEY (id) PRIMARY KEY (id)
); );

View file

@ -11,6 +11,7 @@ pub struct MetaSubject {
pub id: Uuid, pub id: Uuid,
pub document: String, pub document: String,
pub pattern: String, pub pattern: String,
pub subject: Option<String>,
pub redirect: Option<String>, pub redirect: Option<String>,
} }
@ -71,13 +72,13 @@ pub struct MetaProperty {
} }
impl MetaSubject { impl MetaSubject {
pub async fn query_matching(conn: &mut AsyncPgConnection, doc: &str, subject: &str) -> QueryResult<Vec<Self>> { pub async fn query_matching(conn: &mut AsyncPgConnection, doc: &str, subject_: &str) -> QueryResult<Vec<Self>> {
use diesel::prelude::*; use diesel::prelude::*;
use diesel_async::RunQueryDsl; use diesel_async::RunQueryDsl;
use schema::meta_subjects::dsl::*; use schema::meta_subjects::dsl::*;
let document_is_equal = document.eq(doc); let document_is_equal = document.eq(doc);
let subject_matches_pattern = subject.into_sql::<diesel::sql_types::Text>().ilike(pattern); let subject_matches_pattern = subject_.into_sql::<diesel::sql_types::Text>().ilike(pattern);
meta_subjects meta_subjects
.filter(document_is_equal) .filter(document_is_equal)

View file

@ -55,6 +55,7 @@ diesel::table! {
id -> Uuid, id -> Uuid,
document -> Bpchar, document -> Bpchar,
pattern -> Bpchar, pattern -> Bpchar,
subject -> Nullable<Bpchar>,
redirect -> Nullable<Bpchar>, redirect -> Nullable<Bpchar>,
} }
} }

View file

@ -74,6 +74,8 @@ pub async fn webfinger_handler(
return Ok(response); return Ok(response);
} }
let subject = subject.subject.clone();
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)?;
@ -127,8 +129,6 @@ pub async fn webfinger_handler(
match mime { match mime {
"*/*" | "application/json" | "application/jrd+json" => { "*/*" | "application/json" | "application/jrd+json" => {
let subject = Some(resource);
let aliases = aliases let aliases = aliases
.into_iter() .into_iter()
.map(|alias| alias.alias) .map(|alias| alias.alias)
@ -175,8 +175,6 @@ pub async fn webfinger_handler(
return Ok(response); return Ok(response);
}, },
"application/xml" | "application/xrd+xml" => { "application/xml" | "application/xrd+xml" => {
let subject = Some(resource);
let aliases = aliases let aliases = aliases
.into_iter() .into_iter()
.map(|alias| alias.alias) .map(|alias| alias.alias)
@ -265,7 +263,7 @@ pub async fn webfinger_handler(
.expect("webfinger.html.j2 to exist") .expect("webfinger.html.j2 to exist")
.render( .render(
minijinja::context!( minijinja::context!(
subject => resource, subject => subject,
aliases => aliases, aliases => aliases,
properties => properties, properties => properties,
links => links, links => links,