buzzrelay/src/activitypub.rs

64 lines
1.7 KiB
Rust
Raw Permalink Normal View History

2022-12-19 20:20:13 +00:00
use axum::{response::IntoResponse, Json};
2022-12-19 23:15:00 +00:00
use serde::{Deserialize, Serialize};
2022-12-11 00:07:39 +00:00
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Actor {
#[serde(rename = "@context")]
pub jsonld_context: serde_json::Value,
#[serde(rename = "type")]
pub actor_type: String,
pub id: String,
2022-12-23 17:56:45 +00:00
pub name: Option<String>,
pub icon: Option<Media>,
2022-12-11 00:07:39 +00:00
pub inbox: String,
2023-10-29 23:29:11 +00:00
pub outbox: Option<String>,
2023-10-30 00:21:30 +00:00
pub endpoints: Option<ActorEndpoints>,
2022-12-11 00:07:39 +00:00
#[serde(rename = "publicKey")]
pub public_key: ActorPublicKey,
2022-12-12 20:31:42 +00:00
#[serde(rename = "preferredUsername")]
2022-12-19 20:20:13 +00:00
pub preferred_username: Option<String>,
2022-12-11 00:07:39 +00:00
}
2023-10-30 00:21:30 +00:00
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ActorEndpoints {
#[serde(rename = "sharedInbox")]
pub shared_inbox: String,
}
2022-12-11 00:07:39 +00:00
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ActorPublicKey {
pub id: String,
pub owner: Option<String>,
#[serde(rename = "publicKeyPem")]
pub pem: String,
}
2022-12-19 23:15:00 +00:00
/// `ActivityPub` "activity"
2022-12-11 00:07:39 +00:00
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Action<O> {
2022-12-13 03:12:35 +00:00
#[serde(rename = "@context")]
pub jsonld_context: serde_json::Value,
2022-12-11 00:07:39 +00:00
#[serde(rename = "type")]
pub action_type: String,
2022-12-13 03:12:35 +00:00
pub id: String,
2022-12-11 00:07:39 +00:00
pub actor: String,
pub to: Option<serde_json::Value>,
2022-12-11 00:07:39 +00:00
pub object: Option<O>,
}
2022-12-19 20:20:13 +00:00
impl IntoResponse for Actor {
fn into_response(self) -> axum::response::Response {
([("content-type", "application/activity+json")],
Json(self)).into_response()
}
}
2022-12-23 17:56:45 +00:00
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Media {
#[serde(rename = "type")]
2023-10-29 23:29:11 +00:00
pub media_type: Option<String>,
2022-12-23 17:56:45 +00:00
#[serde(rename = "mediaType")]
2023-10-29 23:29:11 +00:00
pub content_type: Option<String>,
2022-12-23 17:56:45 +00:00
pub url: String,
}