Remove _misskey_reaction matching (#500)
[akkoma] / lib / pleroma / web / nodeinfo / nodeinfo_controller.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.Nodeinfo.NodeinfoController do
6 use Pleroma.Web, :controller
7
8 alias Pleroma.Config
9 alias Pleroma.Stats
10 alias Pleroma.User
11 alias Pleroma.Web.Federator.Publisher
12 alias Pleroma.Web.MastodonAPI.InstanceView
13 alias Pleroma.Web.Endpoint
14
15 def schemas(conn, _params) do
16 response = %{
17 links: [
18 %{
19 rel: "http://nodeinfo.diaspora.software/ns/schema/2.0",
20 href: Endpoint.url() <> "/nodeinfo/2.0.json"
21 },
22 %{
23 rel: "http://nodeinfo.diaspora.software/ns/schema/2.1",
24 href: Endpoint.url() <> "/nodeinfo/2.1.json"
25 }
26 ]
27 }
28
29 json(conn, response)
30 end
31
32 # returns a nodeinfo 2.0 map, since 2.1 just adds a repository field
33 # under software.
34 def raw_nodeinfo do
35 stats = Stats.get_stats()
36
37 staff_accounts =
38 User.all_superusers()
39 |> Enum.map(fn u -> u.ap_id end)
40 |> Enum.filter(fn u -> not Enum.member?(Config.get([:instance, :staff_transparency]), u) end)
41
42 features = InstanceView.features()
43 federation = InstanceView.federation()
44
45 %{
46 version: "2.0",
47 software: %{
48 name: Pleroma.Application.name() |> String.downcase(),
49 version: Pleroma.Application.version()
50 },
51 protocols: Publisher.gather_nodeinfo_protocol_names(),
52 services: %{
53 inbound: [],
54 outbound: []
55 },
56 openRegistrations: Config.get([:instance, :registrations_open]),
57 usage: %{
58 users: %{
59 total: Map.get(stats, :user_count, 0)
60 },
61 localPosts: Map.get(stats, :status_count, 0)
62 },
63 metadata: %{
64 nodeName: Config.get([:instance, :name]),
65 nodeDescription: Config.get([:instance, :description]),
66 private: !Config.get([:instance, :public], true),
67 suggestions: %{
68 enabled: false
69 },
70 staffAccounts: staff_accounts,
71 federation: federation,
72 pollLimits: Config.get([:instance, :poll_limits]),
73 postFormats: Config.get([:instance, :allowed_post_formats]),
74 uploadLimits: %{
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])
79 },
80 fieldsLimits: %{
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])
85 },
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),
89 features: features,
90 restrictedNicknames: Config.get([Pleroma.User, :restricted_nicknames]),
91 skipThreadContainment: Config.get([:instance, :skip_thread_containment], false),
92 localBubbleInstances: Config.get([:instance, :local_bubble], [])
93 }
94 }
95 end
96
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
100 conn
101 |> put_resp_header(
102 "content-type",
103 "application/json; profile=http://nodeinfo.diaspora.software/ns/schema/2.0#; charset=utf-8"
104 )
105 |> json(raw_nodeinfo())
106 end
107
108 def nodeinfo(conn, %{"version" => "2.1"}) do
109 raw_response = raw_nodeinfo()
110
111 updated_software =
112 raw_response
113 |> Map.get(:software)
114 |> Map.put(:repository, Pleroma.Application.repository())
115
116 response =
117 raw_response
118 |> Map.put(:software, updated_software)
119 |> Map.put(:version, "2.1")
120
121 conn
122 |> put_resp_header(
123 "content-type",
124 "application/json; profile=http://nodeinfo.diaspora.software/ns/schema/2.1#; charset=utf-8"
125 )
126 |> json(response)
127 end
128
129 def nodeinfo(conn, _) do
130 render_error(conn, :not_found, "Nodeinfo schema version not handled")
131 end
132 end