aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvaartis <vaartis@cock.li>2019-09-11 16:00:48 +0000
committerEkaterina Vaartis <vaartis@cock.li>2019-09-19 00:16:33 +0300
commitcb125ffaf7f744e60fc134ef6b7b847d3838922a (patch)
treeb422f4899b635a6ac2e34faa7325611309eb7ccf
parent8f509e6d1ee8955fc430d1f4ed7929ba0d91177c (diff)
downloadpleroma-cb125ffaf7f744e60fc134ef6b7b847d3838922a.tar.gz
Apply suggestion to lib/pleroma/web/emoji_api/emoji_api_controller.ex
-rw-r--r--lib/pleroma/web/emoji_api/emoji_api_controller.ex32
1 files changed, 14 insertions, 18 deletions
diff --git a/lib/pleroma/web/emoji_api/emoji_api_controller.ex b/lib/pleroma/web/emoji_api/emoji_api_controller.ex
index 9e0ff0b28..28eaf5ae3 100644
--- a/lib/pleroma/web/emoji_api/emoji_api_controller.ex
+++ b/lib/pleroma/web/emoji_api/emoji_api_controller.ex
@@ -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
- zip_result = make_archive(name, pack, pack_dir)
+ 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)
+ send_download(conn, {:binary, zip_result}, filename: "#{name}.zip")
+ else
+ {: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")
+ {:exists?, _} ->
conn
- |> send_download({:binary, zip_result}, filename: "#{name}.zip")
- else
- {:error,
- 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,
- conn
- |> put_status(:not_found)
- |> text("Pack #{name} does not exist")}
+ |> put_status(:not_found)
+ |> text("Pack #{name} does not exist")
end
end