|
|
@ -3,12 +3,6 @@
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.RichMedia.Parser do
|
|
|
|
defmodule Pleroma.Web.RichMedia.Parser do
|
|
|
|
@parsers [
|
|
|
|
|
|
|
|
Pleroma.Web.RichMedia.Parsers.OGP,
|
|
|
|
|
|
|
|
Pleroma.Web.RichMedia.Parsers.TwitterCard,
|
|
|
|
|
|
|
|
Pleroma.Web.RichMedia.Parsers.OEmbed
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@hackney_options [
|
|
|
|
@hackney_options [
|
|
|
|
pool: :media,
|
|
|
|
pool: :media,
|
|
|
|
recv_timeout: 2_000,
|
|
|
|
recv_timeout: 2_000,
|
|
|
@ -16,6 +10,10 @@ defmodule Pleroma.Web.RichMedia.Parser do
|
|
|
|
with_body: true
|
|
|
|
with_body: true
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
defp parsers do
|
|
|
|
|
|
|
|
Pleroma.Config.get([:rich_media, :parsers])
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def parse(nil), do: {:error, "No URL provided"}
|
|
|
|
def parse(nil), do: {:error, "No URL provided"}
|
|
|
|
|
|
|
|
|
|
|
|
if Pleroma.Config.get(:env) == :test do
|
|
|
|
if Pleroma.Config.get(:env) == :test do
|
|
|
@ -48,7 +46,7 @@ defmodule Pleroma.Web.RichMedia.Parser do
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
defp maybe_parse(html) do
|
|
|
|
defp maybe_parse(html) do
|
|
|
|
Enum.reduce_while(@parsers, %{}, fn parser, acc ->
|
|
|
|
Enum.reduce_while(parsers(), %{}, fn parser, acc ->
|
|
|
|
case parser.parse(html, acc) do
|
|
|
|
case parser.parse(html, acc) do
|
|
|
|
{:ok, data} -> {:halt, data}
|
|
|
|
{:ok, data} -> {:halt, data}
|
|
|
|
{:error, _msg} -> {:cont, acc}
|
|
|
|
{:error, _msg} -> {:cont, acc}
|
|
|
|