aboutsummaryrefslogtreecommitdiff
path: root/lib/pleroma/web/preload
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pleroma/web/preload')
-rw-r--r--lib/pleroma/web/preload/instance.ex49
-rw-r--r--lib/pleroma/web/preload/provider.ex7
-rw-r--r--lib/pleroma/web/preload/status_net.ex24
-rw-r--r--lib/pleroma/web/preload/timelines.ex39
-rw-r--r--lib/pleroma/web/preload/user.ex25
5 files changed, 144 insertions, 0 deletions
diff --git a/lib/pleroma/web/preload/instance.ex b/lib/pleroma/web/preload/instance.ex
new file mode 100644
index 000000000..0b6fd3313
--- /dev/null
+++ b/lib/pleroma/web/preload/instance.ex
@@ -0,0 +1,49 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.Preload.Providers.Instance do
+ alias Pleroma.Web.MastodonAPI.InstanceView
+ alias Pleroma.Web.Nodeinfo.Nodeinfo
+ alias Pleroma.Web.Preload.Providers.Provider
+
+ @behaviour Provider
+ @instance_url :"/api/v1/instance"
+ @panel_url :"/instance/panel.html"
+ @nodeinfo_url :"/nodeinfo/2.0"
+
+ @impl Provider
+ def generate_terms(_params) do
+ %{}
+ |> build_info_tag()
+ |> build_panel_tag()
+ |> build_nodeinfo_tag()
+ 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
+ instance_path = Path.join(:code.priv_dir(:pleroma), "static/instance/panel.html")
+
+ 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
+end
diff --git a/lib/pleroma/web/preload/provider.ex b/lib/pleroma/web/preload/provider.ex
new file mode 100644
index 000000000..7ef595a34
--- /dev/null
+++ b/lib/pleroma/web/preload/provider.ex
@@ -0,0 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.Preload.Providers.Provider do
+ @callback generate_terms(map()) :: map()
+end
diff --git a/lib/pleroma/web/preload/status_net.ex b/lib/pleroma/web/preload/status_net.ex
new file mode 100644
index 000000000..367442d5c
--- /dev/null
+++ b/lib/pleroma/web/preload/status_net.ex
@@ -0,0 +1,24 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.Preload.Providers.StatusNet do
+ alias Pleroma.Web.Preload.Providers.Provider
+ alias Pleroma.Web.TwitterAPI.UtilView
+
+ @behaviour Provider
+ @config_url :"/api/statusnet/config.json"
+
+ @impl Provider
+ def generate_terms(_params) do
+ %{}
+ |> build_config_tag()
+ end
+
+ defp build_config_tag(acc) do
+ instance = Pleroma.Config.get(:instance)
+ info_data = UtilView.status_net_config(instance)
+
+ Map.put(acc, @config_url, info_data)
+ end
+end
diff --git a/lib/pleroma/web/preload/timelines.ex b/lib/pleroma/web/preload/timelines.ex
new file mode 100644
index 000000000..e531b8960
--- /dev/null
+++ b/lib/pleroma/web/preload/timelines.ex
@@ -0,0 +1,39 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.Preload.Providers.Timelines do
+ alias Pleroma.Web.ActivityPub.ActivityPub
+ alias Pleroma.Web.MastodonAPI.StatusView
+ alias Pleroma.Web.Preload.Providers.Provider
+
+ @behaviour Provider
+ @public_url :"/api/v1/timelines/public"
+
+ @impl Provider
+ def generate_terms(params) do
+ build_public_tag(%{}, params)
+ end
+
+ def build_public_tag(acc, params) do
+ if Pleroma.Config.get([:restrict_unauthenticated, :timelines, :federated], true) do
+ acc
+ else
+ Map.put(acc, @public_url, public_timeline(params))
+ end
+ end
+
+ defp public_timeline(%{"path" => ["main", "all"]}), do: get_public_timeline(false)
+
+ defp public_timeline(_params), do: get_public_timeline(true)
+
+ defp get_public_timeline(local_only) do
+ activities =
+ ActivityPub.fetch_public_activities(%{
+ type: ["Create"],
+ local_only: local_only
+ })
+
+ StatusView.render("index.json", activities: activities, for: nil, as: :activity)
+ end
+end
diff --git a/lib/pleroma/web/preload/user.ex b/lib/pleroma/web/preload/user.ex
new file mode 100644
index 000000000..3a244845b
--- /dev/null
+++ b/lib/pleroma/web/preload/user.ex
@@ -0,0 +1,25 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.Preload.Providers.User do
+ alias Pleroma.Web.MastodonAPI.AccountView
+ alias Pleroma.Web.Preload.Providers.Provider
+
+ @behaviour Provider
+ @account_url :"/api/v1/accounts"
+
+ @impl Provider
+ def generate_terms(%{user: user}) do
+ build_accounts_tag(%{}, user)
+ end
+
+ def generate_terms(_params), do: %{}
+
+ def build_accounts_tag(acc, nil), do: acc
+
+ def build_accounts_tag(acc, user) do
+ account_data = AccountView.render("show.json", %{user: user, for: user})
+ Map.put(acc, @account_url, account_data)
+ end
+end