+ defp disabled?, do: !Config.get([:media_proxy, :enabled], false)
+
+ defp local?(url), do: String.starts_with?(url, Pleroma.Web.base_url())
+
+ defp whitelisted?(url) do
+ %{host: domain} = URI.parse(url)
+
+ mediaproxy_whitelist_domains =
+ [:media_proxy, :whitelist]
+ |> Config.get()
+ |> Enum.map(&maybe_get_domain_from_url/1)
+
+ whitelist_domains =
+ if base_url = Config.get([Upload, :base_url]) do
+ %{host: base_domain} = URI.parse(base_url)
+ [base_domain | mediaproxy_whitelist_domains]
+ else
+ mediaproxy_whitelist_domains
+ end
+
+ domain in whitelist_domains
+ end
+
+ defp maybe_get_domain_from_url("http" <> _ = url) do
+ URI.parse(url).host
+ end
+
+ defp maybe_get_domain_from_url(domain), do: domain
+
+ def encode_url(url) do
+ base64 = Base.url_encode64(url, @base64_opts)
+
+ sig64 =
+ base64
+ |> signed_url
+ |> Base.url_encode64(@base64_opts)
+
+ build_url(sig64, base64, filename(url))
+ end
+