InstanceView: Add common_information function

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak 2023-08-11 13:57:22 +02:00
parent 9effa24f30
commit 79e46ce73f
1 changed files with 13 additions and 9 deletions

View File

@ -13,12 +13,11 @@ defmodule Pleroma.Web.MastodonAPI.InstanceView do
def render("show.json", _) do def render("show.json", _) do
instance = Config.get(:instance) instance = Config.get(:instance)
%{ common_information(instance)
|> Map.merge(%{
uri: Pleroma.Web.WebFinger.domain(), uri: Pleroma.Web.WebFinger.domain(),
title: Keyword.get(instance, :name),
description: Keyword.get(instance, :description), description: Keyword.get(instance, :description),
short_description: Keyword.get(instance, :short_description), short_description: Keyword.get(instance, :short_description),
version: "#{@mastodon_api_level} (compatible; #{Pleroma.Application.named_version()})",
email: Keyword.get(instance, :email), email: Keyword.get(instance, :email),
urls: %{ urls: %{
streaming_api: Pleroma.Web.Endpoint.websocket_url() streaming_api: Pleroma.Web.Endpoint.websocket_url()
@ -27,7 +26,6 @@ def render("show.json", _) do
thumbnail: thumbnail:
URI.merge(Pleroma.Web.Endpoint.url(), Keyword.get(instance, :instance_thumbnail)) URI.merge(Pleroma.Web.Endpoint.url(), Keyword.get(instance, :instance_thumbnail))
|> to_string, |> to_string,
languages: Keyword.get(instance, :languages, ["en"]),
registrations: Keyword.get(instance, :registrations_open), registrations: Keyword.get(instance, :registrations_open),
approval_required: Keyword.get(instance, :account_approval_required), approval_required: Keyword.get(instance, :account_approval_required),
configuration: configuration(), configuration: configuration(),
@ -43,16 +41,15 @@ def render("show.json", _) do
shout_limit: Config.get([:shout, :limit]), shout_limit: Config.get([:shout, :limit]),
description_limit: Keyword.get(instance, :description_limit), description_limit: Keyword.get(instance, :description_limit),
pleroma: pleroma_configuration(instance) pleroma: pleroma_configuration(instance)
} })
end end
def render("show2.json", _) do def render("show2.json", _) do
instance = Config.get(:instance) instance = Config.get(:instance)
%{ common_information(instance)
|> Map.merge(%{
domain: Pleroma.Web.WebFinger.domain(), domain: Pleroma.Web.WebFinger.domain(),
title: Keyword.get(instance, :name),
version: "#{@mastodon_api_level} (compatible; #{Pleroma.Application.named_version()})",
source_url: Pleroma.Application.repository(), source_url: Pleroma.Application.repository(),
description: Keyword.get(instance, :short_description), description: Keyword.get(instance, :short_description),
usage: %{users: %{active_month: Pleroma.User.active_user_count()}}, usage: %{users: %{active_month: Pleroma.User.active_user_count()}},
@ -61,7 +58,6 @@ def render("show2.json", _) do
URI.merge(Pleroma.Web.Endpoint.url(), Keyword.get(instance, :instance_thumbnail)) URI.merge(Pleroma.Web.Endpoint.url(), Keyword.get(instance, :instance_thumbnail))
|> to_string |> to_string
}, },
languages: Keyword.get(instance, :languages, ["en"]),
configuration: configuration2(), configuration: configuration2(),
registrations: %{ registrations: %{
enabled: Keyword.get(instance, :registrations_open), enabled: Keyword.get(instance, :registrations_open),
@ -74,6 +70,14 @@ def render("show2.json", _) do
}, },
# Extra (not present in Mastodon): # Extra (not present in Mastodon):
pleroma: pleroma_configuration2(instance) pleroma: pleroma_configuration2(instance)
})
end
defp common_information(instance) do
%{
title: Keyword.get(instance, :name),
version: "#{@mastodon_api_level} (compatible; #{Pleroma.Application.named_version()})",
languages: Keyword.get(instance, :languages, ["en"])
} }
end end