serializer.rb 941 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # frozen_string_literal: true
  2. class NodeInfo::Serializer < ActiveModel::Serializer
  3. include RoutingHelper
  4. attributes :version, :software, :protocols, :services, :usage, :open_registrations, :metadata
  5. def version
  6. '2.0'
  7. end
  8. def software
  9. { name: 'mastodon', version: Mastodon::Version.to_s }
  10. end
  11. def services
  12. { outbound: [], inbound: [] }
  13. end
  14. def protocols
  15. %w(activitypub)
  16. end
  17. def usage
  18. {
  19. users: {
  20. total: instance_presenter.user_count,
  21. active_month: instance_presenter.active_user_count(4),
  22. active_halfyear: instance_presenter.active_user_count(24),
  23. },
  24. local_posts: instance_presenter.status_count,
  25. }
  26. end
  27. def open_registrations
  28. Setting.registrations_mode != 'none' && !Rails.configuration.x.single_user_mode
  29. end
  30. def metadata
  31. {}
  32. end
  33. private
  34. def instance_presenter
  35. @instance_presenter ||= InstancePresenter.new
  36. end
  37. end