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_db::source::post::Post;
8 use lemmy_structs::blocking;
9 use lemmy_utils::LemmyError;
10 use lemmy_websocket::LemmyContext;
11 use serde::Deserialize;
13 #[derive(Deserialize)]
14 pub struct PostQuery {
18 /// Return the ActivityPub json representation of a local post over HTTP.
19 pub async fn get_apub_post(
20 info: web::Path<PostQuery>,
21 context: web::Data<LemmyContext>,
22 ) -> Result<HttpResponse<Body>, LemmyError> {
23 let id = info.post_id.parse::<i32>()?;
24 let post = blocking(context.pool(), move |conn| Post::read(conn, id)).await??;
26 return Err(NotFound.into());
30 Ok(create_apub_response(&post.to_apub(context.pool()).await?))
32 Ok(create_apub_tombstone_response(&post.to_tombstone()?))