working code
This commit is contained in:
parent
8d5ce6a3df
commit
8d51aae70c
|
@ -20,40 +20,17 @@ defmodule Pleroma.Web.ActivityPub.MRF.StealEmojiPolicy do
|
||||||
for {emojo_shortcode, emojo_url} <- foreign_emoji,
|
for {emojo_shortcode, emojo_url} <- foreign_emoji,
|
||||||
!has_emojo(installed_emoji, emojo_shortcode) do
|
!has_emojo(installed_emoji, emojo_shortcode) do
|
||||||
Logger.debug("HANDLING EMOJO")
|
Logger.debug("HANDLING EMOJO")
|
||||||
cond do
|
|
||||||
String.contains?(emojo_shortcode, "/") ->
|
|
||||||
Logger.error("BAD EMOJO SHORTCODE: #{emojo_shortcode}")
|
|
||||||
|
|
||||||
!String.starts_with(emojo_url, "https://") ->
|
|
||||||
Logger.error("BAD EMOJO URL: #{emojo_url}")
|
|
||||||
|
|
||||||
true ->
|
|
||||||
Logger.debug("GOOD EMOJO")
|
|
||||||
remote_emojo = HTTPoison.get!(emojo_url)
|
remote_emojo = HTTPoison.get!(emojo_url)
|
||||||
|
|
||||||
if remote_emojo.status_code == 200 do
|
|
||||||
with {:ok, current_dir} <- File.cwd() do
|
with {:ok, current_dir} <- File.cwd() do
|
||||||
new_file =
|
new_file = current_dir <> "/priv/static/emoji/stolen/" <> emojo_shortcode <> Path.extname(emojo_url)
|
||||||
current_dir <>
|
|
||||||
"/priv/static/emoji/stolen/" <> emojo_shortcode <> Path.extname(emojo_url)
|
|
||||||
|
|
||||||
try do
|
|
||||||
{:ok, file} = File.open(new_file, [:write])
|
{:ok, file} = File.open(new_file, [:write])
|
||||||
IO.binwrite(file, remote_emojo.body)
|
IO.binwrite(file, remote_emojo.body)
|
||||||
File.close(file)
|
File.close(file)
|
||||||
Logger.debug("SAVED EMOJO")
|
Logger.debug("SAVED EMOJO")
|
||||||
rescue
|
|
||||||
RuntimeError ->
|
|
||||||
_ = "Error"
|
|
||||||
Logger.error("FAILED TO SAVE EMOJO: #{new_file}")
|
|
||||||
end
|
|
||||||
|
|
||||||
new_file
|
new_file
|
||||||
end
|
end
|
||||||
else
|
|
||||||
Logger.error("FAILED TO DOWNLOAD EMOJO: #{emojo_url}")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
Logger.debug("EMOJI FILES: #{inspect(new_files)}")
|
Logger.debug("EMOJI FILES: #{inspect(new_files)}")
|
||||||
|
|
Loading…
Reference in New Issue