forked from AkkomaGang/akkoma
Apply suggestion to lib/pleroma/web/emoji_api/emoji_api_controller.ex
This commit is contained in:
parent
8f509e6d1e
commit
cb125ffaf7
1 changed files with 15 additions and 19 deletions
|
@ -124,26 +124,22 @@ def download_shared(conn, %{"name" => name}) do
|
||||||
pack_dir = Path.join(@emoji_dir_path, name)
|
pack_dir = Path.join(@emoji_dir_path, name)
|
||||||
pack_file = Path.join(pack_dir, "pack.json")
|
pack_file = Path.join(pack_dir, "pack.json")
|
||||||
|
|
||||||
if File.exists?(pack_file) do
|
with {_, true} <- {:exists?, File.exists?(pack_file)},
|
||||||
pack = Jason.decode!(File.read!(pack_file))
|
pack = Jason.decode!(File.read!(pack_file)),
|
||||||
|
{_, true} <- {:can_download?, can_download?(pack, pack_dir)} do
|
||||||
if can_download?(pack, pack_dir) do
|
|
||||||
zip_result = make_archive(name, pack, pack_dir)
|
zip_result = make_archive(name, pack, pack_dir)
|
||||||
|
send_download(conn, {:binary, zip_result}, filename: "#{name}.zip")
|
||||||
conn
|
|
||||||
|> send_download({:binary, zip_result}, filename: "#{name}.zip")
|
|
||||||
else
|
else
|
||||||
{:error,
|
{:can_download?, _} ->
|
||||||
conn
|
conn
|
||||||
|> put_status(:forbidden)
|
|> put_status(:forbidden)
|
||||||
|> text("Pack #{name} cannot be downloaded from this instance, either pack sharing\
|
|> text("Pack #{name} cannot be downloaded from this instance, either pack sharing\
|
||||||
was disabled for this pack or some files are missing")}
|
was disabled for this pack or some files are missing")
|
||||||
end
|
|
||||||
else
|
{:exists?, _} ->
|
||||||
{:error,
|
|
||||||
conn
|
conn
|
||||||
|> put_status(:not_found)
|
|> put_status(:not_found)
|
||||||
|> text("Pack #{name} does not exist")}
|
|> text("Pack #{name} does not exist")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue