don't check local objects
This commit is contained in:
parent
0996474508
commit
596bf5882d
|
@ -10,56 +10,64 @@ defmodule Pleroma.Web.ActivityPub.MRF.StealEmojiPolicy do
|
|||
length(result) == 1
|
||||
end
|
||||
|
||||
defp local_actor(actor) do
|
||||
host = Pleroma.Config.get([Pleroma.Web.Endpoint, :url, :host])
|
||||
prefix = "https://" <> host <> "/"
|
||||
String.starts_with?(actor, prefix)
|
||||
end
|
||||
|
||||
@impl true
|
||||
def filter(%{"object" => %{"emoji" => foreign_emoji}} = object) do
|
||||
num_foreign_emoji = Kernel.map_size(foreign_emoji)
|
||||
def filter(%{"object" => %{"emoji" => foreign_emoji, "actor" => actor}} = object) do
|
||||
unless local_actor(actor) do
|
||||
num_foreign_emoji = Kernel.map_size(foreign_emoji)
|
||||
|
||||
if num_foreign_emoji > 0 do
|
||||
Logger.debug("#{num_foreign_emoji} EMOJI TO PROCESS")
|
||||
installed_emoji = Pleroma.Emoji.get_all()
|
||||
if num_foreign_emoji > 0 do
|
||||
Logger.debug("#{num_foreign_emoji} EMOJI TO PROCESS")
|
||||
installed_emoji = Pleroma.Emoji.get_all()
|
||||
|
||||
new_files =
|
||||
for {emojo_shortcode, emojo_url} <- foreign_emoji,
|
||||
!has_emojo(installed_emoji, emojo_shortcode) do
|
||||
Logger.debug("HANDLING EMOJO")
|
||||
new_files =
|
||||
for {emojo_shortcode, emojo_url} <- foreign_emoji,
|
||||
!has_emojo(installed_emoji, emojo_shortcode) do
|
||||
Logger.debug("HANDLING EMOJO")
|
||||
|
||||
cond do
|
||||
String.contains?(emojo_shortcode, "/") ->
|
||||
Logger.error("BAD EMOJO SHORTCODE: #{emojo_shortcode}")
|
||||
cond do
|
||||
String.contains?(emojo_shortcode, "/") ->
|
||||
Logger.error("BAD EMOJO SHORTCODE: #{emojo_shortcode}")
|
||||
|
||||
String.starts_with?(emojo_url, "https://") ->
|
||||
try do
|
||||
remote_emojo = HTTPoison.get!(emojo_url)
|
||||
String.starts_with?(emojo_url, "https://") ->
|
||||
try do
|
||||
remote_emojo = HTTPoison.get!(emojo_url)
|
||||
|
||||
if remote_emojo.status_code == 200 do
|
||||
with {:ok, current_dir} <- File.cwd() do
|
||||
new_file = current_dir <> "/priv/static/emoji/stolen/" <> emojo_shortcode <> Path.extname(emojo_url)
|
||||
if remote_emojo.status_code == 200 do
|
||||
with {:ok, current_dir} <- File.cwd() do
|
||||
new_file = current_dir <> "/priv/static/emoji/stolen/" <> emojo_shortcode <> Path.extname(emojo_url)
|
||||
|
||||
{:ok, file} = File.open(new_file, [:write])
|
||||
IO.binwrite(file, remote_emojo.body)
|
||||
File.close(file)
|
||||
Logger.debug("SAVED EMOJO")
|
||||
new_file
|
||||
{:ok, file} = File.open(new_file, [:write])
|
||||
IO.binwrite(file, remote_emojo.body)
|
||||
File.close(file)
|
||||
Logger.debug("SAVED EMOJO")
|
||||
new_file
|
||||
end
|
||||
end
|
||||
rescue
|
||||
e in RuntimeError -> Logger.error("FAILED TO QUERY REMOTE EMOJO #{emojo_url} #{e}")
|
||||
end
|
||||
rescue
|
||||
e in RuntimeError -> Logger.error("FAILED TO QUERY REMOTE EMOJO #{emojo_url} #{e}")
|
||||
end
|
||||
|
||||
true ->
|
||||
Logger.error("EMOJO COND FAIL #{emojo_shortcode} #{emojo_url}")
|
||||
true ->
|
||||
Logger.error("EMOJO COND FAIL #{emojo_shortcode} #{emojo_url}")
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
Logger.debug("EMOJI FILES: #{inspect(new_files)}")
|
||||
|
||||
if length(new_files) > 0 do
|
||||
Logger.debug("RELOADING EMOJI")
|
||||
Pleroma.Emoji.reload()
|
||||
else
|
||||
Logger.debug("NO EMOJI TO LOAD")
|
||||
end
|
||||
|
||||
Logger.debug("EMOJI FILES: #{inspect(new_files)}")
|
||||
|
||||
if length(new_files) > 0 do
|
||||
Logger.debug("RELOADING EMOJI")
|
||||
Pleroma.Emoji.reload()
|
||||
else
|
||||
Logger.debug("NO EMOJI TO LOAD")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue