diff --git a/src/routes/activitypub/activity.rs b/src/routes/activitypub/activity.rs index ebdb4fc4..59e8ba56 100644 --- a/src/routes/activitypub/activity.rs +++ b/src/routes/activitypub/activity.rs @@ -25,8 +25,13 @@ pub async fn view( Path(id): Path, AuthIdentity(auth): AuthIdentity, ) -> Result, StatusCode> { + let aid = if id.starts_with('+') { + format!("https://{}", id.replacen('+', "", 1).replace('@', "/")) + } else { + ctx.aid(id.clone()) + }; match model::addressing::Entity::find_activities() - .filter(model::activity::Column::Id.eq(ctx.aid(id))) + .filter(model::activity::Column::Id.eq(aid)) .filter(auth.filter_condition()) .into_model::() .one(ctx.db()) diff --git a/src/routes/activitypub/mod.rs b/src/routes/activitypub/mod.rs index 995cefcf..c4cd3a92 100644 --- a/src/routes/activitypub/mod.rs +++ b/src/routes/activitypub/mod.rs @@ -65,11 +65,6 @@ impl ActivityPubRouter for Router { } } -#[derive(Debug, serde::Deserialize)] -pub struct RemoteId { - pub id: Option, -} - #[derive(Debug, serde::Deserialize)] // TODO i don't really like how pleroma/mastodon do it actually, maybe change this? pub struct Pagination { diff --git a/src/routes/activitypub/object.rs b/src/routes/activitypub/object.rs index 1471e508..716d461e 100644 --- a/src/routes/activitypub/object.rs +++ b/src/routes/activitypub/object.rs @@ -28,8 +28,13 @@ pub async fn view( Path(id): Path, AuthIdentity(auth): AuthIdentity, ) -> Result, StatusCode> { + let oid = if id.starts_with('+') { + format!("https://{}", id.replacen('+', "", 1).replace('@', "/")) + } else { + ctx.oid(id.clone()) + }; match model::addressing::Entity::find_activities() - .filter(model::object::Column::Id.eq(ctx.oid(id))) + .filter(model::object::Column::Id.eq(oid)) .filter(auth.filter_condition()) .into_model::() .one(ctx.db()) diff --git a/src/routes/activitypub/user/mod.rs b/src/routes/activitypub/user/mod.rs index c6dfbd49..2d209585 100644 --- a/src/routes/activitypub/user/mod.rs +++ b/src/routes/activitypub/user/mod.rs @@ -4,13 +4,13 @@ pub mod outbox; pub mod following; -use axum::extract::{Path, Query, State}; +use axum::extract::{Path, State}; use sea_orm::EntityTrait; use apb::{PublicKeyMut, ActorMut, DocumentMut, DocumentType, ObjectMut, BaseMut, Node}; use crate::{errors::UpubError, model::{self, user}, server::Context, url}; -use super::{jsonld::LD, JsonLD, RemoteId}; +use super::{jsonld::LD, JsonLD}; pub fn ap_user(user: model::user::Model) -> serde_json::Value { serde_json::Value::new_object() @@ -47,15 +47,9 @@ pub fn ap_user(user: model::user::Model) -> serde_json::Value { pub async fn view( State(ctx) : State, Path(id): Path, - Query(rid): Query, ) -> crate::Result> { - // TODO can this be made less convoluted??? - let uid = if id == "+" { - if let Some(rid) = rid.id { - rid - } else { - return Err(UpubError::bad_request()); - } + let uid = if id.starts_with('+') { + format!("https://{}", id.replacen('+', "", 1).replace('@', "/")) } else { ctx.uid(id.clone()) };