1
0
Fork 0
forked from alemi/upub

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