def fetch_data_for_activity(%Activity{data: %{"type" => "Create"}} = activity) do
with true <- Pleroma.Config.get([:rich_media, :enabled]),
%Object{} = object <- Object.normalize(activity),
+ false <- object.data["sensitive"] || false,
{:ok, page_url} <- HTML.extract_first_external_url(object, object.data["content"]),
:ok <- validate_page_url(page_url),
{:ok, rich_media} <- Parser.parse(page_url) do
defmodule Pleroma.Web.RichMedia.HelpersTest do
use Pleroma.DataCase
+ alias Pleroma.Object
alias Pleroma.Web.CommonAPI
import Pleroma.Factory
Pleroma.Config.put([:rich_media, :enabled], false)
end
+
+ test "refuses to crawl URLs from posts marked sensitive" do
+ user = insert(:user)
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "status" => "http://example.com/ogp",
+ "spoiler_text" => "."
+ })
+
+ %Object{} = object = Object.normalize(activity)
+
+ assert object.data["sensitive"]
+
+ Pleroma.Config.put([:rich_media, :enabled], true)
+
+ assert %{} = Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
+
+ Pleroma.Config.put([:rich_media, :enabled], false)
+ end
end