2 http::{create_apub_response, create_apub_tombstone_response},
5 use actix_web::{body::Body, web, HttpResponse};
6 use diesel::result::Error::NotFound;
7 use lemmy_api_structs::blocking;
8 use lemmy_db_queries::Crud;
9 use lemmy_db_schema::source::post::Post;
10 use lemmy_utils::LemmyError;
11 use lemmy_websocket::LemmyContext;
12 use serde::Deserialize;
14 #[derive(Deserialize)]
15 pub(crate) struct PostQuery {
19 /// Return the ActivityPub json representation of a local post over HTTP.
20 pub(crate) async fn get_apub_post(
21 info: web::Path<PostQuery>,
22 context: web::Data<LemmyContext>,
23 ) -> Result<HttpResponse<Body>, LemmyError> {
24 let id = info.post_id.parse::<i32>()?;
25 let post = blocking(context.pool(), move |conn| Post::read(conn, id)).await??;
27 return Err(NotFound.into());
31 Ok(create_apub_response(&post.to_apub(context.pool()).await?))
33 Ok(create_apub_tombstone_response(&post.to_tombstone()?))