1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.Nodeinfo.NodeinfoController do
6 use Pleroma.Web, :controller
11 alias Pleroma.Web.Federator.Publisher
12 alias Pleroma.Web.MastodonAPI.InstanceView
13 alias Pleroma.Web.Endpoint
15 def schemas(conn, _params) do
19 rel: "http://nodeinfo.diaspora.software/ns/schema/2.0",
20 href: Endpoint.url() <> "/nodeinfo/2.0.json"
23 rel: "http://nodeinfo.diaspora.software/ns/schema/2.1",
24 href: Endpoint.url() <> "/nodeinfo/2.1.json"
32 # returns a nodeinfo 2.0 map, since 2.1 just adds a repository field
35 stats = Stats.get_stats()
39 |> Enum.map(fn u -> u.ap_id end)
40 |> Enum.filter(fn u -> not Enum.member?(Config.get([:instance, :staff_transparency]), u) end)
42 features = InstanceView.features()
43 federation = InstanceView.federation()
48 name: Pleroma.Application.name() |> String.downcase(),
49 version: Pleroma.Application.version()
51 protocols: Publisher.gather_nodeinfo_protocol_names(),
56 openRegistrations: Config.get([:instance, :registrations_open]),
59 total: Map.get(stats, :user_count, 0)
61 localPosts: Map.get(stats, :status_count, 0)
64 nodeName: Config.get([:instance, :name]),
65 nodeDescription: Config.get([:instance, :description]),
66 private: !Config.get([:instance, :public], true),
70 staffAccounts: staff_accounts,
71 federation: federation,
72 pollLimits: Config.get([:instance, :poll_limits]),
73 postFormats: Config.get([:instance, :allowed_post_formats]),
75 general: Config.get([:instance, :upload_limit]),
76 avatar: Config.get([:instance, :avatar_upload_limit]),
77 banner: Config.get([:instance, :banner_upload_limit]),
78 background: Config.get([:instance, :background_upload_limit])
81 maxFields: Config.get([:instance, :max_account_fields]),
82 maxRemoteFields: Config.get([:instance, :max_remote_account_fields]),
83 nameLength: Config.get([:instance, :account_field_name_length]),
84 valueLength: Config.get([:instance, :account_field_value_length])
86 accountActivationRequired: Config.get([:instance, :account_activation_required], false),
87 invitesEnabled: Config.get([:instance, :invites_enabled], false),
88 mailerEnabled: Config.get([Pleroma.Emails.Mailer, :enabled], false),
90 restrictedNicknames: Config.get([Pleroma.User, :restricted_nicknames]),
91 skipThreadContainment: Config.get([:instance, :skip_thread_containment], false),
92 localBubbleInstances: Config.get([:instance, :local_bubble], [])
97 # Schema definition: https://github.com/jhass/nodeinfo/blob/master/schemas/2.0/schema.json
98 # and https://github.com/jhass/nodeinfo/blob/master/schemas/2.1/schema.json
99 def nodeinfo(conn, %{"version" => "2.0"}) do
103 "application/json; profile=http://nodeinfo.diaspora.software/ns/schema/2.0#; charset=utf-8"
105 |> json(raw_nodeinfo())
108 def nodeinfo(conn, %{"version" => "2.1"}) do
109 raw_response = raw_nodeinfo()
113 |> Map.get(:software)
114 |> Map.put(:repository, Pleroma.Application.repository())
118 |> Map.put(:software, updated_software)
119 |> Map.put(:version, "2.1")
124 "application/json; profile=http://nodeinfo.diaspora.software/ns/schema/2.1#; charset=utf-8"
129 def nodeinfo(conn, _) do
130 render_error(conn, :not_found, "Nodeinfo schema version not handled")