1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.Preload.Providers.Instance do
6 alias Pleroma.Web.MastodonAPI.InstanceView
7 alias Pleroma.Web.Nodeinfo.Nodeinfo
8 alias Pleroma.Web.Plugs.InstanceStatic
9 alias Pleroma.Web.Preload.Providers.Provider
10 alias Pleroma.Web.TwitterAPI.UtilView
13 @instance_url "/api/v1/instance"
14 @panel_url "/instance/panel.html"
15 @nodeinfo_url "/nodeinfo/2.0.json"
16 @fe_config_url "/api/pleroma/frontend_configurations"
19 def generate_terms(_params) do
23 |> build_nodeinfo_tag()
24 |> build_fe_config_tag()
27 defp build_info_tag(acc) do
28 info_data = InstanceView.render("show.json", %{})
30 Map.put(acc, @instance_url, info_data)
33 defp build_panel_tag(acc) do
34 instance_path = InstanceStatic.file_path(@panel_url |> to_string())
36 if File.exists?(instance_path) do
37 panel_data = File.read!(instance_path)
38 Map.put(acc, @panel_url, panel_data)
44 defp build_nodeinfo_tag(acc) do
45 case Nodeinfo.get_nodeinfo("2.0") do
50 Map.put(acc, @nodeinfo_url, nodeinfo_data)
54 defp build_fe_config_tag(acc) do
55 fe_data = UtilView.render("frontend_configurations.json", %{})
57 Map.put(acc, @fe_config_url, fe_data)