mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-06-02 05:40:11 +00:00
35cbae61bc
* Respond directly with LemmyError Instrument Perform implementations for more precise traces Use ApiError to format JSON errors when messages are present Keep SpanTrace output in LemmyError Display impl * Hide SpanTrace debug output from LemmyError * Don't log when entering spans, only when leaving * Update actix-web * Update actix-rt * Add newline after error info in LemmyError Display impl * Propogate span information to blocking operations * Instrument apub functions * Use skip_all for more instrument attributes, don't skip 'self' in some api actions * Make message a static string * Send proper JSON over websocket * Add 'message' to LemmyError display if present * Use a quieter root span builder, don't pretty-print logs * Keep passwords and emails out of logs * Re-enable logging Login * Instrument feeds * Emit our own errors * Move error log after status code recording * Make Sensitive generic over the inner type * Remove line that logged secrets
39 lines
1.2 KiB
Rust
39 lines
1.2 KiB
Rust
use crate::{
|
|
http::{create_apub_response, create_apub_tombstone_response},
|
|
objects::comment::ApubComment,
|
|
};
|
|
use actix_web::{body::AnyBody, web, web::Path, HttpResponse};
|
|
use diesel::result::Error::NotFound;
|
|
use lemmy_api_common::blocking;
|
|
use lemmy_apub_lib::traits::ApubObject;
|
|
use lemmy_db_schema::{newtypes::CommentId, source::comment::Comment, traits::Crud};
|
|
use lemmy_utils::LemmyError;
|
|
use lemmy_websocket::LemmyContext;
|
|
use serde::Deserialize;
|
|
|
|
#[derive(Deserialize)]
|
|
pub(crate) struct CommentQuery {
|
|
comment_id: String,
|
|
}
|
|
|
|
/// Return the ActivityPub json representation of a local comment over HTTP.
|
|
#[tracing::instrument(skip_all)]
|
|
pub(crate) async fn get_apub_comment(
|
|
info: Path<CommentQuery>,
|
|
context: web::Data<LemmyContext>,
|
|
) -> Result<HttpResponse<AnyBody>, LemmyError> {
|
|
let id = CommentId(info.comment_id.parse::<i32>()?);
|
|
let comment: ApubComment = blocking(context.pool(), move |conn| Comment::read(conn, id))
|
|
.await??
|
|
.into();
|
|
if !comment.local {
|
|
return Err(NotFound.into());
|
|
}
|
|
|
|
if !comment.deleted {
|
|
Ok(create_apub_response(&comment.into_apub(&**context).await?))
|
|
} else {
|
|
Ok(create_apub_tombstone_response(&comment.to_tombstone()?))
|
|
}
|
|
}
|