feat(bootstrap): wire ActivityPubService as FederationActionPort in AppState
This commit is contained in:
@@ -3,7 +3,7 @@ use sqlx::PgPool;
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use activitypub::ThoughtsObjectHandler;
|
use activitypub::ThoughtsObjectHandler;
|
||||||
use activitypub_base::{ApFederationConfig, FederationData};
|
use activitypub_base::service::ActivityPubService;
|
||||||
use domain::{errors::DomainError, events::DomainEvent, ports::EventPublisher};
|
use domain::{errors::DomainError, events::DomainEvent, ports::EventPublisher};
|
||||||
use event_transport::EventPublisherAdapter;
|
use event_transport::EventPublisherAdapter;
|
||||||
use nats::NatsTransport;
|
use nats::NatsTransport;
|
||||||
@@ -16,7 +16,7 @@ use crate::config::Config;
|
|||||||
/// Everything the binary needs to start serving.
|
/// Everything the binary needs to start serving.
|
||||||
pub struct Infrastructure {
|
pub struct Infrastructure {
|
||||||
pub state: AppState,
|
pub state: AppState,
|
||||||
pub fed_config: ApFederationConfig,
|
pub ap_service: Arc<ActivityPubService>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct NoOpEventPublisher;
|
struct NoOpEventPublisher;
|
||||||
@@ -61,24 +61,26 @@ pub async fn build(cfg: &Config) -> Infrastructure {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// 3. ActivityPub federation
|
// 3. ActivityPub federation
|
||||||
let fed_data = FederationData::new(
|
let ap_service = Arc::new(
|
||||||
Arc::new(PostgresFederationRepository::new(pool.clone())),
|
ActivityPubService::new(
|
||||||
Arc::new(PostgresApUserRepository::new(
|
Arc::new(PostgresFederationRepository::new(pool.clone())),
|
||||||
pool.clone(),
|
Arc::new(PostgresApUserRepository::new(
|
||||||
|
pool.clone(),
|
||||||
|
cfg.base_url.clone(),
|
||||||
|
)),
|
||||||
|
Arc::new(ThoughtsObjectHandler::new(
|
||||||
|
Arc::new(PgActivityPubRepository::new(pool.clone())),
|
||||||
|
&cfg.base_url,
|
||||||
|
)),
|
||||||
cfg.base_url.clone(),
|
cfg.base_url.clone(),
|
||||||
)),
|
cfg.allow_registration,
|
||||||
Arc::new(ThoughtsObjectHandler::new(
|
"thoughts".to_string(),
|
||||||
Arc::new(PgActivityPubRepository::new(pool.clone())),
|
cfg.debug,
|
||||||
&cfg.base_url,
|
None,
|
||||||
)),
|
)
|
||||||
cfg.base_url.clone(),
|
|
||||||
cfg.allow_registration,
|
|
||||||
"thoughts".to_string(),
|
|
||||||
None,
|
|
||||||
);
|
|
||||||
let fed_config = ApFederationConfig::new(fed_data, cfg.debug)
|
|
||||||
.await
|
.await
|
||||||
.expect("Failed to build federation config");
|
.expect("Failed to build ActivityPubService"),
|
||||||
|
);
|
||||||
|
|
||||||
// 4. Application state
|
// 4. Application state
|
||||||
let state = AppState {
|
let state = AppState {
|
||||||
@@ -107,7 +109,8 @@ pub async fn build(cfg: &Config) -> Infrastructure {
|
|||||||
)),
|
)),
|
||||||
hasher: Arc::new(auth::Argon2PasswordHasher),
|
hasher: Arc::new(auth::Argon2PasswordHasher),
|
||||||
events: event_publisher,
|
events: event_publisher,
|
||||||
|
federation: ap_service.clone() as Arc<dyn domain::ports::FederationActionPort>,
|
||||||
};
|
};
|
||||||
|
|
||||||
Infrastructure { state, fed_config }
|
Infrastructure { state, ap_service }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ async fn main() {
|
|||||||
"/users/{username}/following",
|
"/users/{username}/following",
|
||||||
axum::routing::get(following_handler),
|
axum::routing::get(following_handler),
|
||||||
)
|
)
|
||||||
.layer(infra.fed_config.middleware());
|
.layer(infra.ap_service.federation_config().middleware());
|
||||||
|
|
||||||
let base = presentation::routes::router()
|
let base = presentation::routes::router()
|
||||||
.merge(ap_router)
|
.merge(ap_router)
|
||||||
|
|||||||
@@ -19,4 +19,5 @@ pub struct AppState {
|
|||||||
pub auth: Arc<dyn AuthService>,
|
pub auth: Arc<dyn AuthService>,
|
||||||
pub hasher: Arc<dyn PasswordHasher>,
|
pub hasher: Arc<dyn PasswordHasher>,
|
||||||
pub events: Arc<dyn EventPublisher>,
|
pub events: Arc<dyn EventPublisher>,
|
||||||
|
pub federation: Arc<dyn FederationActionPort>,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user