mirror of
https://tangled.org/tranquil.farm/tranquil-pds
synced 2026-04-24 18:30:31 +00:00
feat: allow max prefs to be configured
some people (me) have a large amount of prefs and moving from ref pds to tranquil ment i lost a few of these. so in this pr i bumped the max prefs to 1000 and made it configurable via the config
This commit is contained in:
@@ -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<NotTakendown>,
|
||||
Json(input): Json<PutPreferencesInput>,
|
||||
) -> 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();
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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.
|
||||
#
|
||||
|
||||
Reference in New Issue
Block a user