1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Activity.HTML do
9 @cachex Pleroma.Config.get([:cachex, :provider], Cachex)
11 def get_cached_scrubbed_html_for_activity(
16 callback \\ fn x -> x end
18 key = "#{key}#{generate_scrubber_signature(scrubbers)}|#{activity.id}"
20 @cachex.fetch!(:scrubber_cache, key, fn _key ->
21 object = Object.normalize(activity, fetch: false)
22 HTML.ensure_scrubbed_html(content, scrubbers, object.data["fake"] || false, callback)
26 def get_cached_stripped_html_for_activity(content, activity, key) do
27 get_cached_scrubbed_html_for_activity(
29 FastSanitize.Sanitizer.StripTags,
32 &HtmlEntities.decode/1
36 defp generate_scrubber_signature(scrubber) when is_atom(scrubber) do
37 generate_scrubber_signature([scrubber])
40 defp generate_scrubber_signature(scrubbers) do
41 Enum.reduce(scrubbers, "", fn scrubber, signature ->
42 "#{signature}#{to_string(scrubber)}"