instance_serializer.rb 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. # frozen_string_literal: true
  2. class REST::V1::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. def uri
  11. object.domain
  12. end
  13. def short_description
  14. object.description
  15. end
  16. def description
  17. Setting.site_description # Legacy
  18. end
  19. def email
  20. object.contact.email
  21. end
  22. def contact_account
  23. object.contact.account
  24. end
  25. def thumbnail
  26. instance_presenter.thumbnail ? full_asset_url(instance_presenter.thumbnail.file.url(:'@1x')) : frontend_asset_url('images/preview.png')
  27. end
  28. def stats
  29. {
  30. user_count: instance_presenter.user_count,
  31. status_count: instance_presenter.status_count,
  32. domain_count: instance_presenter.domain_count,
  33. }
  34. end
  35. def urls
  36. { streaming_api: Rails.configuration.x.streaming_api_base_url }
  37. end
  38. def configuration
  39. {
  40. accounts: {
  41. max_featured_tags: FeaturedTag::LIMIT,
  42. },
  43. statuses: {
  44. max_characters: StatusLengthValidator::MAX_CHARS,
  45. max_media_attachments: Status::MEDIA_ATTACHMENTS_LIMIT,
  46. characters_reserved_per_url: StatusLengthValidator::URL_PLACEHOLDER_CHARS,
  47. },
  48. media_attachments: {
  49. supported_mime_types: MediaAttachment.supported_mime_types,
  50. image_size_limit: MediaAttachment::IMAGE_LIMIT,
  51. image_matrix_limit: Attachmentable::MAX_MATRIX_LIMIT,
  52. video_size_limit: MediaAttachment::VIDEO_LIMIT,
  53. video_frame_rate_limit: MediaAttachment::MAX_VIDEO_FRAME_RATE,
  54. video_matrix_limit: MediaAttachment::MAX_VIDEO_MATRIX_LIMIT,
  55. },
  56. polls: {
  57. max_options: PollValidator::MAX_OPTIONS,
  58. max_characters_per_option: PollValidator::MAX_OPTION_CHARS,
  59. min_expiration: PollValidator::MIN_EXPIRATION,
  60. max_expiration: PollValidator::MAX_EXPIRATION,
  61. },
  62. }
  63. end
  64. def registrations
  65. Setting.registrations_mode != 'none' && !Rails.configuration.x.single_user_mode
  66. end
  67. def approval_required
  68. Setting.registrations_mode == 'approved'
  69. end
  70. def invites_enabled
  71. UserRole.everyone.can?(:invite_users)
  72. end
  73. private
  74. def instance_presenter
  75. @instance_presenter ||= InstancePresenter.new
  76. end
  77. end