Merge branch 'main' into glitch-soc/merge-upstream
This commit is contained in:
@ -14,6 +14,7 @@ class REST::AccountSerializer < ActiveModel::Serializer
|
||||
|
||||
attribute :suspended, if: :suspended?
|
||||
attribute :silenced, key: :limited, if: :silenced?
|
||||
attribute :noindex, if: :local?
|
||||
|
||||
class FieldSerializer < ActiveModel::Serializer
|
||||
include FormattingHelper
|
||||
@ -107,7 +108,11 @@ class REST::AccountSerializer < ActiveModel::Serializer
|
||||
object.silenced?
|
||||
end
|
||||
|
||||
delegate :suspended?, :silenced?, to: :object
|
||||
def noindex
|
||||
object.user_prefers_noindex?
|
||||
end
|
||||
|
||||
delegate :suspended?, :silenced?, :local?, to: :object
|
||||
|
||||
def moved_and_not_nested?
|
||||
object.moved? && object.moved_to_account.moved_to_account_id.nil?
|
||||
|
17
app/serializers/rest/domain_block_serializer.rb
Normal file
17
app/serializers/rest/domain_block_serializer.rb
Normal file
@ -0,0 +1,17 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class REST::DomainBlockSerializer < ActiveModel::Serializer
|
||||
attributes :domain, :digest, :severity, :comment
|
||||
|
||||
def domain
|
||||
object.public_domain
|
||||
end
|
||||
|
||||
def digest
|
||||
object.domain_digest
|
||||
end
|
||||
|
||||
def comment
|
||||
object.public_comment if instance_options[:with_comment]
|
||||
end
|
||||
end
|
23
app/serializers/rest/extended_description_serializer.rb
Normal file
23
app/serializers/rest/extended_description_serializer.rb
Normal file
@ -0,0 +1,23 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class REST::ExtendedDescriptionSerializer < ActiveModel::Serializer
|
||||
attributes :updated_at, :content
|
||||
|
||||
def updated_at
|
||||
object.updated_at&.iso8601
|
||||
end
|
||||
|
||||
def content
|
||||
if object.text.present?
|
||||
markdown.render(object.text)
|
||||
else
|
||||
''
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def markdown
|
||||
@markdown ||= Redcarpet::Markdown.new(Redcarpet::Render::HTML)
|
||||
end
|
||||
end
|
@ -16,4 +16,12 @@ class REST::FeaturedTagSerializer < ActiveModel::Serializer
|
||||
def name
|
||||
object.display_name
|
||||
end
|
||||
|
||||
def statuses_count
|
||||
object.statuses_count.to_s
|
||||
end
|
||||
|
||||
def last_status_at
|
||||
object.last_status_at&.to_date&.iso8601
|
||||
end
|
||||
end
|
||||
|
@ -17,7 +17,20 @@ class REST::InstanceSerializer < ActiveModel::Serializer
|
||||
has_many :rules, serializer: REST::RuleSerializer
|
||||
|
||||
def thumbnail
|
||||
object.thumbnail ? full_asset_url(object.thumbnail.file.url) : full_pack_url('media/images/preview.png')
|
||||
if object.thumbnail
|
||||
{
|
||||
url: full_asset_url(object.thumbnail.file.url(:'@1x')),
|
||||
blurhash: object.thumbnail.blurhash,
|
||||
versions: {
|
||||
'@1x': full_asset_url(object.thumbnail.file.url(:'@1x')),
|
||||
'@2x': full_asset_url(object.thumbnail.file.url(:'@2x')),
|
||||
},
|
||||
}
|
||||
else
|
||||
{
|
||||
url: full_pack_url('media/images/preview.png'),
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def usage
|
||||
@ -34,6 +47,10 @@ class REST::InstanceSerializer < ActiveModel::Serializer
|
||||
streaming: Rails.configuration.x.streaming_api_base_url,
|
||||
},
|
||||
|
||||
accounts: {
|
||||
max_featured_tags: FeaturedTag::LIMIT,
|
||||
},
|
||||
|
||||
statuses: {
|
||||
max_characters: StatusLengthValidator::MAX_CHARS,
|
||||
max_media_attachments: 4,
|
||||
@ -55,13 +72,36 @@ class REST::InstanceSerializer < ActiveModel::Serializer
|
||||
min_expiration: PollValidator::MIN_EXPIRATION,
|
||||
max_expiration: PollValidator::MAX_EXPIRATION,
|
||||
},
|
||||
|
||||
translation: {
|
||||
enabled: TranslationService.configured?,
|
||||
},
|
||||
}
|
||||
end
|
||||
|
||||
def registrations
|
||||
{
|
||||
enabled: Setting.registrations_mode != 'none' && !Rails.configuration.x.single_user_mode,
|
||||
enabled: registrations_enabled?,
|
||||
approval_required: Setting.registrations_mode == 'approved',
|
||||
message: registrations_enabled? ? nil : registrations_message,
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def registrations_enabled?
|
||||
Setting.registrations_mode != 'none' && !Rails.configuration.x.single_user_mode
|
||||
end
|
||||
|
||||
def registrations_message
|
||||
if Setting.closed_registrations_message.present?
|
||||
markdown.render(Setting.closed_registrations_message)
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def markdown
|
||||
@markdown ||= Redcarpet::Markdown.new(Redcarpet::Render::HTML, no_images: true)
|
||||
end
|
||||
end
|
||||
|
19
app/serializers/rest/privacy_policy_serializer.rb
Normal file
19
app/serializers/rest/privacy_policy_serializer.rb
Normal file
@ -0,0 +1,19 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class REST::PrivacyPolicySerializer < ActiveModel::Serializer
|
||||
attributes :updated_at, :content
|
||||
|
||||
def updated_at
|
||||
object.updated_at.iso8601
|
||||
end
|
||||
|
||||
def content
|
||||
markdown.render(object.text % { domain: Rails.configuration.x.local_domain })
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def markdown
|
||||
@markdown ||= Redcarpet::Markdown.new(Redcarpet::Render::HTML, escape_html: true, no_images: true)
|
||||
end
|
||||
end
|
@ -1,7 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class REST::TranslationSerializer < ActiveModel::Serializer
|
||||
attributes :content, :detected_source_language
|
||||
attributes :content, :detected_source_language, :provider
|
||||
|
||||
def content
|
||||
object.text
|
||||
|
@ -33,7 +33,7 @@ class REST::V1::InstanceSerializer < ActiveModel::Serializer
|
||||
end
|
||||
|
||||
def thumbnail
|
||||
instance_presenter.thumbnail ? full_asset_url(instance_presenter.thumbnail.file.url) : full_pack_url('media/images/preview.png')
|
||||
instance_presenter.thumbnail ? full_asset_url(instance_presenter.thumbnail.file.url(:'@1x')) : full_pack_url('media/images/preview.png')
|
||||
end
|
||||
|
||||
def max_toot_chars
|
||||
@ -71,6 +71,10 @@ class REST::V1::InstanceSerializer < ActiveModel::Serializer
|
||||
|
||||
def configuration
|
||||
{
|
||||
accounts: {
|
||||
max_featured_tags: FeaturedTag::LIMIT,
|
||||
},
|
||||
|
||||
statuses: {
|
||||
max_characters: StatusLengthValidator::MAX_CHARS,
|
||||
max_media_attachments: 4,
|
||||
|
Reference in New Issue
Block a user