Change avatar and account header description limit and expose it in API (#38384)

This commit is contained in:
Claire
2026-03-25 13:32:47 +01:00
committed by GitHub
parent 45e7c7a5e1
commit 7583d07d3a
4 changed files with 14 additions and 3 deletions

View File

@@ -3,6 +3,7 @@
module Account::Avatar module Account::Avatar
extend ActiveSupport::Concern extend ActiveSupport::Concern
MAX_DESCRIPTION_LENGTH = 150
AVATAR_IMAGE_MIME_TYPES = ['image/jpeg', 'image/png', 'image/gif', 'image/webp'].freeze AVATAR_IMAGE_MIME_TYPES = ['image/jpeg', 'image/png', 'image/gif', 'image/webp'].freeze
AVATAR_LIMIT = 8.megabytes AVATAR_LIMIT = 8.megabytes
AVATAR_DIMENSIONS = [400, 400].freeze AVATAR_DIMENSIONS = [400, 400].freeze
@@ -25,7 +26,7 @@ module Account::Avatar
validates_attachment_size :avatar, less_than: AVATAR_LIMIT validates_attachment_size :avatar, less_than: AVATAR_LIMIT
remotable_attachment :avatar, AVATAR_LIMIT, suppress_errors: false remotable_attachment :avatar, AVATAR_LIMIT, suppress_errors: false
validates :avatar_description, length: { maximum: MediaAttachment::MAX_DESCRIPTION_LENGTH }, if: -> { local? && will_save_change_to_avatar_description? } validates :avatar_description, length: { maximum: MAX_DESCRIPTION_LENGTH }, if: -> { local? && will_save_change_to_avatar_description? }
end end
def avatar_original_url def avatar_original_url

View File

@@ -3,6 +3,7 @@
module Account::Header module Account::Header
extend ActiveSupport::Concern extend ActiveSupport::Concern
MAX_DESCRIPTION_LENGTH = 150
HEADER_IMAGE_MIME_TYPES = ['image/jpeg', 'image/png', 'image/gif', 'image/webp'].freeze HEADER_IMAGE_MIME_TYPES = ['image/jpeg', 'image/png', 'image/gif', 'image/webp'].freeze
HEADER_LIMIT = 8.megabytes HEADER_LIMIT = 8.megabytes
HEADER_DIMENSIONS = [1500, 500].freeze HEADER_DIMENSIONS = [1500, 500].freeze
@@ -26,7 +27,7 @@ module Account::Header
validates_attachment_size :header, less_than: HEADER_LIMIT validates_attachment_size :header, less_than: HEADER_LIMIT
remotable_attachment :header, HEADER_LIMIT, suppress_errors: false remotable_attachment :header, HEADER_LIMIT, suppress_errors: false
validates :header_description, length: { maximum: MediaAttachment::MAX_DESCRIPTION_LENGTH }, if: -> { local? && will_save_change_to_header_description? } validates :header_description, length: { maximum: MAX_DESCRIPTION_LENGTH }, if: -> { local? && will_save_change_to_header_description? }
end end
def header_original_url def header_original_url

View File

@@ -71,6 +71,8 @@ class REST::InstanceSerializer < ActiveModel::Serializer
accounts: { accounts: {
max_display_name_length: Account::DISPLAY_NAME_LENGTH_LIMIT, max_display_name_length: Account::DISPLAY_NAME_LENGTH_LIMIT,
max_note_length: Account::NOTE_LENGTH_LIMIT, max_note_length: Account::NOTE_LENGTH_LIMIT,
max_avatar_description_length: Account::Avatar::MAX_DESCRIPTION_LENGTH,
max_header_description_length: Account::Header::MAX_DESCRIPTION_LENGTH,
max_featured_tags: FeaturedTag::LIMIT, max_featured_tags: FeaturedTag::LIMIT,
max_pinned_statuses: StatusPinValidator::PIN_LIMIT, max_pinned_statuses: StatusPinValidator::PIN_LIMIT,
max_profile_fields: Account::DEFAULT_FIELDS_SIZE, max_profile_fields: Account::DEFAULT_FIELDS_SIZE,

View File

@@ -66,8 +66,15 @@ RSpec.describe 'Instances' do
include( include(
configuration: include( configuration: include(
accounts: include( accounts: include(
max_display_name_length: Account::DISPLAY_NAME_LENGTH_LIMIT,
max_note_length: Account::NOTE_LENGTH_LIMIT,
max_avatar_description_length: Account::Avatar::MAX_DESCRIPTION_LENGTH,
max_header_description_length: Account::Header::MAX_DESCRIPTION_LENGTH,
max_featured_tags: FeaturedTag::LIMIT, max_featured_tags: FeaturedTag::LIMIT,
max_pinned_statuses: StatusPinValidator::PIN_LIMIT max_pinned_statuses: StatusPinValidator::PIN_LIMIT,
max_profile_fields: Account::DEFAULT_FIELDS_SIZE,
profile_field_name_limit: Account::Field::MAX_CHARACTERS_LOCAL,
profile_field_value_limit: Account::Field::MAX_CHARACTERS_LOCAL
), ),
statuses: include( statuses: include(
max_characters: StatusLengthValidator::MAX_CHARS, max_characters: StatusLengthValidator::MAX_CHARS,