Compare commits
No commits in common. "cc6dfd0dfc095d106d5f2bf3a12bc6cf2a995c04" and "0e7aacdd0e2680b13ed8c1faa3220e5a3cb6b52e" have entirely different histories.
cc6dfd0dfc
...
0e7aacdd0e
4 changed files with 7 additions and 13 deletions
|
@ -2,14 +2,8 @@ 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)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,6 @@ 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>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,13 +71,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)
|
||||||
|
|
|
@ -55,7 +55,6 @@ diesel::table! {
|
||||||
id -> Uuid,
|
id -> Uuid,
|
||||||
document -> Bpchar,
|
document -> Bpchar,
|
||||||
pattern -> Bpchar,
|
pattern -> Bpchar,
|
||||||
subject -> Nullable<Bpchar>,
|
|
||||||
redirect -> Nullable<Bpchar>,
|
redirect -> Nullable<Bpchar>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,8 +74,6 @@ 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)?;
|
||||||
|
@ -129,6 +127,8 @@ 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,6 +175,8 @@ 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)
|
||||||
|
@ -263,7 +265,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 => subject,
|
subject => resource,
|
||||||
aliases => aliases,
|
aliases => aliases,
|
||||||
properties => properties,
|
properties => properties,
|
||||||
links => links,
|
links => links,
|
||||||
|
|
Loading…
Reference in a new issue