diff --git a/crates/presentation/src/context.rs b/crates/presentation/src/context.rs index cb2e549..759ff00 100644 --- a/crates/presentation/src/context.rs +++ b/crates/presentation/src/context.rs @@ -60,6 +60,8 @@ pub struct Services { pub document_parser: Arc, pub review_logger: Arc, pub person_enrichment: Option>, + #[cfg(feature = "federation")] + pub ap_service: Arc, } #[derive(Clone)] diff --git a/crates/presentation/src/handlers/social.rs b/crates/presentation/src/handlers/social.rs index 30720c3..237f513 100644 --- a/crates/presentation/src/handlers/social.rs +++ b/crates/presentation/src/handlers/social.rs @@ -83,7 +83,7 @@ pub async fn get_blocked_domains_admin( _admin: AdminApiUser, ) -> Result>, ApiError> { let domains = state - .ap_service + .app_ctx.services.ap_service .get_blocked_domains() .await .map_err(ap_to_domain)?; @@ -115,7 +115,7 @@ pub async fn add_blocked_domain_admin( axum::Json(body): axum::Json, ) -> Result { state - .ap_service + .app_ctx.services.ap_service .add_blocked_domain(&body.domain, body.reason.as_deref()) .await .map_err(ap_to_domain)?; @@ -138,7 +138,7 @@ pub async fn remove_blocked_domain_admin( axum::extract::Path(domain): axum::extract::Path, ) -> Result { state - .ap_service + .app_ctx.services.ap_service .remove_blocked_domain(&domain) .await .map_err(ap_to_domain)?; @@ -705,7 +705,7 @@ pub async fn get_followers_collection( if accept.contains("application/activity+json") || accept.contains("application/ld+json") { let page = params.get("page").and_then(|p| p.parse::().ok()); return match state - .ap_service + .app_ctx.services.ap_service .followers_collection_json(user_id, page) .await { @@ -736,7 +736,7 @@ pub async fn get_following_collection( if accept.contains("application/activity+json") || accept.contains("application/ld+json") { let page = params.get("page").and_then(|p| p.parse::().ok()); return match state - .ap_service + .app_ctx.services.ap_service .following_collection_json(user_id, page) .await { @@ -770,7 +770,7 @@ pub async fn get_following_page( "{}/users/{}/following-list", state.app_ctx.config.base_url, profile_user_uuid ); - match state.ap_service.get_following(user_id.value()).await { + match state.app_ctx.services.ap_service.get_following(user_id.value()).await { Ok(following) => { let actors: Vec = following .into_iter() @@ -817,7 +817,7 @@ pub async fn get_followers_page( state.app_ctx.config.base_url, profile_user_uuid ); match state - .ap_service + .app_ctx.services.ap_service .get_accepted_followers(user_id.value()) .await { @@ -899,7 +899,7 @@ pub async fn get_blocked_domains_page( let mut ctx = build_page_context(&state, Some(user_id), csrf.0).await; ctx.page_title = "Blocked Domains — Movies Diary".to_string(); ctx.canonical_url = format!("{}/admin/blocked-domains", state.app_ctx.config.base_url); - match state.ap_service.get_blocked_domains().await { + match state.app_ctx.services.ap_service.get_blocked_domains().await { Ok(domains) => { let entries: Vec = domains .into_iter() @@ -937,7 +937,7 @@ pub async fn post_blocked_domain( } let reason = form.reason.as_deref().filter(|s| !s.trim().is_empty()); match state - .ap_service + .app_ctx.services.ap_service .add_blocked_domain(&form.domain, reason) .await { @@ -958,7 +958,7 @@ pub async fn post_remove_blocked_domain( if crate::csrf::mismatch(&csrf, &form.csrf_token) { return StatusCode::FORBIDDEN.into_response(); } - match state.ap_service.remove_blocked_domain(&form.domain).await { + match state.app_ctx.services.ap_service.remove_blocked_domain(&form.domain).await { Ok(()) => Redirect::to("/admin/blocked-domains").into_response(), Err(e) => { tracing::error!("remove_blocked_domain error: {:?}", e); @@ -975,7 +975,7 @@ pub async fn get_blocked_actors_page( let mut ctx = build_page_context(&state, Some(user_id.clone()), csrf.0).await; ctx.page_title = "Blocked Users — Movies Diary".to_string(); ctx.canonical_url = format!("{}/social/blocked", state.app_ctx.config.base_url); - match state.ap_service.get_blocked_actors(user_id.value()).await { + match state.app_ctx.services.ap_service.get_blocked_actors(user_id.value()).await { Ok(actors) => { let entries: Vec = actors .into_iter() diff --git a/crates/presentation/src/handlers/users.rs b/crates/presentation/src/handlers/users.rs index 6d701a9..b62af9f 100644 --- a/crates/presentation/src/handlers/users.rs +++ b/crates/presentation/src/handlers/users.rs @@ -647,6 +647,8 @@ pub async fn get_user_profile_html( .unwrap_or(""); if accept.contains("application/activity+json") || accept.contains("application/ld+json") { return match state + .app_ctx + .services .ap_service .actor_json(&profile_user_uuid.to_string()) .await diff --git a/crates/presentation/src/main.rs b/crates/presentation/src/main.rs index 1c03d93..d326894 100644 --- a/crates/presentation/src/main.rs +++ b/crates/presentation/src/main.rs @@ -215,6 +215,8 @@ async fn wire_dependencies() -> anyhow::Result<(AppState, axum::Router)> { document_parser: Arc::new(ImporterDocumentParser) as Arc, review_logger, person_enrichment: None, + #[cfg(feature = "federation")] + ap_service, }, config: app_config, }; @@ -224,8 +226,6 @@ async fn wire_dependencies() -> anyhow::Result<(AppState, axum::Router)> { rss_renderer: Arc::new(RssAdapter::new( std::env::var("BASE_URL").unwrap_or_else(|_| "http://localhost:3000".into()), )), - #[cfg(feature = "federation")] - ap_service, }; Ok((state, ap_router)) } diff --git a/crates/presentation/src/state.rs b/crates/presentation/src/state.rs index 9c470e8..4e6c8bc 100644 --- a/crates/presentation/src/state.rs +++ b/crates/presentation/src/state.rs @@ -8,6 +8,4 @@ use domain::ports::RssFeedRenderer; pub struct AppState { pub app_ctx: AppContext, pub rss_renderer: Arc, - #[cfg(feature = "federation")] - pub ap_service: Arc, } diff --git a/crates/presentation/src/tests/extractors.rs b/crates/presentation/src/tests/extractors.rs index 82355d2..6501245 100644 --- a/crates/presentation/src/tests/extractors.rs +++ b/crates/presentation/src/tests/extractors.rs @@ -834,6 +834,8 @@ pub fn make_test_state(auth_service: Arc) -> crate::state::AppS document_parser: Arc::clone(&repo) as _, review_logger: Arc::clone(&repo) as _, person_enrichment: None, + #[cfg(feature = "federation")] + ap_service: Arc::new(activitypub::NoopActivityPubService), }, config: AppConfig { allow_registration: false, @@ -848,8 +850,6 @@ pub fn make_test_state(auth_service: Arc) -> crate::state::AppS }, }, rss_renderer: Arc::new(Panic), - #[cfg(feature = "federation")] - ap_service: Arc::new(activitypub::NoopActivityPubService), } } diff --git a/crates/presentation/tests/api_test.rs b/crates/presentation/tests/api_test.rs index b3ffc27..696deea 100644 --- a/crates/presentation/tests/api_test.rs +++ b/crates/presentation/tests/api_test.rs @@ -487,6 +487,8 @@ async fn test_app() -> Router { document_parser: Arc::new(PanicDocumentParser), review_logger: Arc::new(PanicReviewLogger), person_enrichment: None, + #[cfg(feature = "federation")] + ap_service: Arc::new(activitypub::NoopActivityPubService), }, config: AppConfig { allow_registration: false, @@ -501,8 +503,6 @@ async fn test_app() -> Router { }, }, rss_renderer: Arc::new(RssAdapter::new("http://localhost:3000".into())), - #[cfg(feature = "federation")] - ap_service: Arc::new(activitypub::NoopActivityPubService), }; routes::build_router(state, axum::Router::new())