From d3a2f9e01794a4cde214a7dab2205d4325a8266c Mon Sep 17 00:00:00 2001 From: Astro Date: Sun, 15 Oct 2023 21:01:15 +0200 Subject: [PATCH] cave: move more activitypub struct from buzzback --- buzzback/src/activitypub.rs | 48 ---------------------------------- buzzback/src/error.rs | 6 ----- buzzback/src/main.rs | 5 ++-- cave/src/activitypub/fetch.rs | 2 +- cave/src/activitypub/mod.rs | 49 +++++++++++++++++++++++++++++++++++ 5 files changed, 52 insertions(+), 58 deletions(-) delete mode 100644 buzzback/src/activitypub.rs diff --git a/buzzback/src/activitypub.rs b/buzzback/src/activitypub.rs deleted file mode 100644 index 460e2b7..0000000 --- a/buzzback/src/activitypub.rs +++ /dev/null @@ -1,48 +0,0 @@ -use serde::{Deserialize, Serialize}; - -#[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, - pub name: Option, - pub icon: Option, - pub inbox: String, - pub outbox: String, - #[serde(rename = "publicKey")] - pub public_key: ActorPublicKey, - #[serde(rename = "preferredUsername")] - pub preferred_username: Option, -} - -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct ActorPublicKey { - pub id: String, - pub owner: Option, - #[serde(rename = "publicKeyPem")] - pub pem: String, -} - -/// `ActivityPub` "activity" -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct Action { - #[serde(rename = "@context")] - pub jsonld_context: serde_json::Value, - #[serde(rename = "type")] - pub action_type: String, - pub id: String, - pub actor: String, - pub to: Option, - pub object: Option, -} - -#[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, -} diff --git a/buzzback/src/error.rs b/buzzback/src/error.rs index 3cd811d..ddaa7e2 100644 --- a/buzzback/src/error.rs +++ b/buzzback/src/error.rs @@ -1,7 +1,5 @@ #[derive(Debug, thiserror::Error)] pub enum Error { - #[error("HTTP Digest generation error")] - Digest, #[error("JSON encoding error")] Json(#[from] serde_json::Error), #[error("Signature error")] @@ -10,8 +8,4 @@ pub enum Error { HttpReq(#[from] http::Error), #[error("HTTP client error")] Http(#[from] reqwest::Error), - #[error("Invalid URI")] - InvalidUri, - #[error("Error response from remote")] - Response(String), } diff --git a/buzzback/src/main.rs b/buzzback/src/main.rs index ca0e709..15b692b 100644 --- a/buzzback/src/main.rs +++ b/buzzback/src/main.rs @@ -2,12 +2,11 @@ use sigh::PrivateKey; use std::{sync::Arc, time::Duration}; use std::{panic, process}; use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; -use cave::activitypub::send; +use cave::activitypub; mod error; mod config; mod db; -mod activitypub; async fn follow_back( client: &reqwest::Client, hostname: &str, @@ -29,7 +28,7 @@ async fn follow_back( object: Some(&follow.id), }; let key_id = format!("{}#key", follow.actor); - let result = send::send( + let result = activitypub::send::send( client, &follow.inbox, &key_id, &priv_key, &action, diff --git a/cave/src/activitypub/fetch.rs b/cave/src/activitypub/fetch.rs index 1211e81..b1fb039 100644 --- a/cave/src/activitypub/fetch.rs +++ b/cave/src/activitypub/fetch.rs @@ -23,7 +23,7 @@ where .header("host", &host) .header("content-type", "application/activity+json") .header("date", httpdate::fmt_http_date(SystemTime::now())) - .header("accept", "application/activity+json") + .header("accept", "application/activity+json, application/ld+json") .header("digest", digest_header) .body(vec![])?; SigningConfig::new(RsaSha256, private_key, key_id) diff --git a/cave/src/activitypub/mod.rs b/cave/src/activitypub/mod.rs index 774fa1e..619ecec 100644 --- a/cave/src/activitypub/mod.rs +++ b/cave/src/activitypub/mod.rs @@ -3,3 +3,52 @@ pub mod send; pub mod fetch; mod error; pub use error::Error; + +use serde::{Deserialize, Serialize}; + +#[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, + pub name: Option, + pub icon: Option, + pub inbox: String, + pub outbox: String, + #[serde(rename = "publicKey")] + pub public_key: ActorPublicKey, + #[serde(rename = "preferredUsername")] + pub preferred_username: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ActorPublicKey { + pub id: String, + pub owner: Option, + #[serde(rename = "publicKeyPem")] + pub pem: String, +} + +/// `ActivityPub` "activity" +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Action { + #[serde(rename = "@context")] + pub jsonld_context: serde_json::Value, + #[serde(rename = "type")] + pub action_type: String, + pub id: String, + pub actor: String, + pub to: Option, + pub object: Option, +} + +#[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, +}