Apply suggestion to lib/pleroma/web/emoji_api/emoji_api_controller.ex

This commit is contained in:
vaartis 2019-09-11 16:00:48 +00:00 committed by Ekaterina Vaartis
parent 8f509e6d1e
commit cb125ffaf7

View file

@ -124,26 +124,22 @@ keeping it in cache for #{div(cache_ms, 1000)}s")
pack_dir = Path.join(@emoji_dir_path, name)
pack_file = Path.join(pack_dir, "pack.json")
if File.exists?(pack_file) do
pack = Jason.decode!(File.read!(pack_file))
if can_download?(pack, pack_dir) do
with {_, true} <- {:exists?, File.exists?(pack_file)},
pack = Jason.decode!(File.read!(pack_file)),
{_, true} <- {:can_download?, can_download?(pack, pack_dir)} do
zip_result = make_archive(name, pack, pack_dir)
conn
|> send_download({:binary, zip_result}, filename: "#{name}.zip")
send_download(conn, {:binary, zip_result}, filename: "#{name}.zip")
else
{:error,
{:can_download?, _} ->
conn
|> put_status(:forbidden)
|> text("Pack #{name} cannot be downloaded from this instance, either pack sharing\
was disabled for this pack or some files are missing")}
end
else
{:error,
was disabled for this pack or some files are missing")
{:exists?, _} ->
conn
|> put_status(:not_found)
|> text("Pack #{name} does not exist")}
|> text("Pack #{name} does not exist")
end
end