d95addb0b3361e4a9ed94f80f09555b9e29b81fe
[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 stats = Stats.get_stats()
27
28 staff_accounts =
29 User.moderator_user_query()
30 |> Repo.all()
31 |> Enum.map(fn u -> u.ap_id end)
32
33 response = %{
34 version: "2.0",
35 software: %{
36 name: "pleroma",
37 version: Keyword.get(instance, :version)
38 },
39 protocols: ["ostatus", "activitypub"],
40 services: %{
41 inbound: [],
42 outbound: []
43 },
44 openRegistrations: Keyword.get(instance, :registrations_open),
45 usage: %{
46 users: %{
47 total: stats.user_count || 0
48 },
49 localPosts: stats.status_count || 0
50 },
51 metadata: %{
52 nodeName: Keyword.get(instance, :name),
53 nodeDescription: Keyword.get(instance, :description),
54 mediaProxy: Keyword.get(media_proxy, :enabled),
55 private: !Keyword.get(instance, :public, true),
56 suggestions: %{
57 enabled: Keyword.get(suggestions, :enabled, false),
58 thirdPartyEngine: Keyword.get(suggestions, :third_party_engine, ""),
59 timeout: Keyword.get(suggestions, :timeout, 5000),
60 web: Keyword.get(suggestions, :web, "")
61 },
62 staffAccounts: staff_accounts
63 }
64 }
65
66 conn
67 |> put_resp_header(
68 "content-type",
69 "application/json; profile=http://nodeinfo.diaspora.software/ns/schema/2.0#; charset=utf-8"
70 )
71 |> json(response)
72 end
73
74 def nodeinfo(conn, _) do
75 conn
76 |> put_status(404)
77 |> json(%{error: "Nodeinfo schema version not handled"})
78 end
79 end