summaryrefslogtreecommitdiff
path: root/lib/lsg_irc/link_plugin.ex
diff options
context:
space:
mode:
Diffstat (limited to 'lib/lsg_irc/link_plugin.ex')
-rw-r--r--lib/lsg_irc/link_plugin.ex11
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/lsg_irc/link_plugin.ex b/lib/lsg_irc/link_plugin.ex
index ced80b2..0c785a0 100644
--- a/lib/lsg_irc/link_plugin.ex
+++ b/lib/lsg_irc/link_plugin.ex
@@ -182,13 +182,13 @@ defmodule LSG.IRC.LinkPlugin do
case get_body(url, 30_000_000, client, handler, <<>>) do
{:ok, _} = ok -> ok
:error ->
- {:ok, "file: #{content_type}, size: #{length} bytes"}
+ {:ok, "file: #{content_type}, size: #{human_size(length)}"}
end
#String.starts_with?(content_type, "text/html") && length <= 30_000_000 ->
# get_body(url, 30_000_000, client, <<>>)
true ->
:hackney.close(client)
- {:ok, "file: #{content_type}, size: #{length} bytes"}
+ {:ok, "file: #{content_type}, size: #{human_size(length)}"}
end
end
@@ -256,4 +256,11 @@ defmodule LSG.IRC.LinkPlugin do
{:ok, [uri], "-> #{URI.to_string(uri)}"}
end
+
+ defp human_size(bytes) do
+ bytes
+ |> FileSize.new(:b)
+ |> FileSize.scale()
+ |> FileSize.format()
+ end
end