mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-30 14:57:59 +01:00
fixes for camo images
This commit is contained in:
parent
70c95800ca
commit
796d07f393
1 changed files with 20 additions and 12 deletions
|
@ -1,20 +1,28 @@
|
||||||
defmodule Camo.Image do
|
defmodule Camo.Image do
|
||||||
def image_url(input) 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
|
||||||
input
|
is_nil(uri.host) ->
|
||||||
else
|
""
|
||||||
camo_digest = :crypto.hmac(:sha, camo_key(), input) |> Base.encode16(case: :lower)
|
|
||||||
|
|
||||||
camo_uri = %URI{
|
is_nil(camo_key()) ->
|
||||||
host: camo_host(),
|
input
|
||||||
path: "/" <> camo_digest,
|
|
||||||
query: URI.encode_query(url: input),
|
|
||||||
scheme: "https"
|
|
||||||
}
|
|
||||||
|
|
||||||
URI.to_string(camo_uri)
|
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{
|
||||||
|
host: camo_host(),
|
||||||
|
path: "/" <> camo_digest,
|
||||||
|
query: URI.encode_query(url: input),
|
||||||
|
scheme: "https"
|
||||||
|
}
|
||||||
|
|
||||||
|
URI.to_string(camo_uri)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue