1 use crate::http::{create_apub_response, create_apub_tombstone_response};
2 use actix_web::{body::Body, web, HttpResponse};
3 use diesel::result::Error::NotFound;
4 use lemmy_api_common::blocking;
5 use lemmy_apub::objects::ToApub;
6 use lemmy_db_queries::Crud;
7 use lemmy_db_schema::{source::post::Post, PostId};
8 use lemmy_utils::LemmyError;
9 use lemmy_websocket::LemmyContext;
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 pub(crate) async fn get_apub_post(
19 info: web::Path<PostQuery>,
20 context: web::Data<LemmyContext>,
21 ) -> Result<HttpResponse<Body>, LemmyError> {
22 let id = PostId(info.post_id.parse::<i32>()?);
23 let post = blocking(context.pool(), move |conn| Post::read(conn, id)).await??;
25 return Err(NotFound.into());
29 Ok(create_apub_response(&post.to_apub(context.pool()).await?))
31 Ok(create_apub_tombstone_response(&post.to_tombstone()?))