Merge branch 'hardening/mastodon-rich-media' into 'develop'

rich media: minor hardening

See merge request pleroma/pleroma!717
This commit is contained in:
Haelwenn 2019-01-26 17:30:51 +00:00
commit 7175793304
1 changed files with 10 additions and 2 deletions

View File

@ -5,11 +5,19 @@ defmodule Pleroma.Web.RichMedia.Parser do
Pleroma.Web.RichMedia.Parsers.OEmbed Pleroma.Web.RichMedia.Parsers.OEmbed
] ]
def parse(nil), do: {:error, "No URL provided"}
if Mix.env() == :test do if Mix.env() == :test do
def parse(url), do: parse_url(url) def parse(url), do: parse_url(url)
else else
def parse(url), def parse(url) do
do: Cachex.fetch!(:rich_media_cache, url, fn _ -> parse_url(url) end) with {:ok, data} <- Cachex.fetch(:rich_media_cache, url, fn _ -> parse_url(url) end) do
data
else
_e ->
{:error, "Parsing error"}
end
end
end end
defp parse_url(url) do defp parse_url(url) do