report chat and gopher support at /nodeinfo/2.0.json
[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
7 def schemas(conn, _params) do
8 response = %{
9 links: [
10 %{
11 rel: "http://nodeinfo.diaspora.software/ns/schema/2.0",
12 href: Web.base_url() <> "/nodeinfo/2.0.json"
13 }
14 ]
15 }
16
17 json(conn, response)
18 end
19
20 # Schema definition: https://github.com/jhass/nodeinfo/blob/master/schemas/2.0/schema.json
21 def nodeinfo(conn, %{"version" => "2.0"}) do
22 instance = Application.get_env(:pleroma, :instance)
23 media_proxy = Application.get_env(:pleroma, :media_proxy)
24 suggestions = Application.get_env(:pleroma, :suggestions)
25 chat = Application.get_env(:pleroma, :chat)
26 gopher = Application.get_env(:pleroma, :gopher)
27 stats = Stats.get_stats()
28
29 response = %{
30 version: "2.0",
31 software: %{
32 name: "pleroma",
33 version: Keyword.get(instance, :version)
34 },
35 protocols: ["ostatus", "activitypub"],
36 services: %{
37 inbound: [],
38 outbound: []
39 },
40 openRegistrations: Keyword.get(instance, :registrations_open),
41 usage: %{
42 users: %{
43 total: stats.user_count || 0
44 },
45 localPosts: stats.status_count || 0
46 },
47 metadata: %{
48 nodeName: Keyword.get(instance, :name),
49 nodeDescription: Keyword.get(instance, :description),
50 mediaProxy: Keyword.get(media_proxy, :enabled),
51 private: !Keyword.get(instance, :public, true),
52 suggestions: %{
53 enabled: Keyword.get(suggestions, :enabled, false),
54 thirdPartyEngine: Keyword.get(suggestions, :third_party_engine, ""),
55 timeout: Keyword.get(suggestions, :timeout, 5000),
56 web: Keyword.get(suggestions, :web, "")
57 },
58 chat: Keyword.get(chat, :enabled),
59 gopher: Keyword.get(gopher, :enabled)
60 }
61 }
62
63 conn
64 |> put_resp_header(
65 "content-type",
66 "application/json; profile=http://nodeinfo.diaspora.software/ns/schema/2.0#; charset=utf-8"
67 )
68 |> json(response)
69 end
70
71 def nodeinfo(conn, _) do
72 conn
73 |> put_status(404)
74 |> json(%{error: "Nodeinfo schema version not handled"})
75 end
76 end