Merge branch 'preload-frontend-config' into 'develop'
Preload `/api/pleroma/frontend_configurations`, fixes #1932 Closes #1932 See merge request pleroma/pleroma!3075
This commit is contained in:
commit
5ed7eb1a26
@ -7,11 +7,13 @@ defmodule Pleroma.Web.Preload.Providers.Instance do
|
|||||||
alias Pleroma.Web.MastodonAPI.InstanceView
|
alias Pleroma.Web.MastodonAPI.InstanceView
|
||||||
alias Pleroma.Web.Nodeinfo.Nodeinfo
|
alias Pleroma.Web.Nodeinfo.Nodeinfo
|
||||||
alias Pleroma.Web.Preload.Providers.Provider
|
alias Pleroma.Web.Preload.Providers.Provider
|
||||||
|
alias Pleroma.Web.TwitterAPI.UtilView
|
||||||
|
|
||||||
@behaviour Provider
|
@behaviour Provider
|
||||||
@instance_url "/api/v1/instance"
|
@instance_url "/api/v1/instance"
|
||||||
@panel_url "/instance/panel.html"
|
@panel_url "/instance/panel.html"
|
||||||
@nodeinfo_url "/nodeinfo/2.0.json"
|
@nodeinfo_url "/nodeinfo/2.0.json"
|
||||||
|
@fe_config_url "/api/pleroma/frontend_configurations"
|
||||||
|
|
||||||
@impl Provider
|
@impl Provider
|
||||||
def generate_terms(_params) do
|
def generate_terms(_params) do
|
||||||
@ -19,6 +21,7 @@ defmodule Pleroma.Web.Preload.Providers.Instance do
|
|||||||
|> build_info_tag()
|
|> build_info_tag()
|
||||||
|> build_panel_tag()
|
|> build_panel_tag()
|
||||||
|> build_nodeinfo_tag()
|
|> build_nodeinfo_tag()
|
||||||
|
|> build_fe_config_tag()
|
||||||
end
|
end
|
||||||
|
|
||||||
defp build_info_tag(acc) do
|
defp build_info_tag(acc) do
|
||||||
@ -47,4 +50,10 @@ defmodule Pleroma.Web.Preload.Providers.Instance do
|
|||||||
Map.put(acc, @nodeinfo_url, nodeinfo_data)
|
Map.put(acc, @nodeinfo_url, nodeinfo_data)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp build_fe_config_tag(acc) do
|
||||||
|
fe_data = UtilView.render("frontend_configurations.json", %{})
|
||||||
|
|
||||||
|
Map.put(acc, @fe_config_url, fe_data)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -74,11 +74,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilController do
|
|||||||
end
|
end
|
||||||
|
|
||||||
def frontend_configurations(conn, _params) do
|
def frontend_configurations(conn, _params) do
|
||||||
config =
|
render(conn, "frontend_configurations.json")
|
||||||
Config.get(:frontend_configurations, %{})
|
|
||||||
|> Enum.into(%{})
|
|
||||||
|
|
||||||
json(conn, config)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def emoji(conn, _params) do
|
def emoji(conn, _params) do
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
defmodule Pleroma.Web.TwitterAPI.UtilView do
|
defmodule Pleroma.Web.TwitterAPI.UtilView do
|
||||||
use Pleroma.Web, :view
|
use Pleroma.Web, :view
|
||||||
import Phoenix.HTML.Form
|
import Phoenix.HTML.Form
|
||||||
|
alias Pleroma.Config
|
||||||
alias Pleroma.Web
|
alias Pleroma.Web
|
||||||
|
|
||||||
def status_net_config(instance) do
|
def status_net_config(instance) do
|
||||||
@ -19,4 +20,9 @@ defmodule Pleroma.Web.TwitterAPI.UtilView do
|
|||||||
</config>
|
</config>
|
||||||
"""
|
"""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def render("frontend_configurations.json", _) do
|
||||||
|
Config.get(:frontend_configurations, %{})
|
||||||
|
|> Enum.into(%{})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -45,4 +45,12 @@ defmodule Pleroma.Web.Preload.Providers.InstanceTest do
|
|||||||
assert metadata.private == false
|
assert metadata.private == false
|
||||||
assert metadata.suggestions == %{enabled: false}
|
assert metadata.suggestions == %{enabled: false}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "it renders the frontend configurations", %{
|
||||||
|
"/api/pleroma/frontend_configurations" => fe_configs
|
||||||
|
} do
|
||||||
|
assert %{
|
||||||
|
pleroma_fe: %{background: "/images/city.jpg", logo: "/static/logo.png"}
|
||||||
|
} = fe_configs
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user