X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fuploaders%2Fs3.ex;h=40a836460b6f18744cc77058e7ab404e30ac3208;hb=48b95a9b954b6d9e1b6f98097b35fcca4172c8a0;hp=95f20be6769c5af042e2bcd88e3ac49f0664ab7f;hpb=709816a0f891d6c26c43b54577a3b727c1fe4af6;p=akkoma diff --git a/lib/pleroma/uploaders/s3.ex b/lib/pleroma/uploaders/s3.ex index 95f20be67..40a836460 100644 --- a/lib/pleroma/uploaders/s3.ex +++ b/lib/pleroma/uploaders/s3.ex @@ -1,24 +1,40 @@ defmodule Pleroma.Uploaders.S3 do + alias Pleroma.Web.MediaProxy - def put_file(name, uuid, path, content_type) do + @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) File.rm!(path) - s3_name = "#{uuid}/#{name}" + s3_name = "#{uuid}/#{encode(name)}" - {:ok, result} = + {:ok, _} = ExAws.S3.put_object(bucket, s3_name, file_data, [ {:acl, :public_read}, {:content_type, content_type} ]) |> ExAws.request() - "#{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 + String.replace(name, ~r/[^0-9a-zA-Z!.*'()_-]/, "-") end end