ec7d150a97848603303d16ecee3950bd1d3c22ac
[akkoma] / lib / pleroma / web / mastodon_api / views / instance_view.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.MastodonAPI.InstanceView do
6 use Pleroma.Web, :view
7
8 alias Pleroma.Config
9 alias Pleroma.Web.ActivityPub.MRF
10
11 @mastodon_api_level "2.7.2"
12
13 def render("show.json", _) do
14 instance = Config.get(:instance)
15
16 %{
17 uri: Pleroma.Web.Endpoint.url(),
18 title: Keyword.get(instance, :name),
19 description: Keyword.get(instance, :description),
20 version: "#{@mastodon_api_level} (compatible; #{Pleroma.Application.named_version()})",
21 email: Keyword.get(instance, :email),
22 urls: %{
23 streaming_api: Pleroma.Web.Endpoint.websocket_url()
24 },
25 stats: Pleroma.Stats.get_stats(),
26 thumbnail:
27 URI.merge(Pleroma.Web.Endpoint.url(), Keyword.get(instance, :instance_thumbnail))
28 |> to_string,
29 languages: ["en"],
30 registrations: Keyword.get(instance, :registrations_open),
31 approval_required: Keyword.get(instance, :account_approval_required),
32 # Extra (not present in Mastodon):
33 max_toot_chars: Keyword.get(instance, :limit),
34 poll_limits: Keyword.get(instance, :poll_limits),
35 upload_limit: Keyword.get(instance, :upload_limit),
36 avatar_upload_limit: Keyword.get(instance, :avatar_upload_limit),
37 background_upload_limit: Keyword.get(instance, :background_upload_limit),
38 banner_upload_limit: Keyword.get(instance, :banner_upload_limit),
39 background_image: Pleroma.Web.Endpoint.url() <> Keyword.get(instance, :background_image),
40 shout_limit: Config.get([:shout, :limit]),
41 description_limit: Keyword.get(instance, :description_limit),
42 pleroma: %{
43 metadata: %{
44 account_activation_required: Keyword.get(instance, :account_activation_required),
45 features: features(),
46 federation: federation(),
47 fields_limits: fields_limits(),
48 post_formats: Config.get([:instance, :allowed_post_formats])
49 },
50 stats: %{mau: Pleroma.User.active_user_count()},
51 vapid_public_key: Keyword.get(Pleroma.Web.Push.vapid_config(), :public_key)
52 }
53 }
54 end
55
56 def features do
57 [
58 "pleroma_api",
59 "mastodon_api",
60 "mastodon_api_streaming",
61 "polls",
62 "v2_suggestions",
63 "pleroma_explicit_addressing",
64 "shareable_emoji_packs",
65 "multifetch",
66 "pleroma:api/v1/notifications:include_types_filter",
67 if Config.get([:media_proxy, :enabled]) do
68 "media_proxy"
69 end,
70 if Config.get([:gopher, :enabled]) do
71 "gopher"
72 end,
73 # backwards compat
74 if Config.get([:shout, :enabled]) do
75 "chat"
76 end,
77 if Config.get([:shout, :enabled]) do
78 "shout"
79 end,
80 if Config.get([:instance, :allow_relay]) do
81 "relay"
82 end,
83 if Config.get([:instance, :safe_dm_mentions]) do
84 "safe_dm_mentions"
85 end,
86 "pleroma_emoji_reactions",
87 "pleroma_chat_messages",
88 if Config.get([:instance, :show_reactions]) do
89 "exposable_reactions"
90 end
91 ]
92 |> Enum.filter(& &1)
93 end
94
95 def federation do
96 quarantined = Config.get([:instance, :quarantined_instances], [])
97
98 if Config.get([:mrf, :transparency]) do
99 {:ok, data} = MRF.describe()
100
101 data
102 |> Map.put(
103 :quarantined_instances,
104 Enum.map(quarantined, fn {instance, _reason} -> instance end)
105 )
106 # This is for backwards compatibility. We originally didn't sent
107 # extra info like a reason why an instance was rejected/quarantined/etc.
108 # Because we didn't want to break backwards compatibility it was decided
109 # to add an extra "info" key.
110 |> Map.put(:quarantined_instances_info, %{
111 "quarantined_instances" =>
112 quarantined
113 |> Enum.map(fn {instance, reason} -> {instance, %{"reason" => reason}} end)
114 |> Map.new()
115 })
116 else
117 %{}
118 end
119 |> Map.put(:enabled, Config.get([:instance, :federating]))
120 end
121
122 def fields_limits do
123 %{
124 max_fields: Config.get([:instance, :max_account_fields]),
125 max_remote_fields: Config.get([:instance, :max_remote_account_fields]),
126 name_length: Config.get([:instance, :account_field_name_length]),
127 value_length: Config.get([:instance, :account_field_value_length])
128 }
129 end
130 end