feat: route for viewing specifically remote users
WIP, will probably go away in favor of a uniform route
This commit is contained in:
parent
87d802fa2e
commit
fc488e6b2f
2 changed files with 26 additions and 2 deletions
|
@ -39,6 +39,7 @@ impl ActivityPubRouter for Router<crate::server::Context> {
|
|||
.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))
|
||||
|
|
|
@ -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<Context>, Path(id): Path<String>) -> 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<Context>, Path(id): Path<String>) -> Result
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn remote_view(
|
||||
State(ctx) : State<Context>,
|
||||
Path(server): Path<String>,
|
||||
Path(id): Path<String>,
|
||||
) -> Result<JsonLD<serde_json::Value>, 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)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue