1
0
Fork 0
forked from alemi/upub
upub/src/main.rs

47 lines
1.6 KiB
Rust
Raw Normal View History

pub mod model;
2024-03-14 05:27:08 +01:00
pub mod activitystream;
pub mod activitypub;
pub mod server;
pub mod storage;
use activitystream::{types::{ActivityType, ObjectType}, Object, Type};
use axum::{extract::{Path, State}, http::StatusCode, response::IntoResponse, routing::{get, post}, Json, Router};
2024-02-09 17:07:55 +01:00
#[tokio::main]
async fn main() {
// build our application with a single route
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));
2024-02-09 17:07:55 +01:00
// run our app with hyper, listening globally on port 3000
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
axum::serve(listener, app)
.await
.unwrap();
}
async fn inbox(State(ctx) : State<()>, Json(object): Json<serde_json::Value>) -> Result<Json<serde_json::Value>, 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<String>) -> Result<Json<serde_json::Value>, StatusCode> {
todo!()
}
async fn object(State(ctx) : State<()>, Path(id): Path<String>) -> Result<Json<serde_json::Value>, StatusCode> {
todo!()
}