2022-02-07 19:23:12 +00:00
|
|
|
use crate::{
|
|
|
|
activity_lists::SiteInboxActivities,
|
2022-06-02 14:33:41 +00:00
|
|
|
http::{create_apub_response, receive_lemmy_activity},
|
|
|
|
objects::{instance::ApubSite, person::ApubPerson},
|
2022-02-07 19:23:12 +00:00
|
|
|
protocol::collections::empty_outbox::EmptyOutbox,
|
|
|
|
};
|
2022-06-02 14:33:41 +00:00
|
|
|
use activitypub_federation::{deser::context::WithContext, traits::ApubObject};
|
|
|
|
use actix_web::{web, HttpRequest, HttpResponse};
|
2022-05-03 17:44:13 +00:00
|
|
|
use lemmy_api_common::utils::blocking;
|
2022-02-07 19:23:12 +00:00
|
|
|
use lemmy_db_schema::source::site::Site;
|
2022-06-22 20:24:54 +00:00
|
|
|
use lemmy_utils::error::LemmyError;
|
2022-02-07 19:23:12 +00:00
|
|
|
use lemmy_websocket::LemmyContext;
|
|
|
|
use url::Url;
|
|
|
|
|
|
|
|
pub(crate) async fn get_apub_site_http(
|
|
|
|
context: web::Data<LemmyContext>,
|
|
|
|
) -> Result<HttpResponse, LemmyError> {
|
2022-10-06 18:27:58 +00:00
|
|
|
let site: ApubSite = blocking(context.pool(), Site::read_local).await??.into();
|
2022-02-07 19:23:12 +00:00
|
|
|
|
|
|
|
let apub = site.into_apub(&context).await?;
|
|
|
|
Ok(create_apub_response(&apub))
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tracing::instrument(skip_all)]
|
2022-06-22 20:24:54 +00:00
|
|
|
pub(crate) async fn get_apub_site_outbox(
|
|
|
|
context: web::Data<LemmyContext>,
|
|
|
|
) -> Result<HttpResponse, LemmyError> {
|
2022-02-07 19:23:12 +00:00
|
|
|
let outbox_id = format!(
|
|
|
|
"{}/site_outbox",
|
2022-06-22 20:24:54 +00:00
|
|
|
context.settings().get_protocol_and_hostname()
|
2022-02-07 19:23:12 +00:00
|
|
|
);
|
|
|
|
let outbox = EmptyOutbox::new(Url::parse(&outbox_id)?).await?;
|
|
|
|
Ok(create_apub_response(&outbox))
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tracing::instrument(skip_all)]
|
|
|
|
pub async fn get_apub_site_inbox(
|
|
|
|
request: HttpRequest,
|
2022-06-02 14:33:41 +00:00
|
|
|
payload: String,
|
2022-02-07 19:23:12 +00:00
|
|
|
context: web::Data<LemmyContext>,
|
|
|
|
) -> Result<HttpResponse, LemmyError> {
|
2022-06-02 14:33:41 +00:00
|
|
|
receive_lemmy_activity::<WithContext<SiteInboxActivities>, ApubPerson>(request, payload, context)
|
|
|
|
.await
|
2022-02-07 19:23:12 +00:00
|
|
|
}
|