Pleroma.Web.Nodeinfo.NodeinfoController: Further transparency, breaks API of previous one
[akkoma] / lib / pleroma / web / nodeinfo / nodeinfo_controller.ex
1 defmodule Pleroma.Web.Nodeinfo.NodeinfoController do
2 use Pleroma.Web, :controller
3
4 alias Pleroma.Stats
5 alias Pleroma.Web
6 alias Pleroma.{User, Repo}
7
8 def schemas(conn, _params) do
9 response = %{
10 links: [
11 %{
12 rel: "http://nodeinfo.diaspora.software/ns/schema/2.0",
13 href: Web.base_url() <> "/nodeinfo/2.0.json"
14 }
15 ]
16 }
17
18 json(conn, response)
19 end
20
21 # Schema definition: https://github.com/jhass/nodeinfo/blob/master/schemas/2.0/schema.json
22 def nodeinfo(conn, %{"version" => "2.0"}) do
23 instance = Application.get_env(:pleroma, :instance)
24 media_proxy = Application.get_env(:pleroma, :media_proxy)
25 suggestions = Application.get_env(:pleroma, :suggestions)
26 chat = Application.get_env(:pleroma, :chat)
27 gopher = Application.get_env(:pleroma, :gopher)
28 stats = Stats.get_stats()
29 mrf_simple = Application.get_env(:pleroma, :mrf_simple)
30
31 mrf_policies =
32 if(is_list(instance.rewrite_policy)) do
33 instance.rewrite_policy
34 else
35 [instance.rewrite_policy]
36 end
37
38 staff_accounts =
39 User.moderator_user_query()
40 |> Repo.all()
41 |> Enum.map(fn u -> u.ap_id end)
42
43 response = %{
44 version: "2.0",
45 software: %{
46 name: "pleroma",
47 version: Keyword.get(instance, :version)
48 },
49 protocols: ["ostatus", "activitypub"],
50 services: %{
51 inbound: [],
52 outbound: []
53 },
54 openRegistrations: Keyword.get(instance, :registrations_open),
55 usage: %{
56 users: %{
57 total: stats.user_count || 0
58 },
59 localPosts: stats.status_count || 0
60 },
61 metadata: %{
62 nodeName: Keyword.get(instance, :name),
63 nodeDescription: Keyword.get(instance, :description),
64 mediaProxy: Keyword.get(media_proxy, :enabled),
65 private: !Keyword.get(instance, :public, true),
66 suggestions: %{
67 enabled: Keyword.get(suggestions, :enabled, false),
68 thirdPartyEngine: Keyword.get(suggestions, :third_party_engine, ""),
69 timeout: Keyword.get(suggestions, :timeout, 5000),
70 limit: Keyword.get(suggestions, :limit, 23),
71 web: Keyword.get(suggestions, :web, "")
72 },
73 staffAccounts: staff_accounts,
74 chat: Keyword.get(chat, :enabled),
75 gopher: Keyword.get(gopher, :enabled),
76 federation: %{
77 mrf_policies: mrf_policies,
78 mrf_simple: mrf_simple,
79 quarantined_instances: instance.quarantined_instances
80 }
81 }
82 }
83
84 conn
85 |> put_resp_header(
86 "content-type",
87 "application/json; profile=http://nodeinfo.diaspora.software/ns/schema/2.0#; charset=utf-8"
88 )
89 |> json(response)
90 end
91
92 def nodeinfo(conn, _) do
93 conn
94 |> put_status(404)
95 |> json(%{error: "Nodeinfo schema version not handled"})
96 end
97 end