feat: serve application actor on /

mastodon uses /actor, but i think the root is fine?
This commit is contained in:
əlemi 2024-03-20 11:24:54 +01:00
parent a6b6ca6965
commit 9a7199c496
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -6,7 +6,7 @@ pub mod activity;
use axum::{extract::State, http::StatusCode, Json}; use axum::{extract::State, http::StatusCode, Json};
use sea_orm::{EntityTrait, IntoActiveModel}; use sea_orm::{EntityTrait, IntoActiveModel};
use crate::{activitystream::{object::{activity::{Activity, ActivityType}, ObjectType}, Base, BaseType, Node}, model, server::Context}; use crate::{activitystream::{self, object::{activity::{Activity, ActivityType}, actor::{ActorMut, ActorType}, ObjectMut, ObjectType}, Base, BaseMut, BaseType, Node}, model, server::Context, url};
#[derive(Debug, serde::Deserialize)] #[derive(Debug, serde::Deserialize)]
@ -16,6 +16,19 @@ pub struct Page {
pub max_id: Option<String>, pub max_id: Option<String>,
} }
pub async fn view(State(ctx): State<Context>) -> Result<Json<serde_json::Value>, StatusCode> {
let mut base = activitystream::object();
base
.set_actor_type(Some(ActorType::Application))
.set_id(Some(&url!(ctx, "")))
.set_name(Some("μpub"))
.set_summary(Some("micro social network, federated"))
.set_inbox(Node::link(&url!(ctx, "/inbox")))
.set_outbox(Node::link(&url!(ctx, "/outbox")));
Ok(Json(base))
}
pub async fn inbox(State(ctx) : State<Context>, Json(object): Json<serde_json::Value>) -> Result<Json<serde_json::Value>, StatusCode> { pub async fn inbox(State(ctx) : State<Context>, Json(object): Json<serde_json::Value>) -> Result<Json<serde_json::Value>, StatusCode> {
match object.base_type() { match object.base_type() {
None => { Err(StatusCode::BAD_REQUEST) }, None => { Err(StatusCode::BAD_REQUEST) },