Page MenuHomePhorge

No OneTemporary

Size
1 KB
Referenced Files
None
Subscribers
None
diff --git a/lib/captcha.ex b/lib/captcha.ex
index caed0ca..8863df6 100644
--- a/lib/captcha.ex
+++ b/lib/captcha.ex
@@ -1,19 +1,8 @@
defmodule Captcha do
- # allow customize receive timeout, default: 10_000
- def get(timeout \\ 1_000) do
- pid = Port.open({:spawn, Path.join(:code.priv_dir(:captcha), "captcha")}, [:binary])
-
- # Allow set receive timeout
- receive do
- {^pid, {:data, data}} ->
- <<text::bytes-size(5), img::binary>> = data
- {:ok, text, img}
-
- other ->
- other
- after
- timeout ->
- {:error, :timeout}
+ def get() do
+ case System.cmd(Application.app_dir(:captcha, "priv/captcha"), []) do
+ {<<text::bytes-size(5), img::binary>>, 0} -> {:ok, text, img}
+ _other -> :error
end
end
end
diff --git a/test/elixir_captcha_test.exs b/test/elixir_captcha_test.exs
index ddf2620..9977049 100644
--- a/test/elixir_captcha_test.exs
+++ b/test/elixir_captcha_test.exs
@@ -1,12 +1,8 @@
defmodule CaptchaTest do
use ExUnit.Case
doctest Captcha
test "successfully generates an image" do
assert {:ok, _, _} = Captcha.get()
end
-
- test "respects the timeout" do
- assert {:error, :timeout} = Captcha.get(0)
- end
end

File Metadata

Mime Type
text/x-diff
Expires
Fri, Nov 22, 11:40 PM (1 d, 14 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
38403
Default Alt Text
(1 KB)

Event Timeline