You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
2.6 KiB

  1. # frozen_string_literal: true
  2. class REST::InstanceSerializer < ActiveModel::Serializer
  3. include RoutingHelper
  4. attributes :uri, :title, :short_description, :description, :email,
  5. :version, :urls, :stats, :thumbnail,
  6. :languages, :registrations, :approval_required, :invites_enabled,
  7. :configuration
  8. has_one :contact_account, serializer: REST::AccountSerializer
  9. has_many :rules, serializer: REST::RuleSerializer
  10. delegate :contact_account, :rules, to: :instance_presenter
  11. def uri
  12. Rails.configuration.x.local_domain
  13. end
  14. def title
  15. Setting.site_title
  16. end
  17. def short_description
  18. Setting.site_short_description
  19. end
  20. def description
  21. Setting.site_description
  22. end
  23. def email
  24. Setting.site_contact_email
  25. end
  26. def version
  27. Mastodon::Version.to_s
  28. end
  29. def thumbnail
  30. instance_presenter.thumbnail ? full_asset_url(instance_presenter.thumbnail.file.url) : full_pack_url('media/images/preview.jpg')
  31. end
  32. def stats
  33. {
  34. user_count: instance_presenter.user_count,
  35. status_count: instance_presenter.status_count,
  36. domain_count: instance_presenter.domain_count,
  37. }
  38. end
  39. def urls
  40. { streaming_api: Rails.configuration.x.streaming_api_base_url }
  41. end
  42. def configuration
  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. }
  64. end
  65. def languages
  66. [I18n.default_locale]
  67. end
  68. def registrations
  69. Setting.registrations_mode != 'none' && !Rails.configuration.x.single_user_mode
  70. end
  71. def approval_required
  72. Setting.registrations_mode == 'approved'
  73. end
  74. def invites_enabled
  75. Setting.min_invite_role == 'user'
  76. end
  77. private
  78. def instance_presenter
  79. @instance_presenter ||= InstancePresenter.new
  80. end
  81. end