diff --git a/src/activitystream/mod.rs b/src/activitystream/mod.rs index 3837ac9..8c9161b 100644 --- a/src/activitystream/mod.rs +++ b/src/activitystream/mod.rs @@ -5,3 +5,7 @@ pub use object::{Object, Link, ObjectOrLink}; pub mod activity; pub use activity::Activity; + + +pub mod types; +pub use types::Type; diff --git a/src/activitystream/object.rs b/src/activitystream/object.rs index 72c7fad..b3941c0 100644 --- a/src/activitystream/object.rs +++ b/src/activitystream/object.rs @@ -27,7 +27,7 @@ pub trait Link { pub trait Object { fn id(&self) -> Option<&str> { None } - fn object_type(&self) -> Option<&str> { None } + fn object_type(&self) -> Option { None } fn attachment (&self) -> Option<&str> { None } fn attributed_to (&self) -> Option<&str> { None } fn audience (&self) -> Option<&str> { None } @@ -66,8 +66,8 @@ impl Object for serde_json::Value { self.get("id")?.as_str() } - fn object_type(&self) -> Option<&str> { - self.get("type")?.as_str() + fn object_type(&self) -> Option { + todo!() } // ... diff --git a/src/activitystream/types.rs b/src/activitystream/types.rs new file mode 100644 index 0000000..ebcab58 --- /dev/null +++ b/src/activitystream/types.rs @@ -0,0 +1,68 @@ +pub enum Type { + Object, + ObjectType(ObjectType), + Link, + Mention, // TODO what about this??? + Activity, + IntransitiveActivity, + ActivityType(ActivityType), + Collection, + OrderedCollection, + CollectionPage, + OrderedCollectionPage, + ActorType(ActorType), +} + +pub enum ActivityType { + Accept, + Add, + Announce, + Arrive, + Block, + Create, + Delete, + Dislike, + Flag, + Follow, + Ignore, + Invite, + Join, + Leave, + Like, + Listen, + Move, + Offer, + Question, + Reject, + Read, + Remove, + TentativeReject, + TentativeAccept, + Travel, + Undo, + Update, + View, +} + +pub enum ActorType { + Application, + Group, + Organization, + Person, + Service, +} + +pub enum ObjectType { + Article, + Audio, + Document, + Event, + Image, + Note, + Page, + Place, + Profile, + Relationship, + Tombstone, + Video, +} diff --git a/src/main.rs b/src/main.rs index 7dbb9b4..9ff0730 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,15 +1,21 @@ pub mod model; pub mod activitystream; +pub mod activitypub; +pub mod server; +pub mod storage; -use axum::{ - routing::get, - Router, -}; +use activitystream::{types::{ActivityType, ObjectType}, Object, Type}; +use axum::{extract::{Path, State}, http::StatusCode, response::IntoResponse, routing::{get, post}, Json, Router}; #[tokio::main] async fn main() { // build our application with a single route - let app = Router::new().route("/", get(|| async { "Hello, World!" })); + let app = Router::new() + .with_state(()) + .route("/inbox", post(inbox)) + .route("/outbox", get(|| async { todo!() })) + .route("/users/:id", get(user)) + .route("/objects/:id", get(object)); // run our app with hyper, listening globally on port 3000 let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap(); @@ -18,3 +24,23 @@ async fn main() { .await .unwrap(); } + +async fn inbox(State(ctx) : State<()>, Json(object): Json) -> Result, StatusCode> { + match object.object_type() { + None => { Err(StatusCode::BAD_REQUEST) }, + Some(Type::Activity) => { Err(StatusCode::UNPROCESSABLE_ENTITY) }, + Some(Type::ActivityType(ActivityType::Follow)) => { todo!() }, + Some(Type::ActivityType(ActivityType::Create)) => { todo!() }, + Some(Type::ActivityType(ActivityType::Like)) => { todo!() }, + Some(Type::ActivityType(x)) => { Err(StatusCode::NOT_IMPLEMENTED) }, + Some(x) => { Err(StatusCode::UNPROCESSABLE_ENTITY) } + } +} + +async fn user(State(ctx) : State<()>, Path(id): Path) -> Result, StatusCode> { + todo!() +} + +async fn object(State(ctx) : State<()>, Path(id): Path) -> Result, StatusCode> { + todo!() +}