Skip to content

Commit

Permalink
fix: Adding section for installing homebrew and fixing tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
LuchoTurtle committed Dec 27, 2023
1 parent 07d8687 commit 84be1de
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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)},
Expand Down
2 changes: 1 addition & 1 deletion lib/app_web/live/page_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)},
Expand Down
6 changes: 3 additions & 3 deletions test/app_web/live/page_live_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 84be1de

Please sign in to comment.