Merge branch 'feature/s3-force-media-proxy' into 'develop'

s3 uploader: force public URIs through media proxy

See merge request pleroma/pleroma!403
This commit is contained in:
kaniini 2018-10-29 18:07:47 +00:00
commit 7ac701ccd2
3 changed files with 17 additions and 4 deletions

View File

@ -20,7 +20,8 @@ config :pleroma, Pleroma.Uploaders.Local,
config :pleroma, Pleroma.Uploaders.S3,
bucket: nil,
public_endpoint: "https://s3.amazonaws.com"
public_endpoint: "https://s3.amazonaws.com",
force_media_proxy: false
config :pleroma, :emoji, shortcode_globs: ["/emoji/custom/**/*.png"]

View File

@ -1,10 +1,13 @@
defmodule Pleroma.Uploaders.S3 do
alias Pleroma.Web.MediaProxy
@behaviour Pleroma.Uploaders.Uploader
def put_file(name, uuid, path, content_type, _should_dedupe) do
settings = Application.get_env(:pleroma, Pleroma.Uploaders.S3)
bucket = Keyword.fetch!(settings, :bucket)
public_endpoint = Keyword.fetch!(settings, :public_endpoint)
force_media_proxy = Keyword.fetch!(settings, :force_media_proxy)
{:ok, file_data} = File.read(path)
@ -19,7 +22,16 @@ defmodule Pleroma.Uploaders.S3 do
])
|> ExAws.request()
{:ok, "#{public_endpoint}/#{bucket}/#{s3_name}"}
url_base = "#{public_endpoint}/#{bucket}/#{s3_name}"
public_url =
if force_media_proxy do
MediaProxy.url(url_base)
else
url_base
end
{:ok, public_url}
end
defp encode(name) do

View File

@ -89,8 +89,8 @@ defmodule Pleroma.Web.CommonAPI.Utils do
def add_attachments(text, attachments) do
attachment_text =
Enum.map(attachments, fn
%{"url" => [%{"href" => href} | _]} ->
name = URI.decode(Path.basename(href))
%{"url" => [%{"href" => href} | _]} = attachment ->
name = attachment["name"] || URI.decode(Path.basename(href))
href = MediaProxy.url(href)
"<a href=\"#{href}\" class='attachment'>#{shortname(name)}</a>"