aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorWilliam Pitcock <nenolod@dereferenced.org>2018-09-16 02:07:32 +0000
committerWilliam Pitcock <nenolod@dereferenced.org>2018-09-16 02:16:16 +0000
commita7d0ecdc7c901476f064a9d9fbad639742d3b509 (patch)
tree30834ba215413b1c92c25ea9a7a1be551aba7576 /lib
parentcd13fa17fd8d2c959b4a257a3bdcf52e7f61ddf2 (diff)
downloadpleroma-a7d0ecdc7c901476f064a9d9fbad639742d3b509.tar.gz
html: add policy which transforms inline images to pass through the media proxy
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/html.ex31
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/pleroma/html.ex b/lib/pleroma/html.ex
index 1eb0fdc00..ab62dd1da 100644
--- a/lib/pleroma/html.ex
+++ b/lib/pleroma/html.ex
@@ -142,3 +142,34 @@ defmodule Pleroma.HTML.Scrubber.Default do
Meta.strip_everything_not_covered()
end
+
+defmodule Pleroma.HTML.Transform.MediaProxy do
+ @moduledoc "Transforms inline image URIs to use MediaProxy."
+
+ alias Pleroma.Web.MediaProxy
+
+ def before_scrub(html), do: html
+
+ def scrub_attribute("img", {"src", "http" <> target}) do
+ media_url =
+ ("http" <> target)
+ |> MediaProxy.url()
+
+ {"src", media_url}
+ end
+
+ def scrub_attribute(tag, attribute), do: attribute
+
+ def scrub({"img", attributes, children}) do
+ attributes =
+ attributes
+ |> Enum.map(fn attr -> scrub_attribute("img", attr) end)
+ |> Enum.reject(&is_nil(&1))
+
+ {"img", attributes, children}
+ end
+
+ def scrub({tag, attributes, children}), do: {tag, attributes, children}
+ def scrub({tag, children}), do: children
+ def scrub(text), do: text
+end