This commit is contained in:
Felix Ableitner 2025-07-09 14:41:08 +02:00
parent f0e5149922
commit fae86b9926
3 changed files with 10 additions and 5 deletions

View file

@ -10,7 +10,9 @@ use serde::Serialize;
use serde_json::Value; use serde_json::Value;
use url::Url; use url::Url;
/// TODO /// Generates HTTP response to serve the object for fetching from other instances.
///
/// `federation_context` is the value of `@context`.
pub fn create_http_response<T: Serialize>( pub fn create_http_response<T: Serialize>(
data: T, data: T,
federation_context: &Value, federation_context: &Value,

View file

@ -4,7 +4,7 @@ use crate::kinds::object::TombstoneType;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use url::Url; use url::Url;
/// For serving deleted objects /// Represents a local object that was deleted
#[derive(Clone, Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct Tombstone { pub struct Tombstone {

View file

@ -171,10 +171,13 @@ pub trait Object: Sized + Debug {
/// create and update, so an `upsert` operation should be used. /// create and update, so an `upsert` operation should be used.
async fn from_json(json: Self::Kind, data: &Data<Self::DataType>) -> Result<Self, Self::Error>; async fn from_json(json: Self::Kind, data: &Data<Self::DataType>) -> Result<Self, Self::Error>;
/// Convert the data to json and turn it into an HTTP Response with the correct ActivityPub /// Generates HTTP response to serve the object for fetching from other instances.
/// headers.
/// ///
/// actix-web doesn't allow pretty-print for json so we need to do this manually. /// - If the object has a remote domain, sends a redirect to the original instance.
/// - If [Object.is_deleted] returns true, returns a [crate::protocol::tombstone::Tombstone] instead.
/// - Otherwise serves the object JSON using [Object.into_json] and pretty-print
///
/// `federation_context` is the value of `@context`.
#[cfg(feature = "actix-web")] #[cfg(feature = "actix-web")]
async fn http_response( async fn http_response(
self, self,