summaryrefslogtreecommitdiff
path: root/lib/lsg_irc
diff options
context:
space:
mode:
authorhref <href@random.sh>2021-09-02 00:55:52 +0200
committerhref <href@random.sh>2021-09-02 00:55:52 +0200
commit1e31a281156c2b25ca21ecad6fbbc1c529145242 (patch)
treee0008680bc70103005383a3694404450da335d7c /lib/lsg_irc
parentlink/youtube: use yewtu.be instead of invidio.us (diff)
link: humanize file size
Diffstat (limited to 'lib/lsg_irc')
-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