2020-05-12 15:08:00 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2022-02-26 06:11:42 +00:00
|
|
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
2020-05-12 15:08:00 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.Preload.Providers.Instance do
|
|
|
|
alias Pleroma.Web.MastodonAPI.InstanceView
|
|
|
|
alias Pleroma.Web.Nodeinfo.Nodeinfo
|
2020-07-08 12:41:53 +00:00
|
|
|
alias Pleroma.Web.Plugs.InstanceStatic
|
2020-05-12 15:08:00 +00:00
|
|
|
alias Pleroma.Web.Preload.Providers.Provider
|
2020-10-12 23:49:37 +00:00
|
|
|
alias Pleroma.Web.TwitterAPI.UtilView
|
2020-05-12 15:08:00 +00:00
|
|
|
|
|
|
|
@behaviour Provider
|
2020-06-29 09:41:00 +00:00
|
|
|
@instance_url "/api/v1/instance"
|
|
|
|
@panel_url "/instance/panel.html"
|
|
|
|
@nodeinfo_url "/nodeinfo/2.0.json"
|
2020-10-12 23:49:37 +00:00
|
|
|
@fe_config_url "/api/pleroma/frontend_configurations"
|
2020-05-12 15:08:00 +00:00
|
|
|
|
|
|
|
@impl Provider
|
|
|
|
def generate_terms(_params) do
|
|
|
|
%{}
|
|
|
|
|> build_info_tag()
|
|
|
|
|> build_panel_tag()
|
|
|
|
|> build_nodeinfo_tag()
|
2020-10-12 23:49:37 +00:00
|
|
|
|> build_fe_config_tag()
|
2020-05-12 15:08:00 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
defp build_info_tag(acc) do
|
|
|
|
info_data = InstanceView.render("show.json", %{})
|
|
|
|
|
|
|
|
Map.put(acc, @instance_url, info_data)
|
|
|
|
end
|
|
|
|
|
|
|
|
defp build_panel_tag(acc) do
|
2020-06-30 09:35:54 +00:00
|
|
|
instance_path = InstanceStatic.file_path(@panel_url |> to_string())
|
2020-05-12 15:08:00 +00:00
|
|
|
|
|
|
|
if File.exists?(instance_path) do
|
|
|
|
panel_data = File.read!(instance_path)
|
|
|
|
Map.put(acc, @panel_url, panel_data)
|
|
|
|
else
|
|
|
|
acc
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
defp build_nodeinfo_tag(acc) do
|
|
|
|
case Nodeinfo.get_nodeinfo("2.0") do
|
|
|
|
{:error, _} ->
|
|
|
|
acc
|
|
|
|
|
|
|
|
nodeinfo_data ->
|
|
|
|
Map.put(acc, @nodeinfo_url, nodeinfo_data)
|
|
|
|
end
|
|
|
|
end
|
2020-10-12 23:49:37 +00:00
|
|
|
|
|
|
|
defp build_fe_config_tag(acc) do
|
|
|
|
fe_data = UtilView.render("frontend_configurations.json", %{})
|
|
|
|
|
|
|
|
Map.put(acc, @fe_config_url, fe_data)
|
|
|
|
end
|
2020-05-12 15:08:00 +00:00
|
|
|
end
|