forked from alemi/upub
fix: webfinger
too many special cases just search username and domain there are indexes
This commit is contained in:
parent
f487ac06e9
commit
07d0d400d8
1 changed files with 29 additions and 48 deletions
|
@ -102,31 +102,6 @@ pub async fn webfinger(State(ctx): State<Context>, Query(query): Query<Webfinger
|
||||||
.replace("acct:", "")
|
.replace("acct:", "")
|
||||||
.split_once('@')
|
.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()
|
let usr = model::actor::Entity::find()
|
||||||
.filter(model::actor::Column::PreferredUsername.eq(user))
|
.filter(model::actor::Column::PreferredUsername.eq(user))
|
||||||
.filter(model::actor::Column::Domain.eq(domain))
|
.filter(model::actor::Column::Domain.eq(domain))
|
||||||
|
@ -134,6 +109,15 @@ pub async fn webfinger(State(ctx): State<Context>, Query(query): Query<Webfinger
|
||||||
.await?
|
.await?
|
||||||
.ok_or_else(UpubError::not_found)?;
|
.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 {
|
Ok(JsonRD(JsonResourceDescriptor {
|
||||||
subject: format!("acct:{user}@{domain}"),
|
subject: format!("acct:{user}@{domain}"),
|
||||||
aliases: vec![usr.id.clone()],
|
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(),
|
properties: jrd::Map::default(),
|
||||||
// we are no authority on local users, this info should be considered already outdated,
|
expires,
|
||||||
// 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())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue