From cbadf9d3333d3840d21cfcd3bd4f33d3b5b90445 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Sat, 2 Feb 2019 11:38:37 +0300 Subject: [PATCH 1/6] Fix rich media relative path --- lib/pleroma/web/mastodon_api/views/status_view.ex | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index d5b7e68c7..826563f74 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -184,6 +184,11 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do def render("card.json", %{rich_media: rich_media, page_url: page_url}) do page_url = rich_media[:url] || page_url page_url_data = URI.parse(page_url) + + image_url = + URI.merge(page_url_data, URI.parse(rich_media[:image])) + |> to_string + site_name = rich_media[:site_name] || page_url_data.host %{ @@ -191,7 +196,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do provider_name: site_name, provider_url: page_url_data.scheme <> "://" <> page_url_data.host, url: page_url, - image: rich_media[:image] |> MediaProxy.url(), + image: image_url |> MediaProxy.url(), title: rich_media[:title], description: rich_media[:description], pleroma: %{ From e4d18f328b738a2c3a953e721f0d350cfba20089 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Sat, 2 Feb 2019 11:53:46 +0300 Subject: [PATCH 2/6] merge only if page_url is an absolute path --- lib/pleroma/web/mastodon_api/views/status_view.ex | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index 826563f74..aa38784a6 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -186,8 +186,12 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do page_url_data = URI.parse(page_url) image_url = - URI.merge(page_url_data, URI.parse(rich_media[:image])) - |> to_string + if %URI{host: nil} = page_url_data do + rich_media[:image] + else + URI.merge(page_url_data, URI.parse(rich_media[:image])) + |> to_string + end site_name = rich_media[:site_name] || page_url_data.host From 833404f0f549a5c2ac58d43239217648cc354a6a Mon Sep 17 00:00:00 2001 From: rinpatch Date: Sat, 2 Feb 2019 12:04:18 +0300 Subject: [PATCH 3/6] Use with instead of if in the card --- lib/pleroma/web/mastodon_api/views/status_view.ex | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index aa38784a6..c8fde93ba 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -186,11 +186,12 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do page_url_data = URI.parse(page_url) image_url = - if %URI{host: nil} = page_url_data do + with %URI{host: nil} <- page_url_data do rich_media[:image] else - URI.merge(page_url_data, URI.parse(rich_media[:image])) - |> to_string + _ -> + URI.merge(page_url_data, URI.parse(rich_media[:image])) + |> to_string end site_name = rich_media[:site_name] || page_url_data.host From 68d461b3a9f3be58af85a7ae98ace2ebcbc616f2 Mon Sep 17 00:00:00 2001 From: rinpatch Date: Sat, 2 Feb 2019 12:24:24 +0300 Subject: [PATCH 4/6] Check if rich media uri is relative --- .../web/mastodon_api/views/status_view.ex | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/pleroma/web/mastodon_api/views/status_view.ex b/lib/pleroma/web/mastodon_api/views/status_view.ex index c8fde93ba..d1b11d4f1 100644 --- a/lib/pleroma/web/mastodon_api/views/status_view.ex +++ b/lib/pleroma/web/mastodon_api/views/status_view.ex @@ -182,17 +182,18 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do end def render("card.json", %{rich_media: rich_media, page_url: page_url}) do - page_url = rich_media[:url] || page_url - page_url_data = URI.parse(page_url) + page_url_data = + if rich_media[:url] != nil do + URI.merge(URI.parse(page_url), URI.parse(rich_media[:url])) + else + page_url + end + + page_url = page_url_data |> to_string image_url = - with %URI{host: nil} <- page_url_data do - rich_media[:image] - else - _ -> - URI.merge(page_url_data, URI.parse(rich_media[:image])) - |> to_string - end + URI.merge(page_url_data, URI.parse(rich_media[:image])) + |> to_string site_name = rich_media[:site_name] || page_url_data.host From 127f99ae18eea7732e8cb7756a102ca4c5beacca Mon Sep 17 00:00:00 2001 From: href Date: Mon, 4 Feb 2019 17:44:41 +0100 Subject: [PATCH 5/6] Mime: detect RIFF formats (wave, webp, avi) --- lib/pleroma/mime.ex | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/pleroma/mime.ex b/lib/pleroma/mime.ex index 84fb536e0..36771533f 100644 --- a/lib/pleroma/mime.ex +++ b/lib/pleroma/mime.ex @@ -102,10 +102,18 @@ defmodule Pleroma.MIME do "audio/ogg" end - defp check_mime_type(<<0x52, 0x49, 0x46, 0x46, _::binary>>) do + defp check_mime_type(<<"RIFF", _::binary-size(4), "WAVE", _::binary>>) do "audio/wav" end + defp check_mime_type(<<"RIFF", _::binary-size(4), "WEBP", _::binary>>) do + "image/webp" + end + + defp check_mime_type(<<"RIFF", _::binary-size(4), "AVI.", _::binary>>) do + "video/avi" + end + defp check_mime_type(_) do @default end From 4031c94a59dd36753d96666dadc1b32678d37c74 Mon Sep 17 00:00:00 2001 From: Karen Konou Date: Mon, 4 Feb 2019 18:26:56 +0100 Subject: [PATCH 6/6] fix hellthread threshold deprecation warning --- lib/pleroma/config/deprecation_warnings.ex | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/pleroma/config/deprecation_warnings.ex b/lib/pleroma/config/deprecation_warnings.ex index 0eb1833aa..7451fd0a7 100644 --- a/lib/pleroma/config/deprecation_warnings.ex +++ b/lib/pleroma/config/deprecation_warnings.ex @@ -12,8 +12,10 @@ defmodule Pleroma.Config.DeprecationWarnings do You are using the old configuration mechanism for the frontend. Please check config.md. """) end + end - if Pleroma.Config.get(:mrf_hellthread, :threshold) do + def check_hellthread_threshold do + if Pleroma.Config.get([:mrf_hellthread, :threshold]) do Logger.warn(""" !!!DEPRECATION WARNING!!! You are using the old configuration mechanism for the hellthread filter. Please check config.md. @@ -23,5 +25,6 @@ defmodule Pleroma.Config.DeprecationWarnings do def warn do check_frontend_config_mechanism() + check_hellthread_threshold() end end