2 http::{create_apub_response, create_apub_tombstone_response, err_object_not_local},
3 objects::post::ApubPost,
5 use activitypub_federation::traits::ApubObject;
6 use actix_web::{web, HttpResponse};
7 use lemmy_api_common::context::LemmyContext;
8 use lemmy_db_schema::{newtypes::PostId, source::post::Post, traits::Crud};
9 use lemmy_utils::error::LemmyError;
10 use serde::Deserialize;
12 #[derive(Deserialize)]
13 pub(crate) struct PostQuery {
17 /// Return the ActivityPub json representation of a local post over HTTP.
18 #[tracing::instrument(skip_all)]
19 pub(crate) async fn get_apub_post(
20 info: web::Path<PostQuery>,
21 context: web::Data<LemmyContext>,
22 ) -> Result<HttpResponse, LemmyError> {
23 let id = PostId(info.post_id.parse::<i32>()?);
24 let post: ApubPost = Post::read(context.pool(), id).await?.into();
26 return Err(err_object_not_local());
29 if !post.deleted && !post.removed {
30 Ok(create_apub_response(&post.into_apub(&context).await?))
32 Ok(create_apub_tombstone_response(post.ap_id.clone()))