mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2026-02-16 01:27:07 +00:00
Handle invalid cards
This commit is contained in:
parent
ebeb9c6bc9
commit
95196fb5ac
2 changed files with 16 additions and 18 deletions
|
|
@ -370,9 +370,11 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
|
|||
end
|
||||
|
||||
def render("card.json", %Embed{url: _, meta: _} = embed) do
|
||||
embed
|
||||
|> Card.parse()
|
||||
|> Card.to_map()
|
||||
with {:ok, %Card{} = card} <- Card.parse(embed) do
|
||||
Card.to_map(card)
|
||||
else
|
||||
_ -> nil
|
||||
end
|
||||
end
|
||||
|
||||
def render("card.json", %Card{} = card), do: Card.to_map(card)
|
||||
|
|
|
|||
|
|
@ -41,32 +41,28 @@ defmodule Pleroma.Web.RichMedia.Parser.Card do
|
|||
image: oembed["thumbnail_url"] |> proxy(),
|
||||
embed_url: oembed["url"] |> proxy()
|
||||
}
|
||||
|> validate()
|
||||
end
|
||||
|
||||
def parse(%{url: url} = embed) do
|
||||
title = get_title(embed)
|
||||
|
||||
if is_binary(title) do
|
||||
%Card{
|
||||
url: url,
|
||||
title: title,
|
||||
description: get_description(embed),
|
||||
type: "link",
|
||||
image: get_image(embed) |> proxy()
|
||||
}
|
||||
else
|
||||
nil
|
||||
end
|
||||
%Card{
|
||||
url: url,
|
||||
title: get_title(embed),
|
||||
description: get_description(embed),
|
||||
type: "link",
|
||||
image: get_image(embed) |> proxy()
|
||||
}
|
||||
|> validate()
|
||||
end
|
||||
|
||||
def parse(_), do: nil
|
||||
def parse(card), do: {:error, {:invalid_metadata, card}}
|
||||
|
||||
defp get_title(embed) do
|
||||
case embed do
|
||||
%{meta: %{"twitter:title" => title}} when is_binary(title) and title != "" -> title
|
||||
%{meta: %{"og:title" => title}} when is_binary(title) and title != "" -> title
|
||||
%{title: title} when is_binary(title) and title != "" -> title
|
||||
_ -> ""
|
||||
_ -> nil
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue