闭社主体 forked from https://github.com/tootsuite/mastodon
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.

59 lines
1.1 KiB

  1. # frozen_string_literal: true
  2. class REST::InstanceSerializer < ActiveModel::Serializer
  3. include RoutingHelper
  4. attributes :uri, :title, :description, :email,
  5. :version, :urls, :stats, :thumbnail,
  6. :languages
  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 description
  16. Setting.site_description
  17. end
  18. def email
  19. Setting.site_contact_email
  20. end
  21. def version
  22. Mastodon::Version.to_s
  23. end
  24. def thumbnail
  25. instance_presenter.thumbnail ? full_asset_url(instance_presenter.thumbnail.file.url) : full_pack_url('preview.jpg')
  26. end
  27. def stats
  28. {
  29. user_count: instance_presenter.user_count,
  30. status_count: instance_presenter.status_count,
  31. domain_count: instance_presenter.domain_count,
  32. }
  33. end
  34. def urls
  35. { streaming_api: Rails.configuration.x.streaming_api_base_url }
  36. end
  37. def languages
  38. [I18n.default_locale]
  39. end
  40. private
  41. def instance_presenter
  42. @instance_presenter ||= InstancePresenter.new
  43. end
  44. end