nodeinfo_controller.ex 1.96 KB
Newer Older
dashie's avatar
dashie committed
1
2
3
4
5
6
7
8
9
10
11
defmodule Pleroma.Web.Nodeinfo.NodeinfoController do
  use Pleroma.Web, :controller

  alias Pleroma.Stats
  alias Pleroma.Web

  def schemas(conn, _params) do
    response = %{
      links: [
        %{
          rel: "http://nodeinfo.diaspora.software/ns/schema/2.0",
12
          href: Web.base_url() <> "/nodeinfo/2.0.json"
dashie's avatar
dashie committed
13
14
15
16
17
18
19
20
21
        }
      ]
    }

    json(conn, response)
  end

  # Schema definition: https://github.com/jhass/nodeinfo/blob/master/schemas/2.0/schema.json
  def nodeinfo(conn, %{"version" => "2.0"}) do
lain's avatar
lain committed
22
23
    instance = Application.get_env(:pleroma, :instance)
    media_proxy = Application.get_env(:pleroma, :media_proxy)
24
    suggestions = Application.get_env(:pleroma, :suggestions)
25
26
    stats = Stats.get_stats()

dashie's avatar
dashie committed
27
28
29
30
    response = %{
      version: "2.0",
      software: %{
        name: "pleroma",
lain's avatar
lain committed
31
        version: Keyword.get(instance, :version)
dashie's avatar
dashie committed
32
33
34
35
36
37
      },
      protocols: ["ostatus", "activitypub"],
      services: %{
        inbound: [],
        outbound: []
      },
lain's avatar
lain committed
38
      openRegistrations: Keyword.get(instance, :registrations_open),
dashie's avatar
dashie committed
39
40
      usage: %{
        users: %{
41
          total: stats.user_count || 0
42
        },
43
        localPosts: stats.status_count || 0
dashie's avatar
dashie committed
44
      },
dashie's avatar
dashie committed
45
      metadata: %{
lain's avatar
lain committed
46
        nodeName: Keyword.get(instance, :name),
47
        nodeDescription: Keyword.get(instance, :description),
48
        mediaProxy: Keyword.get(media_proxy, :enabled),
Hakaba Hitoyo's avatar
merge    
Hakaba Hitoyo committed
49
        private: !Keyword.get(instance, :public, true),
Hakaba Hitoyo's avatar
Hakaba Hitoyo committed
50
51
52
53
54
        suggestions: %{
          enabled: Keyword.get(suggestions, :enabled, false),
          thirdPartyEngine: Keyword.get(suggestions, :third_party_engine, ""),
          timeout: Keyword.get(suggestions, :timeout, 5000)
        }
dashie's avatar
dashie committed
55
      }
dashie's avatar
dashie committed
56
57
    }

58
59
60
61
62
63
    conn
    |> put_resp_header(
      "content-type",
      "application/json; profile=http://nodeinfo.diaspora.software/ns/schema/2.0#; charset=utf-8"
    )
    |> json(response)
dashie's avatar
dashie committed
64
65
66
67
68
  end

  def nodeinfo(conn, _) do
    conn
    |> put_status(404)
dashie's avatar
dashie committed
69
    |> json(%{error: "Nodeinfo schema version not handled"})
dashie's avatar
dashie committed
70
71
  end
end