set_postgres_server_version()
- # Requires Config.TransferTask so ConfigDB values are loaded
- steal_emoji_policy_setup()
-
result
end
[Pleroma.Web.RichMedia.Helpers, Pleroma.Web.MediaProxy]
|> Enum.each(&ConcurrentLimiter.new(&1, 1, 0))
end
-
- @spec steal_emoji_policy_setup() :: :ok
- defp steal_emoji_policy_setup() do
- with true <-
- Pleroma.Web.ActivityPub.MRF.StealEmojiPolicy in Config.get!([:mrf, :policies]) do
- path =
- [:instance, :static_dir]
- |> Config.get!()
- |> Path.join("emoji/steal")
-
- if !File.exists?(path), do: File.mkdir_p!(path)
- else
- _ ->
- :ok
- end
- end
end
defp accept_host?(host), do: host in Config.get([:mrf_steal_emoji, :hosts], [])
- defp steal_emoji({shortcode, url}) do
+ defp steal_emoji({shortcode, url}, emoji_dir_path) do
url = Pleroma.Web.MediaProxy.url(url)
{:ok, response} = Pleroma.HTTP.get(url)
size_limit = Config.get([:mrf_steal_emoji, :size_limit], 50_000)
if byte_size(response.body) <= size_limit do
- emoji_dir_path =
- Config.get(
- [:mrf_steal_emoji, :path],
- Path.join(Config.get([:instance, :static_dir]), "emoji/stolen")
- )
-
extension =
url
|> URI.parse()
file_path = Path.join([emoji_dir_path, shortcode <> (extension || ".png")])
- try do
- :ok = File.write(file_path, response.body)
-
+ with :ok <- File.write(file_path, response.body) do
shortcode
- rescue
+ else
e ->
Logger.warn("MRF.StealEmojiPolicy: Failed to write to #{file_path}: #{inspect(e)}")
nil
if remote_host?(host) and accept_host?(host) do
installed_emoji = Pleroma.Emoji.get_all() |> Enum.map(fn {k, _} -> k end)
+ emoji_dir_path =
+ Config.get(
+ [:mrf_steal_emoji, :path],
+ Path.join(Config.get([:instance, :static_dir]), "emoji/stolen")
+ )
+
+ if not Config.get([:mrf_steal_emoji, :dir_exists?], false) do
+ create_dir(emoji_dir_path)
+ end
+
new_emojis =
foreign_emojis
|> Enum.filter(fn {shortcode, _url} -> shortcode not in installed_emoji end)
!reject_emoji?
end)
- |> Enum.map(&steal_emoji(&1))
+ |> Enum.map(&steal_emoji(&1, emoji_dir_path))
|> Enum.filter(& &1)
if !Enum.empty?(new_emojis) do
def describe do
{:ok, %{}}
end
+
+ defp create_dir(path) do
+ if not File.exists?(path) do
+ File.mkdir_p!(path)
+ end
+
+ Config.put([:mrf_steal_emoji, :dir_exists?], true)
+ end
end