Support blurhash
[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.base_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: Pleroma.Web.base_url() <> Keyword.get(instance, :instance_thumbnail),
27 languages: ["en"],
28 registrations: Keyword.get(instance, :registrations_open),
29 approval_required: Keyword.get(instance, :account_approval_required),
30 # Extra (not present in Mastodon):
31 max_toot_chars: Keyword.get(instance, :limit),
32 poll_limits: Keyword.get(instance, :poll_limits),
33 upload_limit: Keyword.get(instance, :upload_limit),
34 avatar_upload_limit: Keyword.get(instance, :avatar_upload_limit),
35 background_upload_limit: Keyword.get(instance, :background_upload_limit),
36 banner_upload_limit: Keyword.get(instance, :banner_upload_limit),
37 background_image: Pleroma.Web.base_url() <> Keyword.get(instance, :background_image),
38 chat_limit: Keyword.get(instance, :chat_limit),
39 description_limit: Keyword.get(instance, :description_limit),
40 pleroma: %{
41 metadata: %{
42 account_activation_required: Keyword.get(instance, :account_activation_required),
43 features: features(),
44 federation: federation(),
45 fields_limits: fields_limits(),
46 post_formats: Config.get([:instance, :allowed_post_formats])
47 },
48 stats: %{mau: Pleroma.User.active_user_count()},
49 vapid_public_key: Keyword.get(Pleroma.Web.Push.vapid_config(), :public_key)
50 }
51 }
52 end
53
54 def features do
55 [
56 "pleroma_api",
57 "mastodon_api",
58 "mastodon_api_streaming",
59 "polls",
60 "pleroma_explicit_addressing",
61 "shareable_emoji_packs",
62 "multifetch",
63 "pleroma:api/v1/notifications:include_types_filter",
64 if Config.get([:media_proxy, :enabled]) do
65 "media_proxy"
66 end,
67 if Config.get([:gopher, :enabled]) do
68 "gopher"
69 end,
70 if Config.get([:chat, :enabled]) do
71 "chat"
72 end,
73 if Config.get([:instance, :allow_relay]) do
74 "relay"
75 end,
76 if Config.get([:instance, :safe_dm_mentions]) do
77 "safe_dm_mentions"
78 end,
79 "pleroma_emoji_reactions",
80 "pleroma_chat_messages"
81 ]
82 |> Enum.filter(& &1)
83 end
84
85 def federation do
86 quarantined = Config.get([:instance, :quarantined_instances], [])
87
88 if Config.get([:mrf, :transparency]) do
89 {:ok, data} = MRF.describe()
90
91 data
92 |> Map.merge(%{quarantined_instances: quarantined})
93 else
94 %{}
95 end
96 |> Map.put(:enabled, Config.get([:instance, :federating]))
97 end
98
99 def fields_limits do
100 %{
101 max_fields: Config.get([:instance, :max_account_fields]),
102 max_remote_fields: Config.get([:instance, :max_remote_account_fields]),
103 name_length: Config.get([:instance, :account_field_name_length]),
104 value_length: Config.get([:instance, :account_field_value_length])
105 }
106 end
107 end