Preload: Load the correct instance panel
authorlain <lain@soykaf.club>
Tue, 30 Jun 2020 09:35:54 +0000 (11:35 +0200)
committerlain <lain@soykaf.club>
Tue, 30 Jun 2020 09:35:54 +0000 (11:35 +0200)
lib/pleroma/web/preload/instance.ex
test/fixtures/preload_static/instance/panel.html [new file with mode: 0644]
test/web/preload/instance_test.exs

index 0b6fd33139bacec08fabbd5beb0ae4557b6ce021..5c6e33e475bbce22ea884a8921bb8f8a2aa539c0 100644 (file)
@@ -6,6 +6,7 @@ defmodule Pleroma.Web.Preload.Providers.Instance do
   alias Pleroma.Web.MastodonAPI.InstanceView
   alias Pleroma.Web.Nodeinfo.Nodeinfo
   alias Pleroma.Web.Preload.Providers.Provider
+  alias Pleroma.Plugs.InstanceStatic
 
   @behaviour Provider
   @instance_url :"/api/v1/instance"
@@ -27,7 +28,7 @@ defmodule Pleroma.Web.Preload.Providers.Instance do
   end
 
   defp build_panel_tag(acc) do
-    instance_path = Path.join(:code.priv_dir(:pleroma), "static/instance/panel.html")
+    instance_path = InstanceStatic.file_path(@panel_url |> to_string())
 
     if File.exists?(instance_path) do
       panel_data = File.read!(instance_path)
diff --git a/test/fixtures/preload_static/instance/panel.html b/test/fixtures/preload_static/instance/panel.html
new file mode 100644 (file)
index 0000000..fc58e4e
--- /dev/null
@@ -0,0 +1 @@
+HEY!
index 42a0d87bc67fa0ab7ca07c6075b948e4848b4de5..df150d7bebc1163aed7bfb7f890d5dd82ae97d76 100644 (file)
@@ -25,6 +25,17 @@ defmodule Pleroma.Web.Preload.Providers.InstanceTest do
            )
   end
 
+  test "it works with overrides" do
+    clear_config([:instance, :static_dir], "test/fixtures/preload_static")
+
+    %{"/instance/panel.html": panel} = Instance.generate_terms(nil)
+
+    assert String.contains?(
+             panel,
+             "HEY!"
+           )
+  end
+
   test "it renders the node_info", %{"/nodeinfo/2.0": nodeinfo} do
     %{
       metadata: metadata,