1
0
Fork 0
forked from alemi/upub

feat: logged in user can search by webfinger

more expensive than "localized" +..@..@ urls because must always make
one extra request but allows easier searching
This commit is contained in:
əlemi 2024-05-13 01:48:51 +02:00
parent f2867e56e7
commit 8a1afadea0
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -7,7 +7,7 @@ pub mod following;
use axum::extract::{Path, Query, State}; use axum::extract::{Path, Query, State};
use sea_orm::{ColumnTrait, EntityTrait, QueryFilter, QuerySelect, SelectColumns}; use sea_orm::{ColumnTrait, EntityTrait, QueryFilter, QuerySelect, SelectColumns};
use apb::{ActorMut, Node, ObjectMut}; use apb::{ActorMut, Node};
use crate::{errors::UpubError, model::{self, user}, server::{auth::AuthIdentity, fetcher::Fetcher, Context}, url}; use crate::{errors::UpubError, model::{self, user}, server::{auth::AuthIdentity, fetcher::Fetcher, Context}, url};
use super::{jsonld::LD, JsonLD, TryFetch}; use super::{jsonld::LD, JsonLD, TryFetch};
@ -19,8 +19,13 @@ pub async fn view(
Path(id): Path<String>, Path(id): Path<String>,
Query(query): Query<TryFetch>, Query(query): Query<TryFetch>,
) -> crate::Result<JsonLD<serde_json::Value>> { ) -> crate::Result<JsonLD<serde_json::Value>> {
let uid = ctx.uri("users", id.clone()); let mut uid = ctx.uri("users", id.clone());
if auth.is_local() && query.fetch && !ctx.is_local(&uid) { if auth.is_local() && query.fetch && !ctx.is_local(&uid) {
if id.starts_with('@') {
if let Some((user, host)) = id.replacen('@', "", 1).split_once('@') {
uid = ctx.webfinger(user, host).await?;
}
}
ctx.fetch_user(&uid).await?; ctx.fetch_user(&uid).await?;
} }