Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 lines
3.5KB

  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. defmodule Pleroma.Web.MastodonAPI.InstanceView do
  5. use Pleroma.Web, :view
  6. alias Pleroma.Config
  7. alias Pleroma.Web.ActivityPub.MRF
  8. @mastodon_api_level "2.7.2"
  9. def render("show.json", _) do
  10. instance = Config.get(:instance)
  11. %{
  12. uri: Pleroma.Web.Endpoint.url(),
  13. title: Keyword.get(instance, :name),
  14. description: Keyword.get(instance, :description),
  15. version: "#{@mastodon_api_level} (compatible; #{Pleroma.Application.named_version()})",
  16. email: Keyword.get(instance, :email),
  17. urls: %{
  18. streaming_api: Pleroma.Web.Endpoint.websocket_url()
  19. },
  20. stats: Pleroma.Stats.get_stats(),
  21. thumbnail: Pleroma.Web.Endpoint.url() <> Keyword.get(instance, :instance_thumbnail),
  22. languages: ["en"],
  23. registrations: Keyword.get(instance, :registrations_open),
  24. approval_required: Keyword.get(instance, :account_approval_required),
  25. # Extra (not present in Mastodon):
  26. max_toot_chars: Keyword.get(instance, :limit),
  27. poll_limits: Keyword.get(instance, :poll_limits),
  28. upload_limit: Keyword.get(instance, :upload_limit),
  29. avatar_upload_limit: Keyword.get(instance, :avatar_upload_limit),
  30. background_upload_limit: Keyword.get(instance, :background_upload_limit),
  31. banner_upload_limit: Keyword.get(instance, :banner_upload_limit),
  32. background_image: Pleroma.Web.Endpoint.url() <> Keyword.get(instance, :background_image),
  33. chat_limit: Keyword.get(instance, :chat_limit),
  34. description_limit: Keyword.get(instance, :description_limit),
  35. pleroma: %{
  36. metadata: %{
  37. account_activation_required: Keyword.get(instance, :account_activation_required),
  38. features: features(),
  39. federation: federation(),
  40. fields_limits: fields_limits(),
  41. post_formats: Config.get([:instance, :allowed_post_formats])
  42. },
  43. stats: %{mau: Pleroma.User.active_user_count()},
  44. vapid_public_key: Keyword.get(Pleroma.Web.Push.vapid_config(), :public_key)
  45. }
  46. }
  47. end
  48. def features do
  49. [
  50. "pleroma_api",
  51. "mastodon_api",
  52. "mastodon_api_streaming",
  53. "polls",
  54. "pleroma_explicit_addressing",
  55. "shareable_emoji_packs",
  56. "multifetch",
  57. "pleroma:api/v1/notifications:include_types_filter",
  58. if Config.get([:media_proxy, :enabled]) do
  59. "media_proxy"
  60. end,
  61. if Config.get([:gopher, :enabled]) do
  62. "gopher"
  63. end,
  64. if Config.get([:chat, :enabled]) do
  65. "chat"
  66. end,
  67. if Config.get([:instance, :allow_relay]) do
  68. "relay"
  69. end,
  70. if Config.get([:instance, :safe_dm_mentions]) do
  71. "safe_dm_mentions"
  72. end,
  73. "pleroma_emoji_reactions",
  74. "pleroma_chat_messages"
  75. ]
  76. |> Enum.filter(& &1)
  77. end
  78. def federation do
  79. quarantined = Config.get([:instance, :quarantined_instances], [])
  80. if Config.get([:mrf, :transparency]) do
  81. {:ok, data} = MRF.describe()
  82. data
  83. |> Map.merge(%{quarantined_instances: quarantined})
  84. else
  85. %{}
  86. end
  87. |> Map.put(:enabled, Config.get([:instance, :federating]))
  88. end
  89. def fields_limits do
  90. %{
  91. max_fields: Config.get([:instance, :max_account_fields]),
  92. max_remote_fields: Config.get([:instance, :max_remote_account_fields]),
  93. name_length: Config.get([:instance, :account_field_name_length]),
  94. value_length: Config.get([:instance, :account_field_value_length])
  95. }
  96. end
  97. end