forked from alemi/upub
feat: more consistent way to view remote users
This commit is contained in:
parent
6613f337ce
commit
8b10bde544
3 changed files with 25 additions and 25 deletions
|
@ -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"]
|
||||
|
|
|
@ -39,7 +39,6 @@ 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))
|
||||
|
@ -56,6 +55,11 @@ impl ActivityPubRouter for Router<crate::server::Context> {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Deserialize)]
|
||||
pub struct RemoteId {
|
||||
pub id: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Deserialize)]
|
||||
// TODO i don't really like how pleroma/mastodon do it actually, maybe change this?
|
||||
pub struct Pagination {
|
||||
|
|
|
@ -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<Context>, Path(id): Path<String>) -> crate::Result<JsonLD<serde_json::Value>> {
|
||||
match user::Entity::find_by_id(ctx.uid(id.clone()))
|
||||
pub async fn view(
|
||||
State(ctx) : State<Context>,
|
||||
Path(id): Path<String>,
|
||||
Query(rid): Query<RemoteId>,
|
||||
) -> crate::Result<JsonLD<serde_json::Value>> {
|
||||
// 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<Context>, Path(id): Path<String>) -> crate:
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn remote_view(
|
||||
State(ctx) : State<Context>,
|
||||
Path((server, id)): Path<(String, String)>,
|
||||
) -> crate::Result<JsonLD<serde_json::Value>> {
|
||||
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()),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue