fixes for camo images

This commit is contained in:
byte[] 2021-03-22 12:53:23 -04:00
parent 70c95800ca
commit 796d07f393

View file

@ -1,10 +1,18 @@
defmodule Camo.Image do
def image_url(input) do
%{host: host} = URI.parse(input)
uri = URI.parse(input)
if !host or String.ends_with?(host, cdn_host()) or is_nil(camo_key()) do
cond do
is_nil(uri.host) ->
""
is_nil(camo_key()) ->
input
else
uri.host in [cdn_host(), camo_host()] ->
URI.to_string(update_in(uri.scheme, fn _ -> "https" end))
true ->
camo_digest = :crypto.hmac(:sha, camo_key(), input) |> Base.encode16(case: :lower)
camo_uri = %URI{