2 http::{create_apub_response, create_apub_tombstone_response},
5 use actix_web::{body::Body, web, web::Path, HttpResponse};
6 use diesel::result::Error::NotFound;
7 use lemmy_api_common::blocking;
8 use lemmy_db_schema::{newtypes::CommentId, source::comment::Comment, traits::Crud};
9 use lemmy_utils::LemmyError;
10 use lemmy_websocket::LemmyContext;
11 use serde::Deserialize;
13 #[derive(Deserialize)]
14 pub(crate) struct CommentQuery {
18 /// Return the ActivityPub json representation of a local comment over HTTP.
19 pub(crate) async fn get_apub_comment(
20 info: Path<CommentQuery>,
21 context: web::Data<LemmyContext>,
22 ) -> Result<HttpResponse<Body>, LemmyError> {
23 let id = CommentId(info.comment_id.parse::<i32>()?);
24 let comment = blocking(context.pool(), move |conn| Comment::read(conn, id)).await??;
26 return Err(NotFound.into());
30 Ok(create_apub_response(
31 &comment.to_apub(context.pool()).await?,
34 Ok(create_apub_tombstone_response(&comment.to_tombstone()?))