From 7f6685113677f550e30dcaded928fab91581918f Mon Sep 17 00:00:00 2001 From: alemi Date: Sat, 13 Apr 2024 06:55:16 +0200 Subject: [PATCH] fix: Path<()>, not Path<>, Path<> --- src/routes/activitypub/user/mod.rs | 31 +++++++++++------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/src/routes/activitypub/user/mod.rs b/src/routes/activitypub/user/mod.rs index 08566eac..fef2d706 100644 --- a/src/routes/activitypub/user/mod.rs +++ b/src/routes/activitypub/user/mod.rs @@ -8,7 +8,7 @@ use axum::{extract::{Path, State}, http::StatusCode}; use sea_orm::{ColumnTrait, Condition, EntityTrait, QueryFilter}; use apb::{PublicKeyMut, ActorMut, DocumentMut, DocumentType, ObjectMut, BaseMut, Node}; -use crate::{model::{self, user}, server::Context, url}; +use crate::{errors::UpubError, model::{self, user}, server::Context, url}; use super::{jsonld::LD, JsonLD}; @@ -44,13 +44,13 @@ pub fn ap_user(user: model::user::Model) -> serde_json::Value { .set_endpoints(Node::Empty) } -pub async fn view(State(ctx) : State, Path(id): Path) -> Result, StatusCode> { +pub async fn view(State(ctx) : State, Path(id): Path) -> crate::Result> { match user::Entity::find_by_id(ctx.uid(id.clone())) .find_also_related(model::config::Entity) - .one(ctx.db()).await + .one(ctx.db()).await? { // local user - Ok(Some((user, Some(_cfg)))) => { + Some((user, Some(_cfg))) => { Ok(JsonLD(ap_user(user.clone()) // ew ugly clone TODO .set_inbox(Node::link(url!(ctx, "/users/{id}/inbox"))) .set_outbox(Node::link(url!(ctx, "/users/{id}/outbox"))) @@ -61,35 +61,26 @@ pub async fn view(State(ctx) : State, Path(id): Path) -> Result )) }, // 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) => { - tracing::error!("error querying for user: {e}"); - Err(StatusCode::INTERNAL_SERVER_ERROR) - }, + Some((user, None)) => Ok(JsonLD(ap_user(user).ld_context())), + None => Err(UpubError::not_found()), } } pub async fn remote_view( State(ctx) : State, - Path(server): Path, - Path(id): Path, -) -> Result, StatusCode> { + Path((server, id)): Path<(String, String)>, +) -> crate::Result> { match user::Entity::find() .filter( Condition::all() .add(user::Column::PreferredUsername.eq(id)) .add(user::Column::Domain.eq(server)) ) - .one(ctx.db()).await + .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) - }, + Some(user) => Ok(JsonLD(ap_user(user).ld_context())), + None => Err(UpubError::not_found()), } }