X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fpleroma%2Fuploaders%2Fs3.ex;h=e7de3f3e0de84da366987a3b0a89ca9429080c20;hb=4e72762322a5616ce426df62888ee3bc7af19dc8;hp=19832a7ecc456e38390d1d931370bb1402d3a2dd;hpb=c443c9bd72b04b8a24d904bc20fde0d4ffca71d7;p=akkoma diff --git a/lib/pleroma/uploaders/s3.ex b/lib/pleroma/uploaders/s3.ex index 19832a7ec..e7de3f3e0 100644 --- a/lib/pleroma/uploaders/s3.ex +++ b/lib/pleroma/uploaders/s3.ex @@ -1,21 +1,34 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2019 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Uploaders.S3 do @behaviour Pleroma.Uploaders.Uploader require Logger - # The file name is re-encoded with S3's constraints here to comply with previous links with less strict filenames + # The file name is re-encoded with S3's constraints here to comply with previous + # links with less strict filenames def get_file(file) do config = Pleroma.Config.get([__MODULE__]) + bucket = Keyword.fetch!(config, :bucket) + + bucket_with_namespace = + if namespace = Keyword.get(config, :bucket_namespace) do + namespace <> ":" <> bucket + else + bucket + end {:ok, {:url, Path.join([ Keyword.fetch!(config, :public_endpoint), - Keyword.fetch!(config, :bucket), + bucket_with_namespace, strict_encode(URI.decode(file)) ])}} end - def put_file(upload = %Pleroma.Upload{}) do + def put_file(%Pleroma.Upload{} = upload) do config = Pleroma.Config.get([__MODULE__]) bucket = Keyword.get(config, :bucket)