Fix the issue with HTML scrubber

This commit is contained in:
rinpatch 2019-04-01 11:55:59 +03:00
commit 45ba10bf47
3 changed files with 34 additions and 10 deletions

View file

@ -28,9 +28,13 @@ defmodule Pleroma.HTML do
def filter_tags(html), do: filter_tags(html, nil)
def strip_tags(html), do: Scrubber.scrub(html, Scrubber.StripTags)
# TODO: rename object to activity because that's what it is really working with
def get_cached_scrubbed_html_for_object(content, scrubbers, object, module) do
key = "#{module}#{generate_scrubber_signature(scrubbers)}|#{object.id}"
Cachex.fetch!(:scrubber_cache, key, fn _key -> ensure_scrubbed_html(content, scrubbers) end)
Cachex.fetch!(:scrubber_cache, key, fn _key ->
ensure_scrubbed_html(content, scrubbers, object.data["object"]["fake"] || false)
end)
end
def get_cached_stripped_html_for_object(content, object, module) do
@ -44,11 +48,20 @@ defmodule Pleroma.HTML do
def ensure_scrubbed_html(
content,
scrubbers
scrubbers,
_fake = false
) do
{:commit, filter_tags(content, scrubbers)}
end
def ensure_scrubbed_html(
content,
scrubbers,
_fake = true
) do
{:ignore, filter_tags(content, scrubbers)}
end
defp generate_scrubber_signature(scrubber) when is_atom(scrubber) do
generate_scrubber_signature([scrubber])
end