This repository has been archived on 2023-07-11. You can view files and clone it, but cannot push or open issues or pull requests.
buzzrelay/src/activitypub.rs

56 lines
1.5 KiB
Rust
Raw Normal View History

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