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