1 use crate::APUB_JSON_CONTENT_TYPE;
2 use actix_web::{body::Body, web, HttpResponse};
3 use lemmy_db::activity::Activity;
4 use lemmy_structs::blocking;
5 use lemmy_utils::{settings::Settings, LemmyError};
6 use lemmy_websocket::LemmyContext;
7 use serde::{Deserialize, Serialize};
14 /// Convert the data to json and turn it into an HTTP Response with the correct ActivityPub
16 fn create_apub_response<T>(data: &T) -> HttpResponse<Body>
21 .content_type(APUB_JSON_CONTENT_TYPE)
25 fn create_apub_tombstone_response<T>(data: &T) -> HttpResponse<Body>
30 .content_type(APUB_JSON_CONTENT_TYPE)
34 #[derive(Deserialize)]
35 pub struct CommunityQuery {
40 /// Return the ActivityPub json representation of a local community over HTTP.
41 pub async fn get_activity(
42 info: web::Path<CommunityQuery>,
43 context: web::Data<LemmyContext>,
44 ) -> Result<HttpResponse<Body>, LemmyError> {
45 let settings = Settings::get();
46 let activity_id = format!(
47 "{}/activities/{}/{}",
48 settings.get_protocol_and_hostname(),
52 let activity = blocking(context.pool(), move |conn| {
53 Activity::read_from_apub_id(&conn, &activity_id)
57 if !activity.local || activity.sensitive {
58 Ok(HttpResponse::NotFound().finish())
60 Ok(create_apub_response(&activity.data))