|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +class NodeInfoSerializer < ActiveModel::Serializer |
| 4 | + include RoutingHelper |
| 5 | + |
| 6 | + attributes :version, :usage, :software, :services, |
| 7 | + :protocols, :openRegistrations, :metadata |
| 8 | + |
| 9 | + def version |
| 10 | + object.adapter.serializer.instance_options[:version] |
| 11 | + end |
| 12 | + |
| 13 | + def usage |
| 14 | + { |
| 15 | + users: { |
| 16 | + total: instance_presenter.user_count, |
| 17 | + activeHalfyear: instance_presenter.active_count(timespan: Time.zone.now - 6.months..Time.zone.now), |
| 18 | + activeMonth: instance_presenter.active_count, |
| 19 | + }, |
| 20 | + localPosts: instance_presenter.status_count, |
| 21 | + } |
| 22 | + end |
| 23 | + |
| 24 | + def software |
| 25 | + sw = { |
| 26 | + version: Mastodon::Version.to_s, |
| 27 | + name: 'mastodon' |
| 28 | + } |
| 29 | + sw[:repository] = Mastodon::Version.source_base_url if version == '2.1' |
| 30 | + sw |
| 31 | + end |
| 32 | + |
| 33 | + def services |
| 34 | + { |
| 35 | + outbound: [], |
| 36 | + inbound: [], |
| 37 | + } |
| 38 | + end |
| 39 | + |
| 40 | + def protocols |
| 41 | + %w(ostatus activitypub) |
| 42 | + end |
| 43 | + |
| 44 | + def openRegistrations |
| 45 | + Setting.open_registrations |
| 46 | + end |
| 47 | + |
| 48 | + def metadata |
| 49 | + { |
| 50 | + nodeName: instance_presenter.site_title, |
| 51 | + nodeDescription: instance_presenter.site_description, |
| 52 | + nodeTerms: instance_presenter.site_terms, |
| 53 | + siteContactEmail: instance_presenter.site_contact_email, |
| 54 | + domain_count: instance_presenter.domain_count, |
| 55 | + features: features, |
| 56 | + invitesEnabled: Setting.min_invite_role != 'admin', |
| 57 | + federation: federation, |
| 58 | + } |
| 59 | + end |
| 60 | + |
| 61 | + def features |
| 62 | + %w(mastodon_api mastodon_api_streaming) |
| 63 | + end |
| 64 | + |
| 65 | + def federation |
| 66 | + domains = DomainBlock.all |
| 67 | + feds = { |
| 68 | + reject_media: [], |
| 69 | + reject_reports: [], |
| 70 | + } |
| 71 | + domains.each do |domain| |
| 72 | + feds[domain.severity] = [] unless feds.keys.include?(domain.severity) |
| 73 | + feds[domain.severity] << domain.domain |
| 74 | + feds[:reject_media] << domain.domain if domain.reject_media |
| 75 | + feds[:reject_reports] << domain.domain if domain.reject_reports |
| 76 | + end |
| 77 | + feds |
| 78 | + end |
| 79 | + |
| 80 | + private |
| 81 | + |
| 82 | + def instance_presenter |
| 83 | + @instance_presenter ||= InstancePresenter.new |
| 84 | + end |
| 85 | +end |
0 commit comments