diff --git a/README.md b/README.md index a261603..bf7ea7a 100644 --- a/README.md +++ b/README.md @@ -2921,6 +2921,22 @@ you should install the package `libmagic-dev`. > - Mac: https://gist.github.com/eparreno/1845561 > - Windows: https://github.com/nscaife/file-windows > - Linux: https://zoomadmin.com/HowToInstall/UbuntuPackage/libmagic-dev +> +> **Definitely read `gen_magic`'s installation section in https://github.com/evadne/gen_magic#installation**. +> You may need to perform additional steps. + +You'll need to add [`gen_magic`](https://github.com/evadne/gen_magic) +to `mix.exs`. +This dependency will allow us to access `libmagic` +through `Elixir`. + +```elixir +def deps do + [ + {:gen_magic, "~> 1.1.1"} + ] +end +``` In the `Application` module, you should add the `GenMagic` daemon (the C lib is loaded once for all and referenced by its name). @@ -3011,7 +3027,7 @@ def handle_progress(:image_list, entry, socket) when entry.done? do with %{tensor: tensor, image_info: image_info} <- consume_uploaded_entry(socket, entry, fn %{} = meta -> with {:magic, {:ok, %{mime_type: mime}}} <- - {:magic, magic_check(path)} |> dbg(), + {:magic, magic_check(path)}, file_binary <- File.read!(path), {:image_info, {mimetype, width, height, _variant}} <- {:image_info, ExImageInfo.info(file_binary)}, diff --git a/lib/app_web/live/page_live.ex b/lib/app_web/live/page_live.ex index a4ee40f..57cb8a9 100644 --- a/lib/app_web/live/page_live.ex +++ b/lib/app_web/live/page_live.ex @@ -127,7 +127,7 @@ defmodule AppWeb.PageLive do with %{tensor: tensor, image_info: image_info} <- consume_uploaded_entry(socket, entry, fn %{path: path} -> with {:magic, {:ok, %{mime_type: mime}}} <- - {:magic, magic_check(path)} |> dbg(), + {:magic, magic_check(path)}, file_binary <- File.read!(path), {:image_info, {mimetype, width, height, _variant}} <- {:image_info, ExImageInfo.info(file_binary)}, diff --git a/test/app_web/live/page_live_test.exs b/test/app_web/live/page_live_test.exs index c82c487..a063b76 100644 --- a/test/app_web/live/page_live_test.exs +++ b/test/app_web/live/page_live_test.exs @@ -93,12 +93,12 @@ defmodule AppWeb.PageLiveTest do test "check MIME type", %{conn: _conn} do path = [:code.priv_dir(:app), "static", "images", "test.png"] |> Path.join() - file = build_upload(path, "image/xyz") + _file = build_upload(path, "image/xyz") - assert AppWeb.PageLive.magic_check(path) == {:error, "not acceptable"} + assert AppWeb.PageLive.magic_check(path) == {:error, "Not acceptable."} accepted_mime = ~w(image/jpeg image/jpg image/png image/webp) - assert App.Image.gen_magic_eval(path, accepted_mime) == {:error, "not acceptable"} + assert App.Image.gen_magic_eval(path, accepted_mime) == {:error, "Not acceptable."} assert App.Image.gen_magic_eval("", accepted_mime) == {:error, "invalid command"} end