8088306c3bd0c01f6f4d0d4ae725f48067a448a8
[akkoma] / lib / pleroma / web / mastodon_api / views / instance_view.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 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() <> "/instance/thumbnail.jpeg",
27 languages: ["en"],
28 registrations: Keyword.get(instance, :registrations_open),
29 # Extra (not present in Mastodon):
30 max_toot_chars: Keyword.get(instance, :limit),
31 poll_limits: Keyword.get(instance, :poll_limits),
32 upload_limit: Keyword.get(instance, :upload_limit),
33 avatar_upload_limit: Keyword.get(instance, :avatar_upload_limit),
34 background_upload_limit: Keyword.get(instance, :background_upload_limit),
35 banner_upload_limit: Keyword.get(instance, :banner_upload_limit),
36 background_image: Keyword.get(instance, :background_image),
37 pleroma: %{
38 metadata: %{
39 features: features(),
40 federation: federation()
41 },
42 vapid_public_key: Keyword.get(Pleroma.Web.Push.vapid_config(), :public_key)
43 }
44 }
45 end
46
47 def features do
48 [
49 "pleroma_api",
50 "mastodon_api",
51 "mastodon_api_streaming",
52 "polls",
53 "pleroma_explicit_addressing",
54 "shareable_emoji_packs",
55 "multifetch",
56 "pleroma:api/v1/notifications:include_types_filter",
57 if Config.get([:media_proxy, :enabled]) do
58 "media_proxy"
59 end,
60 if Config.get([:gopher, :enabled]) do
61 "gopher"
62 end,
63 if Config.get([:chat, :enabled]) do
64 "chat"
65 end,
66 if Config.get([:instance, :allow_relay]) do
67 "relay"
68 end,
69 if Config.get([:instance, :safe_dm_mentions]) do
70 "safe_dm_mentions"
71 end,
72 "pleroma_emoji_reactions"
73 ]
74 |> Enum.filter(& &1)
75 end
76
77 def federation do
78 quarantined = Config.get([:instance, :quarantined_instances], [])
79
80 if Config.get([:instance, :mrf_transparency]) do
81 {:ok, data} = MRF.describe()
82
83 data
84 |> Map.merge(%{quarantined_instances: quarantined})
85 else
86 %{}
87 end
88 |> Map.put(:enabled, Config.get([:instance, :federating]))
89 end
90 end