refactor: dedup JSONB name/value helpers, add profile fields validation
Some checks failed
lint / lint (push) Failing after 9m29s
test / unit (push) Has been cancelled

Extract parse/serialize into postgres::jsonb, used by user,
remote_actor, and postgres-federation. Validate profile fields
in update_profile use case (max 4, name≤64, value≤256).
This commit is contained in:
2026-05-29 13:59:39 +02:00
parent 805bd9534f
commit 020a79704f
5 changed files with 46 additions and 45 deletions

View File

@@ -1,4 +1,7 @@
const MAX_TOP_FRIENDS: usize = 8;
const MAX_PROFILE_FIELDS: usize = 4;
const MAX_FIELD_NAME_LEN: usize = 64;
const MAX_FIELD_VALUE_LEN: usize = 256;
use bytes::Bytes;
use domain::{
@@ -55,6 +58,20 @@ pub async fn update_profile(
user_id: &UserId,
input: UpdateProfileInput,
) -> Result<(), DomainError> {
if let Some(ref fields) = input.profile_fields {
if fields.len() > MAX_PROFILE_FIELDS {
return Err(DomainError::InvalidInput(format!(
"profile fields: max {MAX_PROFILE_FIELDS}"
)));
}
for (name, value) in fields {
if name.len() > MAX_FIELD_NAME_LEN || value.len() > MAX_FIELD_VALUE_LEN {
return Err(DomainError::InvalidInput(
"profile field name or value too long".into(),
));
}
}
}
users.update_profile(user_id, input).await?;
events
.publish(&DomainEvent::ProfileUpdated {