[#210] [TwitterAPI] Made actor be stored for uploads. Added ownership check
[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 alias Pleroma.Config
8 alias Pleroma.Web.ActivityPub.MRF
9
10 plug(Pleroma.Web.FederatingPlug)
11
12 def schemas(conn, _params) do
13 response = %{
14 links: [
15 %{
16 rel: "http://nodeinfo.diaspora.software/ns/schema/2.0",
17 href: Web.base_url() <> "/nodeinfo/2.0.json"
18 }
19 ]
20 }
21
22 json(conn, response)
23 end
24
25 # Schema definition: https://github.com/jhass/nodeinfo/blob/master/schemas/2.0/schema.json
26 def nodeinfo(conn, %{"version" => "2.0"}) do
27 instance = Application.get_env(:pleroma, :instance)
28 media_proxy = Application.get_env(:pleroma, :media_proxy)
29 suggestions = Application.get_env(:pleroma, :suggestions)
30 chat = Application.get_env(:pleroma, :chat)
31 gopher = Application.get_env(:pleroma, :gopher)
32 stats = Stats.get_stats()
33
34 mrf_simple =
35 Application.get_env(:pleroma, :mrf_simple)
36 |> Enum.into(%{})
37
38 mrf_policies =
39 MRF.get_policies()
40 |> Enum.map(fn policy -> to_string(policy) |> String.split(".") |> List.last() end)
41
42 quarantined = Keyword.get(instance, :quarantined_instances)
43
44 quarantined =
45 if is_list(quarantined) do
46 quarantined
47 else
48 []
49 end
50
51 staff_accounts =
52 User.moderator_user_query()
53 |> Repo.all()
54 |> Enum.map(fn u -> u.ap_id end)
55
56 mrf_user_allowlist =
57 Config.get([:mrf_user_allowlist], [])
58 |> Enum.into(%{}, fn {k, v} -> {k, length(v)} end)
59
60 mrf_transparency = Keyword.get(instance, :mrf_transparency)
61
62 federation_response =
63 if mrf_transparency do
64 %{
65 mrf_policies: mrf_policies,
66 mrf_simple: mrf_simple,
67 mrf_user_allowlist: mrf_user_allowlist,
68 quarantined_instances: quarantined
69 }
70 else
71 %{}
72 end
73
74 features = [
75 "pleroma_api",
76 "mastodon_api",
77 "mastodon_api_streaming",
78 if Keyword.get(media_proxy, :enabled) do
79 "media_proxy"
80 end,
81 if Keyword.get(gopher, :enabled) do
82 "gopher"
83 end,
84 if Keyword.get(chat, :enabled) do
85 "chat"
86 end,
87 if Keyword.get(suggestions, :enabled) do
88 "suggestions"
89 end
90 ]
91
92 response = %{
93 version: "2.0",
94 software: %{
95 name: Pleroma.Application.name(),
96 version: Pleroma.Application.version()
97 },
98 protocols: ["ostatus", "activitypub"],
99 services: %{
100 inbound: [],
101 outbound: []
102 },
103 openRegistrations: Keyword.get(instance, :registrations_open),
104 usage: %{
105 users: %{
106 total: stats.user_count || 0
107 },
108 localPosts: stats.status_count || 0
109 },
110 metadata: %{
111 nodeName: Keyword.get(instance, :name),
112 nodeDescription: Keyword.get(instance, :description),
113 private: !Keyword.get(instance, :public, true),
114 suggestions: %{
115 enabled: Keyword.get(suggestions, :enabled, false),
116 thirdPartyEngine: Keyword.get(suggestions, :third_party_engine, ""),
117 timeout: Keyword.get(suggestions, :timeout, 5000),
118 limit: Keyword.get(suggestions, :limit, 23),
119 web: Keyword.get(suggestions, :web, "")
120 },
121 staffAccounts: staff_accounts,
122 federation: federation_response,
123 postFormats: Keyword.get(instance, :allowed_post_formats),
124 uploadLimits: %{
125 general: Keyword.get(instance, :upload_limit),
126 avatar: Keyword.get(instance, :avatar_upload_limit),
127 banner: Keyword.get(instance, :banner_upload_limit),
128 background: Keyword.get(instance, :background_upload_limit)
129 },
130 features: features
131 }
132 }
133
134 conn
135 |> put_resp_header(
136 "content-type",
137 "application/json; profile=http://nodeinfo.diaspora.software/ns/schema/2.0#; charset=utf-8"
138 )
139 |> json(response)
140 end
141
142 def nodeinfo(conn, _) do
143 conn
144 |> put_status(404)
145 |> json(%{error: "Nodeinfo schema version not handled"})
146 end
147 end