forked from AkkomaGang/akkoma
Fix the issue with HTML scrubber
This commit is contained in:
parent
cd387f8693
commit
45ba10bf47
3 changed files with 34 additions and 10 deletions
|
@ -28,9 +28,13 @@ def filter_tags(html, scrubber), do: Scrubber.scrub(html, scrubber)
|
||||||
def filter_tags(html), do: filter_tags(html, nil)
|
def filter_tags(html), do: filter_tags(html, nil)
|
||||||
def strip_tags(html), do: Scrubber.scrub(html, Scrubber.StripTags)
|
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
|
def get_cached_scrubbed_html_for_object(content, scrubbers, object, module) do
|
||||||
key = "#{module}#{generate_scrubber_signature(scrubbers)}|#{object.id}"
|
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
|
end
|
||||||
|
|
||||||
def get_cached_stripped_html_for_object(content, object, module) do
|
def get_cached_stripped_html_for_object(content, object, module) do
|
||||||
|
@ -44,11 +48,20 @@ def get_cached_stripped_html_for_object(content, object, module) do
|
||||||
|
|
||||||
def ensure_scrubbed_html(
|
def ensure_scrubbed_html(
|
||||||
content,
|
content,
|
||||||
scrubbers
|
scrubbers,
|
||||||
|
_fake = false
|
||||||
) do
|
) do
|
||||||
{:commit, filter_tags(content, scrubbers)}
|
{:commit, filter_tags(content, scrubbers)}
|
||||||
end
|
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
|
defp generate_scrubber_signature(scrubber) when is_atom(scrubber) do
|
||||||
generate_scrubber_signature([scrubber])
|
generate_scrubber_signature([scrubber])
|
||||||
end
|
end
|
||||||
|
|
|
@ -44,6 +44,11 @@ def get_by_ap_id(ap_id) do
|
||||||
# Use this whenever possible, especially when walking graphs in an O(N) loop!
|
# Use this whenever possible, especially when walking graphs in an O(N) loop!
|
||||||
def normalize(%Activity{object: %Object{} = object}), do: object
|
def normalize(%Activity{object: %Object{} = object}), do: object
|
||||||
|
|
||||||
|
# A hack for fake activities
|
||||||
|
def normalize(%Activity{data: %{"object" => %{"fake" => true} = data}}) do
|
||||||
|
%Object{id: "pleroma:fake_object_id", data: data}
|
||||||
|
end
|
||||||
|
|
||||||
# Catch and log Object.normalize() calls where the Activity's child object is not
|
# Catch and log Object.normalize() calls where the Activity's child object is not
|
||||||
# preloaded.
|
# preloaded.
|
||||||
def normalize(%Activity{data: %{"object" => %{"id" => ap_id}}}) do
|
def normalize(%Activity{data: %{"object" => %{"id" => ap_id}}}) do
|
||||||
|
|
|
@ -150,14 +150,20 @@ def insert(map, local \\ true, fake \\ false) when is_map(map) do
|
||||||
{:ok, activity}
|
{:ok, activity}
|
||||||
|
|
||||||
{:fake, true, map, recipients} ->
|
{:fake, true, map, recipients} ->
|
||||||
{:ok,
|
map =
|
||||||
%Activity{
|
map
|
||||||
|
|> put_in(["object", "fake"], true)
|
||||||
|
|
||||||
|
activity = %Activity{
|
||||||
data: map,
|
data: map,
|
||||||
local: local,
|
local: local,
|
||||||
actor: map["actor"],
|
actor: map["actor"],
|
||||||
recipients: recipients,
|
recipients: recipients,
|
||||||
id: "pleroma:fakeid"
|
id: "pleroma:fakeid"
|
||||||
}}
|
}
|
||||||
|
|
||||||
|
# Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
|
||||||
|
{:ok, activity}
|
||||||
|
|
||||||
error ->
|
error ->
|
||||||
{:error, error}
|
{:error, error}
|
||||||
|
|
Loading…
Reference in a new issue