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