diff --git a/crates/presentation/Cargo.toml b/crates/presentation/Cargo.toml index 7ff52b9..b73bc14 100644 --- a/crates/presentation/Cargo.toml +++ b/crates/presentation/Cargo.toml @@ -17,8 +17,6 @@ uuid = { workspace = true } chrono = { workspace = true } tracing = { workspace = true } async-trait = { workspace = true } -sha2 = "0.10" -hex = "0.4" url = { workspace = true } utoipa = { version = "5.5.0", features = ["axum_extras", "uuid", "chrono"] } utoipa-scalar = { version = "0.3.0", features = ["axum"], default-features = false } diff --git a/crates/presentation/src/extractors.rs b/crates/presentation/src/extractors.rs index 55fc94d..7cc7de7 100644 --- a/crates/presentation/src/extractors.rs +++ b/crates/presentation/src/extractors.rs @@ -2,6 +2,27 @@ use crate::{errors::ApiError, state::AppState}; use axum::{extract::FromRequestParts, http::request::Parts}; use domain::value_objects::UserId; +// --------------------------------------------------------------------------- +// deps_struct! — generates Deps struct + impl FromAppState from a field list. +// Field names must match AppState exactly (enforced at compile time). +// --------------------------------------------------------------------------- + +#[macro_export] +macro_rules! deps_struct { + ( $name:ident { $( $field:ident : $trait:path ),+ $(,)? } ) => { + pub struct $name { + $( pub $field: ::std::sync::Arc, )+ + } + impl $crate::extractors::FromAppState for $name { + fn from_state(s: &$crate::state::AppState) -> Self { + Self { + $( $field: ::std::sync::Arc::clone(&s.$field), )+ + } + } + } + }; +} + // --------------------------------------------------------------------------- // Deps extractor — narrows AppState to a handler-specific deps struct // --------------------------------------------------------------------------- @@ -23,6 +44,10 @@ impl FromRequestParts for Deps { } } +// --------------------------------------------------------------------------- +// Auth extractors +// --------------------------------------------------------------------------- + pub struct AuthUser(pub UserId); pub struct OptionalAuthUser(pub Option); @@ -57,17 +82,12 @@ async fn extract_user_id(parts: &mut Parts, state: &AppState) -> Result String { - use sha2::{Digest, Sha256}; - let hash = Sha256::digest(s.as_bytes()); - hex::encode(hash) -} diff --git a/crates/presentation/src/state.rs b/crates/presentation/src/state.rs index 2ee7bfa..8fc0b20 100644 --- a/crates/presentation/src/state.rs +++ b/crates/presentation/src/state.rs @@ -12,6 +12,7 @@ pub struct AppState { pub blocks: Arc, pub tags: Arc, pub api_keys: Arc, + pub api_key_auth: Arc, pub top_friends: Arc, pub notifications: Arc, pub remote_actors: Arc, @@ -25,4 +26,5 @@ pub struct AppState { pub ap_repo: Arc, pub remote_actor_connections: Arc, pub federation_scheduler: Arc, + pub engagement: Arc, }