logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

media_proxy.ex (966B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.HTML.Transform.MediaProxy do
  5. @moduledoc "Transforms inline image URIs to use MediaProxy."
  6. alias Pleroma.Web.MediaProxy
  7. def before_scrub(html), do: html
  8. def scrub_attribute(:img, {"src", "http" <> target}) do
  9. media_url =
  10. ("http" <> target)
  11. |> MediaProxy.url()
  12. {"src", media_url}
  13. end
  14. def scrub_attribute(_tag, attribute), do: attribute
  15. def scrub({:img, attributes, children}) do
  16. attributes =
  17. attributes
  18. |> Enum.map(fn attr -> scrub_attribute(:img, attr) end)
  19. |> Enum.reject(&is_nil(&1))
  20. {:img, attributes, children}
  21. end
  22. def scrub({:comment, _text, _children}), do: ""
  23. def scrub({tag, attributes, children}), do: {tag, attributes, children}
  24. def scrub({_tag, children}), do: children
  25. def scrub(text), do: text
  26. end