diff --git a/src/routes/activitypub/mod.rs b/src/routes/activitypub/mod.rs index 181b985a..3cd4df26 100644 --- a/src/routes/activitypub/mod.rs +++ b/src/routes/activitypub/mod.rs @@ -39,6 +39,7 @@ impl ActivityPubRouter for Router { .route("/nodeinfo/:version", get(ap::well_known::nodeinfo)) // actor routes .route("/users/:id", get(ap::user::view)) + .route("/users/:server/:id", get(ap::user::remote_view)) .route("/users/:id/inbox", post(ap::user::inbox::post)) .route("/users/:id/inbox", get(ap::user::inbox::get)) .route("/users/:id/inbox/page", get(ap::user::inbox::page)) diff --git a/src/routes/activitypub/user/mod.rs b/src/routes/activitypub/user/mod.rs index f835b6ea..08566eac 100644 --- a/src/routes/activitypub/user/mod.rs +++ b/src/routes/activitypub/user/mod.rs @@ -5,7 +5,7 @@ pub mod outbox; pub mod following; use axum::{extract::{Path, State}, http::StatusCode}; -use sea_orm::EntityTrait; +use sea_orm::{ColumnTrait, Condition, EntityTrait, QueryFilter}; use apb::{PublicKeyMut, ActorMut, DocumentMut, DocumentType, ObjectMut, BaseMut, Node}; use crate::{model::{self, user}, server::Context, url}; @@ -60,7 +60,7 @@ pub async fn view(State(ctx) : State, Path(id): Path) -> Result .ld_context() )) }, - // remote user + // remote user TODDO doesn't work? Ok(Some((user, None))) => Ok(JsonLD(ap_user(user).ld_context())), Ok(None) => Err(StatusCode::NOT_FOUND), Err(e) => { @@ -70,3 +70,26 @@ pub async fn view(State(ctx) : State, Path(id): Path) -> Result } } +pub async fn remote_view( + State(ctx) : State, + Path(server): Path, + Path(id): Path, +) -> Result, StatusCode> { + match user::Entity::find() + .filter( + Condition::all() + .add(user::Column::PreferredUsername.eq(id)) + .add(user::Column::Domain.eq(server)) + ) + .one(ctx.db()).await + { + // local user + Ok(Some(user)) => Ok(JsonLD(ap_user(user).ld_context())), + Ok(None) => Err(StatusCode::NOT_FOUND), + Err(e) => { + tracing::error!("error querying for user: {e}"); + Err(StatusCode::INTERNAL_SERVER_ERROR) + }, + } +} +