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;
|
|
|
|
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))
|
|
|
|
.route("/nodeinfo/:version", get(ap::well_known::nodeinfo))
|
|
|
|
// actor routes
|
|
|
|
.route("/users/:id", get(ap::user::view))
|
2024-04-13 06:50:04 +02:00
|
|
|
.route("/users/:server/:id", get(ap::user::remote_view))
|
2024-04-11 00:29:32 +02:00
|
|
|
.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>))
|
|
|
|
// specific object routes
|
|
|
|
.route("/activities/:id", get(ap::activity::view))
|
|
|
|
.route("/objects/:id", get(ap::object::view))
|
2024-04-06 16:56:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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()
|
|
|
|
}
|
|
|
|
}
|