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.

118 lines
2.8 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. :max_toot_chars, :poll_limits
  9. has_one :contact_account, serializer: REST::AccountSerializer
  10. has_many :rules, serializer: REST::RuleSerializer
  11. delegate :contact_account, :rules, to: :instance_presenter
  12. def uri
  13. Rails.configuration.x.local_domain
  14. end
  15. def title
  16. Setting.site_title
  17. end
  18. def short_description
  19. Setting.site_short_description
  20. end
  21. def description
  22. Setting.site_description
  23. end
  24. def email
  25. Setting.site_contact_email
  26. end
  27. def version
  28. Mastodon::Version.to_s
  29. end
  30. def thumbnail
  31. instance_presenter.thumbnail ? full_asset_url(instance_presenter.thumbnail.file.url) : full_pack_url('media/images/preview.jpg')
  32. end
  33. def stats
  34. {
  35. user_count: instance_presenter.user_count,
  36. status_count: instance_presenter.status_count,
  37. domain_count: instance_presenter.domain_count,
  38. }
  39. end
  40. def urls
  41. { streaming_api: Rails.configuration.x.streaming_api_base_url }
  42. end
  43. def configuration
  44. {
  45. statuses: {
  46. max_characters: StatusLengthValidator::MAX_CHARS,
  47. max_media_attachments: 4,
  48. characters_reserved_per_url: StatusLengthValidator::URL_PLACEHOLDER_CHARS,
  49. },
  50. media_attachments: {
  51. supported_mime_types: MediaAttachment::IMAGE_MIME_TYPES + MediaAttachment::VIDEO_MIME_TYPES + MediaAttachment::AUDIO_MIME_TYPES,
  52. image_size_limit: MediaAttachment::IMAGE_LIMIT,
  53. image_matrix_limit: Attachmentable::MAX_MATRIX_LIMIT,
  54. video_size_limit: MediaAttachment::VIDEO_LIMIT,
  55. video_frame_rate_limit: MediaAttachment::MAX_VIDEO_FRAME_RATE,
  56. video_matrix_limit: MediaAttachment::MAX_VIDEO_MATRIX_LIMIT,
  57. },
  58. polls: {
  59. max_options: PollValidator::MAX_OPTIONS,
  60. max_characters_per_option: PollValidator::MAX_OPTION_CHARS,
  61. min_expiration: PollValidator::MIN_EXPIRATION,
  62. max_expiration: PollValidator::MAX_EXPIRATION,
  63. },
  64. }
  65. end
  66. def languages
  67. [I18n.default_locale]
  68. end
  69. def registrations
  70. Setting.registrations_mode != 'none' && !Rails.configuration.x.single_user_mode
  71. end
  72. def approval_required
  73. Setting.registrations_mode == 'approved'
  74. end
  75. def invites_enabled
  76. Setting.min_invite_role == 'user'
  77. end
  78. def max_toot_chars
  79. 5000
  80. end
  81. def poll_limits
  82. {
  83. max_options: 10,
  84. max_expiration: 2592000,
  85. min_expiration: 300,
  86. max_option_chars: 50
  87. }
  88. end
  89. private
  90. def instance_presenter
  91. @instance_presenter ||= InstancePresenter.new
  92. end
  93. end