fix: webfinger

too many special cases just search username and domain there are indexes
This commit is contained in:
əlemi 2024-05-29 20:01:57 +02:00
parent f487ac06e9
commit 07d0d400d8
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -102,31 +102,6 @@ pub async fn webfinger(State(ctx): State<Context>, Query(query): Query<Webfinger
.replace("acct:", "")
.split_once('@')
{
if domain == ctx.domain() {
// local user
let uid = ctx.uid(user);
let usr = model::actor::Entity::find_by_ap_id(&uid)
.one(ctx.db())
.await?
.ok_or_else(UpubError::not_found)?;
Ok(JsonRD(JsonResourceDescriptor {
subject: format!("acct:{user}@{domain}"),
aliases: vec![usr.id.clone()],
links: vec![
JsonResourceDescriptorLink {
rel: "self".to_string(),
link_type: Some("application/ld+json".to_string()),
href: Some(usr.id),
properties: jrd::Map::default(),
titles: jrd::Map::default(),
},
],
expires: None,
properties: jrd::Map::default(),
}))
} else {
// remote user
let usr = model::actor::Entity::find()
.filter(model::actor::Column::PreferredUsername.eq(user))
.filter(model::actor::Column::Domain.eq(domain))
@ -134,6 +109,15 @@ pub async fn webfinger(State(ctx): State<Context>, Query(query): Query<Webfinger
.await?
.ok_or_else(UpubError::not_found)?;
let expires = if domain == ctx.domain() {
// TODO configurable webfinger TTL, also 30 days may be too much???
Some(chrono::Utc::now() + chrono::Duration::days(30))
} else {
// we are no authority on local users, this info should be considered already outdated,
// but can still be relevant, for example for our frontend
Some(chrono::Utc::now())
};
Ok(JsonRD(JsonResourceDescriptor {
subject: format!("acct:{user}@{domain}"),
aliases: vec![usr.id.clone()],
@ -147,11 +131,8 @@ pub async fn webfinger(State(ctx): State<Context>, Query(query): Query<Webfinger
},
],
properties: jrd::Map::default(),
// we are no authority on local users, this info should be considered already outdated,
// but can still be relevant, for example for our frontend
expires: Some(chrono::Utc::now()),
expires,
}))
}
} else {
Err(StatusCode::UNPROCESSABLE_ENTITY.into())
}