Compare commits
3 commits
0e7aacdd0e
...
cc6dfd0dfc
Author | SHA1 | Date | |
---|---|---|---|
cc6dfd0dfc | |||
219880f3d3 | |||
5078b41499 |
4 changed files with 13 additions and 7 deletions
|
@ -2,8 +2,14 @@ CREATE TABLE IF NOT EXISTS meta_subjects (
|
|||
id UUID DEFAULT gen_random_uuid(),
|
||||
document BPCHAR NOT NULL,
|
||||
pattern BPCHAR NOT NULL,
|
||||
subject 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)
|
||||
);
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ pub struct MetaSubject {
|
|||
pub id: Uuid,
|
||||
pub document: String,
|
||||
pub pattern: String,
|
||||
pub subject: Option<String>,
|
||||
pub redirect: Option<String>,
|
||||
}
|
||||
|
||||
|
@ -71,13 +72,13 @@ pub struct MetaProperty {
|
|||
}
|
||||
|
||||
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_async::RunQueryDsl;
|
||||
use schema::meta_subjects::dsl::*;
|
||||
|
||||
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
|
||||
.filter(document_is_equal)
|
||||
|
|
|
@ -55,6 +55,7 @@ diesel::table! {
|
|||
id -> Uuid,
|
||||
document -> Bpchar,
|
||||
pattern -> Bpchar,
|
||||
subject -> Nullable<Bpchar>,
|
||||
redirect -> Nullable<Bpchar>,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,6 +74,8 @@ pub async fn webfinger_handler(
|
|||
return Ok(response);
|
||||
}
|
||||
|
||||
let subject = subject.subject.clone();
|
||||
|
||||
let aliases = MetaAlias::query_matching(&mut conn, WEBFINGER_DOC, &resource)
|
||||
.await
|
||||
.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
|
||||
|
@ -127,8 +129,6 @@ pub async fn webfinger_handler(
|
|||
|
||||
match mime {
|
||||
"*/*" | "application/json" | "application/jrd+json" => {
|
||||
let subject = Some(resource);
|
||||
|
||||
let aliases = aliases
|
||||
.into_iter()
|
||||
.map(|alias| alias.alias)
|
||||
|
@ -175,8 +175,6 @@ pub async fn webfinger_handler(
|
|||
return Ok(response);
|
||||
},
|
||||
"application/xml" | "application/xrd+xml" => {
|
||||
let subject = Some(resource);
|
||||
|
||||
let aliases = aliases
|
||||
.into_iter()
|
||||
.map(|alias| alias.alias)
|
||||
|
@ -265,7 +263,7 @@ pub async fn webfinger_handler(
|
|||
.expect("webfinger.html.j2 to exist")
|
||||
.render(
|
||||
minijinja::context!(
|
||||
subject => resource,
|
||||
subject => subject,
|
||||
aliases => aliases,
|
||||
properties => properties,
|
||||
links => links,
|
||||
|
|
Loading…
Reference in a new issue