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