diff --git a/Cargo.toml b/Cargo.toml index 3bde751..b32c6f5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,6 +32,7 @@ tokio = { version = "1.35", features = ["full"] } # TODO slim this down sea-orm = { version = "0.12", features = ["macros", "sqlx-sqlite", "runtime-tokio-rustls"] } reqwest = { version = "0.12", features = ["json"] } axum = "0.7" +tower-http = { version = "0.5", features = ["cors", "trace"] } apb = { path = "apb", features = ["unstructured", "orm"] } # nodeinfo = "0.0.2" # the version on crates.io doesn't re-export necessary types to build the struct!!! nodeinfo = { git = "https://codeberg.org/thefederationinfo/nodeinfo-rs", rev = "e865094804" } @@ -40,7 +41,6 @@ sea-orm-migration = { version = "0.12", optional = true } # mastodon mastodon-async-entities = { version = "1.1.0", optional = true } time = { version = "0.3", features = ["serde"], optional = true } -tower-http = { version = "0.5.2", features = ["cors", "trace"] } [features] default = ["faker", "migrations", "mastodon"] diff --git a/src/routes/activitypub/mod.rs b/src/routes/activitypub/mod.rs index 3cd4df2..680660d 100644 --- a/src/routes/activitypub/mod.rs +++ b/src/routes/activitypub/mod.rs @@ -39,7 +39,6 @@ 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)) @@ -56,6 +55,11 @@ 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/user/mod.rs b/src/routes/activitypub/user/mod.rs index 0ec881f..c6dfbd4 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, State}; -use sea_orm::{ColumnTrait, Condition, EntityTrait, QueryFilter}; +use axum::extract::{Path, Query, 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}; +use super::{jsonld::LD, JsonLD, RemoteId}; pub fn ap_user(user: model::user::Model) -> serde_json::Value { serde_json::Value::new_object() @@ -44,8 +44,22 @@ 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) -> crate::Result> { - match user::Entity::find_by_id(ctx.uid(id.clone())) +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()); + } + } else { + ctx.uid(id.clone()) + }; + match user::Entity::find_by_id(uid) .find_also_related(model::config::Entity) .one(ctx.db()).await? { @@ -66,21 +80,3 @@ pub async fn view(State(ctx) : State, Path(id): Path) -> crate: } } -pub async fn remote_view( - State(ctx) : State, - 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? - { - // local user - Some(user) => Ok(JsonLD(ap_user(user).ld_context())), - None => Err(UpubError::not_found()), - } -} -