1 use crate::http::{create_apub_response, create_apub_tombstone_response};
2 use actix_web::{body::Body, web, web::Path, 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::comment::Comment, CommentId};
8 use lemmy_utils::LemmyError;
9 use lemmy_websocket::LemmyContext;
10 use serde::Deserialize;
12 #[derive(Deserialize)]
13 pub(crate) struct CommentQuery {
17 /// Return the ActivityPub json representation of a local comment over HTTP.
18 pub(crate) async fn get_apub_comment(
19 info: Path<CommentQuery>,
20 context: web::Data<LemmyContext>,
21 ) -> Result<HttpResponse<Body>, LemmyError> {
22 let id = CommentId(info.comment_id.parse::<i32>()?);
23 let comment = blocking(context.pool(), move |conn| Comment::read(conn, id)).await??;
25 return Err(NotFound.into());
29 Ok(create_apub_response(
30 &comment.to_apub(context.pool()).await?,
33 Ok(create_apub_tombstone_response(&comment.to_tombstone()?))