instance_serializer.rb 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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')) : full_pack_url('media/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 usage
  39. {
  40. users: {
  41. active_month: instance_presenter.active_user_count(4),
  42. },
  43. }
  44. end
  45. def configuration
  46. {
  47. accounts: {
  48. max_featured_tags: FeaturedTag::LIMIT,
  49. },
  50. statuses: {
  51. max_characters: StatusLengthValidator::MAX_CHARS,
  52. max_media_attachments: 4,
  53. characters_reserved_per_url: StatusLengthValidator::URL_PLACEHOLDER_CHARS,
  54. },
  55. media_attachments: {
  56. supported_mime_types: MediaAttachment::IMAGE_MIME_TYPES + MediaAttachment::VIDEO_MIME_TYPES + MediaAttachment::AUDIO_MIME_TYPES,
  57. image_size_limit: MediaAttachment::IMAGE_LIMIT,
  58. image_matrix_limit: Attachmentable::MAX_MATRIX_LIMIT,
  59. video_size_limit: MediaAttachment::VIDEO_LIMIT,
  60. video_frame_rate_limit: MediaAttachment::MAX_VIDEO_FRAME_RATE,
  61. video_matrix_limit: MediaAttachment::MAX_VIDEO_MATRIX_LIMIT,
  62. },
  63. polls: {
  64. max_options: PollValidator::MAX_OPTIONS,
  65. max_characters_per_option: PollValidator::MAX_OPTION_CHARS,
  66. min_expiration: PollValidator::MIN_EXPIRATION,
  67. max_expiration: PollValidator::MAX_EXPIRATION,
  68. },
  69. }
  70. end
  71. def registrations
  72. Setting.registrations_mode != 'none' && !Rails.configuration.x.single_user_mode
  73. end
  74. def approval_required
  75. Setting.registrations_mode == 'approved'
  76. end
  77. def invites_enabled
  78. UserRole.everyone.can?(:invite_users)
  79. end
  80. private
  81. def instance_presenter
  82. @instance_presenter ||= InstancePresenter.new
  83. end
  84. end