diff --git a/crates/tranquil-api/src/actor/preferences.rs b/crates/tranquil-api/src/actor/preferences.rs index d892f15..bfe19f3 100644 --- a/crates/tranquil-api/src/actor/preferences.rs +++ b/crates/tranquil-api/src/actor/preferences.rs @@ -12,7 +12,6 @@ use tranquil_pds::auth::{Auth, NotTakendown, Permissive}; use tranquil_pds::state::AppState; const APP_BSKY_NAMESPACE: &str = "app.bsky"; -const MAX_PREFERENCES_COUNT: usize = 100; const MAX_PREFERENCE_SIZE: usize = 10_000; const PERSONAL_DETAILS_PREF: &str = "app.bsky.actor.defs#personalDetailsPref"; const DECLARED_AGE_PREF: &str = "app.bsky.actor.defs#declaredAgePref"; @@ -92,6 +91,8 @@ pub async fn put_preferences( auth: Auth, Json(input): Json, ) -> Response { + let max_preferences_count: usize = tranquil_config::get().server.max_preferences_count; + let has_full_access = auth.permissions().has_full_access(); let user_id: uuid::Uuid = match state.repos.user.get_id_by_did(&auth.did).await { Ok(Some(id)) => id, @@ -99,11 +100,11 @@ pub async fn put_preferences( return ApiError::InternalError(Some("User not found".into())).into_response(); } }; - if input.preferences.len() > MAX_PREFERENCES_COUNT { + if input.preferences.len() > max_preferences_count { return ApiError::InvalidRequest(format!( "Too many preferences: {} exceeds limit of {}", input.preferences.len(), - MAX_PREFERENCES_COUNT + max_preferences_count )) .into_response(); } diff --git a/crates/tranquil-config/src/lib.rs b/crates/tranquil-config/src/lib.rs index 829325c..3849d79 100644 --- a/crates/tranquil-config/src/lib.rs +++ b/crates/tranquil-config/src/lib.rs @@ -451,6 +451,10 @@ pub struct ServerConfig { /// Maximum allowed blob size in bytes (default 10 GiB). #[config(env = "MAX_BLOB_SIZE", default = 10_737_418_240u64)] pub max_blob_size: u64, + + /// Maximum allowed number of preferences + #[config(env = "MAX_PREFERENCES_COUNT", default = 1000)] + pub max_preferences_count: usize, } impl ServerConfig { diff --git a/example.toml b/example.toml index a29d481..2a5d7b1 100644 --- a/example.toml +++ b/example.toml @@ -89,6 +89,13 @@ # Default value: 10737418240 #max_blob_size = 10737418240 +# Maximum allowed number of preferences +# +# Can also be specified via environment variable `MAX_PREFERENCES_COUNT`. +# +# Default value: 1000 +#max_preferences_count = 1000 + [frontend] # Whether to enable the built in serving of the frontend. #