summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/mix/tasks/pleroma/instance.ex22
-rw-r--r--lib/pleroma/web/activity_pub/mrf/mediaproxy_warming_policy.ex56
2 files changed, 61 insertions, 17 deletions
diff --git a/lib/mix/tasks/pleroma/instance.ex b/lib/mix/tasks/pleroma/instance.ex
index 997eabbeb..a27c4b897 100644
--- a/lib/mix/tasks/pleroma/instance.ex
+++ b/lib/mix/tasks/pleroma/instance.ex
@@ -114,12 +114,12 @@ defmodule Mix.Tasks.Pleroma.Instance do
options,
:db_configurable,
"Do you want to store the configuration in the database (allows controlling it from admin-fe)? (y/n)",
- "y"
+ "n"
) === "y"
dbhost = get_option(options, :dbhost, "What is the hostname of your database?", "localhost")
- dbname = get_option(options, :dbname, "What is the name of your database?", "pleroma_dev")
+ dbname = get_option(options, :dbname, "What is the name of your database?", "pleroma")
dbuser =
get_option(
@@ -198,28 +198,16 @@ defmodule Mix.Tasks.Pleroma.Instance do
rum_enabled: rum_enabled
)
- shell_info(
- "Writing config to #{config_path}. You should rename it to config/prod.secret.exs or config/dev.secret.exs."
- )
+ shell_info("Writing config to #{config_path}.")
File.write(config_path, result_config)
- shell_info("Writing #{psql_path}.")
+ shell_info("Writing the postgres script to #{psql_path}.")
File.write(psql_path, result_psql)
write_robots_txt(indexable, template_dir)
shell_info(
- "\n" <>
- """
- To get started:
- 1. Verify the contents of the generated files.
- 2. Run `sudo -u postgres psql -f #{escape_sh_path(psql_path)}`.
- """ <>
- if config_path in ["config/dev.secret.exs", "config/prod.secret.exs"] do
- ""
- else
- "3. Run `mv #{escape_sh_path(config_path)} 'config/prod.secret.exs'`."
- end
+ "\n All files successfully written! Refer to the installation instructions for your platform for next steps"
)
else
shell_error(
diff --git a/lib/pleroma/web/activity_pub/mrf/mediaproxy_warming_policy.ex b/lib/pleroma/web/activity_pub/mrf/mediaproxy_warming_policy.ex
new file mode 100644
index 000000000..01d21a299
--- /dev/null
+++ b/lib/pleroma/web/activity_pub/mrf/mediaproxy_warming_policy.ex
@@ -0,0 +1,56 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicy do
+ @moduledoc "Preloads any attachments in the MediaProxy cache by prefetching them"
+ @behaviour Pleroma.Web.ActivityPub.MRF
+
+ alias Pleroma.HTTP
+ alias Pleroma.Web.MediaProxy
+
+ require Logger
+
+ @hackney_options [
+ pool: :media,
+ recv_timeout: 10_000
+ ]
+
+ def perform(:prefetch, url) do
+ Logger.info("Prefetching #{inspect(url)}")
+
+ url
+ |> MediaProxy.url()
+ |> HTTP.get([], adapter: @hackney_options)
+ end
+
+ def perform(:preload, %{"object" => %{"attachment" => attachments}} = _message) do
+ Enum.each(attachments, fn
+ %{"url" => url} when is_list(url) ->
+ url
+ |> Enum.each(fn
+ %{"href" => href} ->
+ PleromaJobQueue.enqueue(:background, __MODULE__, [:prefetch, href])
+
+ x ->
+ Logger.debug("Unhandled attachment URL object #{inspect(x)}")
+ end)
+
+ x ->
+ Logger.debug("Unhandled attachment #{inspect(x)}")
+ end)
+ end
+
+ @impl true
+ def filter(
+ %{"type" => "Create", "object" => %{"attachment" => attachments} = _object} = message
+ )
+ when is_list(attachments) and length(attachments) > 0 do
+ PleromaJobQueue.enqueue(:background, __MODULE__, [:preload, message])
+
+ {:ok, message}
+ end
+
+ @impl true
+ def filter(message), do: {:ok, message}
+end