projects
/
akkoma
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'develop' of https://git.pleroma.social/pleroma/pleroma into develop
[akkoma]
/
lib
/
pleroma
/
web
/
rich_media
/
parser.ex
diff --git
a/lib/pleroma/web/rich_media/parser.ex
b/lib/pleroma/web/rich_media/parser.ex
index b33411cc7a1d95f67aa43942a24ab8fde36c23da..21cd47890abc8a17fa583241cdd8f970a91d3be4 100644
(file)
--- a/
lib/pleroma/web/rich_media/parser.ex
+++ b/
lib/pleroma/web/rich_media/parser.ex
@@
-9,9
+9,16
@@
defmodule Pleroma.Web.RichMedia.Parser do
Pleroma.Web.RichMedia.Parsers.OEmbed
]
Pleroma.Web.RichMedia.Parsers.OEmbed
]
+ @hackney_options [
+ pool: :media,
+ recv_timeout: 2_000,
+ max_body: 2_000_000,
+ with_body: true
+ ]
+
def parse(nil), do: {:error, "No URL provided"}
def parse(nil), do: {:error, "No URL provided"}
- if
Mix.env(
) == :test do
+ if
Pleroma.Config.get(:env
) == :test do
def parse(url), do: parse_url(url)
else
def parse(url) do
def parse(url), do: parse_url(url)
else
def parse(url) do
@@
-28,9
+35,12
@@
defmodule Pleroma.Web.RichMedia.Parser do
defp parse_url(url) do
try do
defp parse_url(url) do
try do
- {:ok, %Tesla.Env{body: html}} = Pleroma.HTTP.get(url, [], adapter:
[pool: :media]
)
+ {:ok, %Tesla.Env{body: html}} = Pleroma.HTTP.get(url, [], adapter:
@hackney_options
)
- html |> maybe_parse() |> clean_parsed_data() |> check_parsed_data()
+ html
+ |> maybe_parse()
+ |> clean_parsed_data()
+ |> check_parsed_data()
rescue
e ->
{:error, "Parsing error: #{inspect(e)}"}
rescue
e ->
{:error, "Parsing error: #{inspect(e)}"}
@@
-54,20
+64,12
@@
defmodule Pleroma.Web.RichMedia.Parser do
{:error, "Found metadata was invalid or incomplete: #{inspect(data)}"}
end
{:error, "Found metadata was invalid or incomplete: #{inspect(data)}"}
end
- defp string_is_valid_unicode(data) do
- data
- |> :unicode.characters_to_binary()
- |> clean_string()
- end
-
- defp clean_string({:error, _, _}), do: {:error, "Invalid data"}
- defp clean_string(data), do: {:ok, data}
-
defp clean_parsed_data(data) do
data
defp clean_parsed_data(data) do
data
- |> Enum.reject(fn {_, val} ->
- case string_is_valid_unicode(val) do
- {:ok, _} -> false
+ |> Enum.reject(fn {key, val} ->
+ with {:ok, _} <- Jason.encode(%{key => val}) do
+ false
+ else
_ -> true
end
end)
_ -> true
end
end)