Only find SHA256 for packs that are shared
authorEkaterina Vaartis <vaartis@cock.li>
Sun, 11 Aug 2019 20:24:23 +0000 (23:24 +0300)
committerEkaterina Vaartis <vaartis@cock.li>
Wed, 18 Sep 2019 21:16:33 +0000 (00:16 +0300)
lib/pleroma/web/emoji_api/emoji_api_controller.ex

index 7ef9b543d33bc343d1da0d3314acad5e2397da07..915059783d2cf4871793f9ea073f1a4b519f46e0 100644 (file)
@@ -36,13 +36,19 @@ defmodule Pleroma.Web.EmojiAPI.EmojiAPIController do
           |> Enum.map(fn {name, pack} ->
             pack_path = Path.join(@emoji_dir_path, name)
 
-            archive_for_sha = make_archive(name, pack, pack_path)
-            archive_sha = :crypto.hash(:sha256, archive_for_sha) |> Base.encode16()
-
-            {name,
-             pack
-             |> put_in(["pack", "can-download"], can_download?(pack, pack_path))
-             |> put_in(["pack", "download-sha256"], archive_sha)}
+            if can_download?(pack, pack_path) do
+              archive_for_sha = make_archive(name, pack, pack_path)
+              archive_sha = :crypto.hash(:sha256, archive_for_sha) |> Base.encode16()
+
+              {name,
+               pack
+               |> put_in(["pack", "can-download"], true)
+               |> put_in(["pack", "download-sha256"], archive_sha)}
+            else
+              {name,
+               pack
+               |> put_in(["pack", "can-download"], false)}
+            end
           end)
           |> Enum.into(%{})
       end