diff options
author | Claire <claire.github-309c@sitedethib.com> | 2022-10-28 11:36:25 +0200 |
---|---|---|
committer | Claire <claire.github-309c@sitedethib.com> | 2022-10-28 19:23:58 +0200 |
commit | cb19be67d1b47dd04cb5bb88e09f0101a614bd1c (patch) | |
tree | 6c85ccc6ac0279ae7b1ed4dff56c8e83f71a0c95 /app/serializers/rest | |
parent | 371563b0e249b6369e04709fb974a8e57413529f (diff) | |
parent | 8dfe5179ee7186e549dbe1186a151ffa848fe8ab (diff) |
Merge branch 'main' into glitch-soc/merge-upstream
Diffstat (limited to 'app/serializers/rest')
-rw-r--r-- | app/serializers/rest/account_serializer.rb | 7 | ||||
-rw-r--r-- | app/serializers/rest/domain_block_serializer.rb | 17 | ||||
-rw-r--r-- | app/serializers/rest/extended_description_serializer.rb | 23 | ||||
-rw-r--r-- | app/serializers/rest/featured_tag_serializer.rb | 8 | ||||
-rw-r--r-- | app/serializers/rest/instance_serializer.rb | 44 | ||||
-rw-r--r-- | app/serializers/rest/privacy_policy_serializer.rb | 19 | ||||
-rw-r--r-- | app/serializers/rest/translation_serializer.rb | 2 | ||||
-rw-r--r-- | app/serializers/rest/v1/instance_serializer.rb | 6 |
8 files changed, 121 insertions, 5 deletions
diff --git a/app/serializers/rest/account_serializer.rb b/app/serializers/rest/account_serializer.rb index e644a3f91..9a3ca75dc 100644 --- a/app/serializers/rest/account_serializer.rb +++ b/app/serializers/rest/account_serializer.rb @@ -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? diff --git a/app/serializers/rest/domain_block_serializer.rb b/app/serializers/rest/domain_block_serializer.rb new file mode 100644 index 000000000..678463e13 --- /dev/null +++ b/app/serializers/rest/domain_block_serializer.rb @@ -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 diff --git a/app/serializers/rest/extended_description_serializer.rb b/app/serializers/rest/extended_description_serializer.rb new file mode 100644 index 000000000..c0fa3450d --- /dev/null +++ b/app/serializers/rest/extended_description_serializer.rb @@ -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 diff --git a/app/serializers/rest/featured_tag_serializer.rb b/app/serializers/rest/featured_tag_serializer.rb index 8abcd9b90..c4b35ab03 100644 --- a/app/serializers/rest/featured_tag_serializer.rb +++ b/app/serializers/rest/featured_tag_serializer.rb @@ -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 diff --git a/app/serializers/rest/instance_serializer.rb b/app/serializers/rest/instance_serializer.rb index f4ea49427..5ae1099d0 100644 --- a/app/serializers/rest/instance_serializer.rb +++ b/app/serializers/rest/instance_serializer.rb @@ -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 diff --git a/app/serializers/rest/privacy_policy_serializer.rb b/app/serializers/rest/privacy_policy_serializer.rb new file mode 100644 index 000000000..f0572e714 --- /dev/null +++ b/app/serializers/rest/privacy_policy_serializer.rb @@ -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 diff --git a/app/serializers/rest/translation_serializer.rb b/app/serializers/rest/translation_serializer.rb index a06f23f32..05ededc95 100644 --- a/app/serializers/rest/translation_serializer.rb +++ b/app/serializers/rest/translation_serializer.rb @@ -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 diff --git a/app/serializers/rest/v1/instance_serializer.rb b/app/serializers/rest/v1/instance_serializer.rb index fefbed8ee..389ec7dff 100644 --- a/app/serializers/rest/v1/instance_serializer.rb +++ b/app/serializers/rest/v1/instance_serializer.rb @@ -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, |