projects
/
akkoma
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'develop' into update-oauth-template
[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..e4595800c2f04afebbb40b381d5a28aa2eaf9b8a 100644
(file)
--- a/
lib/pleroma/web/rich_media/parser.ex
+++ b/
lib/pleroma/web/rich_media/parser.ex
@@
-9,6
+9,13
@@
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"}
if Mix.env() == :test do
def parse(nil), do: {:error, "No URL provided"}
if Mix.env() == :test 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)