bf845a4424e32e4fe628abff0a7826851f4ac464
[akkoma] / lib / pleroma / web / nodeinfo / nodeinfo_controller.ex
1 defmodule Pleroma.Web.Nodeinfo.NodeinfoController do
2 use Pleroma.Web, :controller
3
4 alias Pleroma.Web.Nodeinfo
5 alias Pleroma.Stats
6 alias Pleroma.Web
7
8 @instance Application.get_env(:pleroma, :instance)
9
10 def schemas(conn, _params) do
11 response = %{
12 links: [
13 %{
14 rel: "http://nodeinfo.diaspora.software/ns/schema/2.0",
15 href: Web.base_url() <> "/nodeinfo/2.0.json"
16 }
17 ]
18 }
19
20 json(conn, response)
21 end
22
23 # Schema definition: https://github.com/jhass/nodeinfo/blob/master/schemas/2.0/schema.json
24 def nodeinfo(conn, %{"version" => "2.0"}) do
25 response = %{
26 version: "2.0",
27 software: %{
28 name: "pleroma",
29 version: Keyword.get(@instance, :version)
30 },
31 protocols: ["ostatus", "activitypub"],
32 services: %{
33 inbound: [],
34 outbound: []
35 },
36 openRegistrations: Keyword.get(@instance, :registrations_open),
37 usage: %{
38 users: %{
39 total: Stats.get_stats().user_count || 0
40 },
41 localPosts: Stats.get_stats().status_count || 0
42 },
43 metadata: %{}
44 }
45
46 json(conn, response)
47 end
48
49 def nodeinfo(conn, _) do
50 conn
51 |> put_status(404)
52 |> json(%{error: "Nodeinfo schema version not handled"})
53 end
54 end