instance_view.ex 3.57 KB
Newer Older
1
# Pleroma: A lightweight social networking server
Haelwenn's avatar
Haelwenn committed
2
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3
4
5
6
7
# SPDX-License-Identifier: AGPL-3.0-only

defmodule Pleroma.Web.MastodonAPI.InstanceView do
  use Pleroma.Web, :view

8
9
10
  alias Pleroma.Config
  alias Pleroma.Web.ActivityPub.MRF

11
12
13
  @mastodon_api_level "2.7.2"

  def render("show.json", _) do
14
    instance = Config.get(:instance)
15
16

    %{
17
      uri: Pleroma.Web.Endpoint.url(),
18
19
20
21
22
23
24
25
      title: Keyword.get(instance, :name),
      description: Keyword.get(instance, :description),
      version: "#{@mastodon_api_level} (compatible; #{Pleroma.Application.named_version()})",
      email: Keyword.get(instance, :email),
      urls: %{
        streaming_api: Pleroma.Web.Endpoint.websocket_url()
      },
      stats: Pleroma.Stats.get_stats(),
26
      thumbnail:
27
28
        URI.merge(Pleroma.Web.Endpoint.url(), Keyword.get(instance, :instance_thumbnail))
        |> to_string,
29
30
      languages: ["en"],
      registrations: Keyword.get(instance, :registrations_open),
31
      approval_required: Keyword.get(instance, :account_approval_required),
32
33
34
35
36
37
      # Extra (not present in Mastodon):
      max_toot_chars: Keyword.get(instance, :limit),
      poll_limits: Keyword.get(instance, :poll_limits),
      upload_limit: Keyword.get(instance, :upload_limit),
      avatar_upload_limit: Keyword.get(instance, :avatar_upload_limit),
      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
43
      pleroma: %{
        metadata: %{
44
          account_activation_required: Keyword.get(instance, :account_activation_required),
45
          features: features(),
46
          federation: federation(),
47
48
          fields_limits: fields_limits(),
          post_formats: Config.get([:instance, :allowed_post_formats])
49
        },
minibikini's avatar
minibikini committed
50
        stats: %{mau: Pleroma.User.active_user_count()},
51
52
        vapid_public_key: Keyword.get(Pleroma.Web.Push.vapid_config(), :public_key)
      }
53
54
    }
  end
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71

  def features do
    [
      "pleroma_api",
      "mastodon_api",
      "mastodon_api_streaming",
      "polls",
      "pleroma_explicit_addressing",
      "shareable_emoji_packs",
      "multifetch",
      "pleroma:api/v1/notifications:include_types_filter",
      if Config.get([:media_proxy, :enabled]) do
        "media_proxy"
      end,
      if Config.get([:gopher, :enabled]) do
        "gopher"
      end,
72
73
      if Config.get([:shout, :enabled]) do
        "shout"
74
75
76
77
78
79
80
      end,
      if Config.get([:instance, :allow_relay]) do
        "relay"
      end,
      if Config.get([:instance, :safe_dm_mentions]) do
        "safe_dm_mentions"
      end,
81
82
      "pleroma_emoji_reactions",
      "pleroma_chat_messages"
83
84
85
86
87
88
89
    ]
    |> Enum.filter(& &1)
  end

  def federation do
    quarantined = Config.get([:instance, :quarantined_instances], [])

90
    if Config.get([:mrf, :transparency]) do
91
92
93
94
95
96
97
98
99
      {:ok, data} = MRF.describe()

      data
      |> Map.merge(%{quarantined_instances: quarantined})
    else
      %{}
    end
    |> Map.put(:enabled, Config.get([:instance, :federating]))
  end
100
101
102

  def fields_limits do
    %{
feld's avatar
feld committed
103
104
105
106
      max_fields: Config.get([:instance, :max_account_fields]),
      max_remote_fields: Config.get([:instance, :max_remote_account_fields]),
      name_length: Config.get([:instance, :account_field_name_length]),
      value_length: Config.get([:instance, :account_field_value_length])
107
108
    }
  end
109
end