mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-06-27 09:40:33 +00:00
* Create example for apub lib * some rewriting of apub lib * Add LocalInstance struct for apub lib to avoid using Lemmy Settings * Move ActorType trait to lemmy_apub, because its not needed in library * Use reqwest_retry instead of custom impl, dont specify timeout on every send() * Some improvements to example * Moved inbox handling to library * bug fixes * Move context and serde helpers into library * wip: example changes * Add lemmy_utils feature to build only LemmyError * Rename to activitypub_federation * Remove lemmy_utils dep from activitypub_federation using generic error type * Finish activitypub example * Cleanup and fix tests * Reorganize library files * Remove ApubObject.to_tombstone() * Extract activitypub library into separate git repository
45 lines
1.4 KiB
Rust
45 lines
1.4 KiB
Rust
use crate::{
|
|
activity_lists::SiteInboxActivities,
|
|
http::{create_apub_response, receive_lemmy_activity},
|
|
objects::{instance::ApubSite, person::ApubPerson},
|
|
protocol::collections::empty_outbox::EmptyOutbox,
|
|
};
|
|
use activitypub_federation::{deser::context::WithContext, traits::ApubObject};
|
|
use actix_web::{web, HttpRequest, HttpResponse};
|
|
use lemmy_api_common::utils::blocking;
|
|
use lemmy_db_schema::source::site::Site;
|
|
use lemmy_utils::{error::LemmyError, settings::structs::Settings};
|
|
use lemmy_websocket::LemmyContext;
|
|
use url::Url;
|
|
|
|
pub(crate) async fn get_apub_site_http(
|
|
context: web::Data<LemmyContext>,
|
|
) -> Result<HttpResponse, LemmyError> {
|
|
let site: ApubSite = blocking(context.pool(), Site::read_local_site)
|
|
.await??
|
|
.into();
|
|
|
|
let apub = site.into_apub(&context).await?;
|
|
Ok(create_apub_response(&apub))
|
|
}
|
|
|
|
#[tracing::instrument(skip_all)]
|
|
pub(crate) async fn get_apub_site_outbox() -> Result<HttpResponse, LemmyError> {
|
|
let outbox_id = format!(
|
|
"{}/site_outbox",
|
|
Settings::get().get_protocol_and_hostname()
|
|
);
|
|
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,
|
|
payload: String,
|
|
context: web::Data<LemmyContext>,
|
|
) -> Result<HttpResponse, LemmyError> {
|
|
receive_lemmy_activity::<WithContext<SiteInboxActivities>, ApubPerson>(request, payload, context)
|
|
.await
|
|
}
|