1
0

instance_serializer.rb 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. # frozen_string_literal: true
  2. class REST::InstanceSerializer < ActiveModel::Serializer
  3. class ContactSerializer < ActiveModel::Serializer
  4. attributes :email
  5. has_one :account, serializer: REST::AccountSerializer
  6. end
  7. include RoutingHelper
  8. attributes :domain, :title, :version, :source_url, :description,
  9. :usage, :thumbnail, :languages, :configuration,
  10. :registrations
  11. has_one :contact, serializer: ContactSerializer
  12. has_many :rules, serializer: REST::RuleSerializer
  13. def thumbnail
  14. if object.thumbnail
  15. {
  16. url: full_asset_url(object.thumbnail.file.url(:'@1x')),
  17. blurhash: object.thumbnail.blurhash,
  18. versions: {
  19. '@1x': full_asset_url(object.thumbnail.file.url(:'@1x')),
  20. '@2x': full_asset_url(object.thumbnail.file.url(:'@2x')),
  21. },
  22. }
  23. else
  24. {
  25. url: full_pack_url('media/images/preview.png'),
  26. }
  27. end
  28. end
  29. def usage
  30. {
  31. users: {
  32. active_month: object.active_user_count(4),
  33. },
  34. }
  35. end
  36. def configuration
  37. {
  38. urls: {
  39. streaming: Rails.configuration.x.streaming_api_base_url,
  40. },
  41. accounts: {
  42. max_featured_tags: FeaturedTag::LIMIT,
  43. },
  44. statuses: {
  45. max_characters: StatusLengthValidator::MAX_CHARS,
  46. max_media_attachments: 4,
  47. characters_reserved_per_url: StatusLengthValidator::URL_PLACEHOLDER_CHARS,
  48. },
  49. media_attachments: {
  50. supported_mime_types: MediaAttachment::IMAGE_MIME_TYPES + MediaAttachment::VIDEO_MIME_TYPES + MediaAttachment::AUDIO_MIME_TYPES,
  51. image_size_limit: MediaAttachment::IMAGE_LIMIT,
  52. image_matrix_limit: Attachmentable::MAX_MATRIX_LIMIT,
  53. video_size_limit: MediaAttachment::VIDEO_LIMIT,
  54. video_frame_rate_limit: MediaAttachment::MAX_VIDEO_FRAME_RATE,
  55. video_matrix_limit: MediaAttachment::MAX_VIDEO_MATRIX_LIMIT,
  56. },
  57. polls: {
  58. max_options: PollValidator::MAX_OPTIONS,
  59. max_characters_per_option: PollValidator::MAX_OPTION_CHARS,
  60. min_expiration: PollValidator::MIN_EXPIRATION,
  61. max_expiration: PollValidator::MAX_EXPIRATION,
  62. },
  63. translation: {
  64. enabled: TranslationService.configured?,
  65. },
  66. }
  67. end
  68. def registrations
  69. {
  70. enabled: registrations_enabled?,
  71. approval_required: Setting.registrations_mode == 'approved',
  72. message: registrations_enabled? ? nil : registrations_message,
  73. }
  74. end
  75. private
  76. def registrations_enabled?
  77. Setting.registrations_mode != 'none' && !Rails.configuration.x.single_user_mode
  78. end
  79. def registrations_message
  80. if Setting.closed_registrations_message.present?
  81. markdown.render(Setting.closed_registrations_message)
  82. else
  83. nil
  84. end
  85. end
  86. def markdown
  87. @markdown ||= Redcarpet::Markdown.new(Redcarpet::Render::HTML, no_images: true)
  88. end
  89. end