fix(rich media): fix error handling when resource preview URL leads to empty parsed data

Closes #1279

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2023-05-26 15:55:17 +02:00
parent 878cd84bc4
commit 850b4e2a73
3 changed files with 28 additions and 27 deletions

View File

@@ -67,8 +67,8 @@ defmodule Mobilizon.Service.RichMedia.Parsers.OEmbed do
{:ok, data} <- Jason.decode(json),
data <-
data
|> Map.new(fn {k, v} -> {String.to_existing_atom(k), String.trim(v)} end)
|> Map.take(@oembed_allowed_attributes) do
|> Map.new(fn {k, v} -> {k, if(is_binary(v), do: String.trim(v), else: v)} end)
|> Map.take(Enum.map(@oembed_allowed_attributes, &to_string/1)) do
{:ok, data}
end
end