2024-03-20 05:44:50 +01:00
|
|
|
pub mod user;
|
2024-03-24 04:05:09 +01:00
|
|
|
pub mod inbox;
|
|
|
|
pub mod outbox;
|
2024-03-20 05:44:50 +01:00
|
|
|
pub mod object;
|
2024-04-19 03:29:28 +02:00
|
|
|
pub mod context;
|
2024-03-20 05:44:50 +01:00
|
|
|
pub mod activity;
|
2024-04-11 00:29:32 +02:00
|
|
|
pub mod application;
|
|
|
|
pub mod auth;
|
2024-03-22 00:17:52 +01:00
|
|
|
pub mod well_known;
|
|
|
|
|
2024-03-21 03:07:35 +01:00
|
|
|
pub mod jsonld;
|
|
|
|
pub use jsonld::JsonLD;
|
2024-03-20 05:44:50 +01:00
|
|
|
|
2024-04-11 00:29:32 +02:00
|
|
|
use axum::{http::StatusCode, response::IntoResponse, routing::{get, post}, Router};
|
2024-03-20 05:44:50 +01:00
|
|
|
|
2024-04-11 00:29:32 +02:00
|
|
|
pub trait ActivityPubRouter {
|
|
|
|
fn ap_routes(self) -> Self;
|
2024-04-09 04:35:57 +02:00
|
|
|
}
|
|
|
|
|
2024-04-11 00:29:32 +02:00
|
|
|
impl ActivityPubRouter for Router<crate::server::Context> {
|
|
|
|
fn ap_routes(self) -> Self {
|
|
|
|
use crate::routes::activitypub as ap; // TODO use self ?
|
|
|
|
|
|
|
|
self
|
|
|
|
// core server inbox/outbox, maybe for feeds? TODO do we need these?
|
|
|
|
.route("/", get(ap::application::view))
|
|
|
|
// TODO shared inboxes and instance stream will come later, just use users *boxes for now
|
2024-04-12 20:01:47 +02:00
|
|
|
.route("/inbox", post(ap::inbox::post))
|
2024-04-11 00:29:32 +02:00
|
|
|
.route("/inbox", get(ap::inbox::get))
|
2024-04-12 20:01:47 +02:00
|
|
|
.route("/inbox/page", get(ap::inbox::page))
|
|
|
|
.route("/outbox", post(ap::outbox::post))
|
|
|
|
.route("/outbox", get(ap::outbox::get))
|
|
|
|
.route("/outbox/page", get(ap::outbox::page))
|
2024-04-11 00:29:32 +02:00
|
|
|
// AUTH routes
|
|
|
|
.route("/auth", post(ap::auth::login))
|
|
|
|
// .well-known and discovery
|
|
|
|
.route("/.well-known/webfinger", get(ap::well_known::webfinger))
|
|
|
|
.route("/.well-known/host-meta", get(ap::well_known::host_meta))
|
|
|
|
.route("/.well-known/nodeinfo", get(ap::well_known::nodeinfo_discovery))
|
2024-04-18 05:46:10 +02:00
|
|
|
.route("/.well-known/oauth-authorization-server", get(ap::well_known::oauth_authorization_server))
|
2024-04-11 00:29:32 +02:00
|
|
|
.route("/nodeinfo/:version", get(ap::well_known::nodeinfo))
|
|
|
|
// actor routes
|
|
|
|
.route("/users/:id", get(ap::user::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))
|
|
|
|
.route("/users/:id/outbox", post(ap::user::outbox::post))
|
|
|
|
.route("/users/:id/outbox", get(ap::user::outbox::get))
|
|
|
|
.route("/users/:id/outbox/page", get(ap::user::outbox::page))
|
|
|
|
.route("/users/:id/followers", get(ap::user::following::get::<false>))
|
|
|
|
.route("/users/:id/followers/page", get(ap::user::following::page::<false>))
|
|
|
|
.route("/users/:id/following", get(ap::user::following::get::<true>))
|
|
|
|
.route("/users/:id/following/page", get(ap::user::following::page::<true>))
|
2024-04-15 01:56:54 +02:00
|
|
|
// activities
|
2024-04-11 00:29:32 +02:00
|
|
|
.route("/activities/:id", get(ap::activity::view))
|
2024-04-15 01:56:54 +02:00
|
|
|
// context
|
2024-04-19 03:29:28 +02:00
|
|
|
.route("/context/:id", get(ap::context::get))
|
|
|
|
.route("/context/:id/page", get(ap::context::page))
|
2024-04-15 01:56:54 +02:00
|
|
|
// specific object routes
|
2024-04-11 00:29:32 +02:00
|
|
|
.route("/objects/:id", get(ap::object::view))
|
2024-04-19 03:32:21 +02:00
|
|
|
.route("/objects/:id/replies", get(ap::object::replies::get))
|
|
|
|
.route("/objects/:id/replies/page", get(ap::object::replies::page))
|
2024-04-15 01:56:54 +02:00
|
|
|
//.route("/objects/:id/likes", get(ap::object::likes::get))
|
|
|
|
//.route("/objects/:id/likes/page", get(ap::object::likes::page))
|
|
|
|
//.route("/objects/:id/announces", get(ap::object::announces::get))
|
|
|
|
//.route("/objects/:id/announces/page", get(ap::object::announces::page))
|
2024-04-06 16:56:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-18 04:48:49 +02:00
|
|
|
#[derive(Debug, serde::Deserialize)]
|
|
|
|
pub struct TryFetch {
|
|
|
|
#[serde(default)]
|
|
|
|
pub fetch: bool,
|
|
|
|
}
|
|
|
|
|
2024-03-20 07:55:24 +01:00
|
|
|
#[derive(Debug, serde::Deserialize)]
|
|
|
|
// TODO i don't really like how pleroma/mastodon do it actually, maybe change this?
|
2024-03-22 02:50:38 +01:00
|
|
|
pub struct Pagination {
|
|
|
|
pub offset: Option<u64>,
|
|
|
|
pub batch: Option<u64>,
|
2024-03-20 05:44:50 +01:00
|
|
|
}
|
|
|
|
|
2024-03-28 04:52:17 +01:00
|
|
|
pub struct CreationResult(pub String);
|
|
|
|
impl IntoResponse for CreationResult {
|
|
|
|
fn into_response(self) -> axum::response::Response {
|
|
|
|
(
|
|
|
|
StatusCode::CREATED,
|
|
|
|
[("Location", self.0.as_str())]
|
|
|
|
)
|
|
|
|
.into_response()
|
|
|
|
}
|
|
|
|
}
|