instance_serializer.rb 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. has_one :contact_account, serializer: REST::AccountSerializer
  8. delegate :contact_account, to: :instance_presenter
  9. def uri
  10. Rails.configuration.x.local_domain
  11. end
  12. def title
  13. Setting.site_title
  14. end
  15. def short_description
  16. Setting.site_short_description
  17. end
  18. def description
  19. Setting.site_description
  20. end
  21. def email
  22. Setting.site_contact_email
  23. end
  24. def version
  25. Mastodon::Version.to_s
  26. end
  27. def thumbnail
  28. instance_presenter.thumbnail ? full_asset_url(instance_presenter.thumbnail.file.url) : full_pack_url('media/images/preview.jpg')
  29. end
  30. def stats
  31. {
  32. user_count: instance_presenter.user_count,
  33. status_count: instance_presenter.status_count,
  34. domain_count: instance_presenter.domain_count,
  35. }
  36. end
  37. def urls
  38. { streaming_api: Rails.configuration.x.streaming_api_base_url }
  39. end
  40. def languages
  41. [I18n.default_locale]
  42. end
  43. def registrations
  44. Setting.registrations_mode != 'none' && !Rails.configuration.x.single_user_mode
  45. end
  46. def approval_required
  47. Setting.registrations_mode == 'approved'
  48. end
  49. def invites_enabled
  50. Setting.min_invite_role == 'user'
  51. end
  52. private
  53. def instance_presenter
  54. @instance_presenter ||= InstancePresenter.new
  55. end
  56. end