X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;ds=inline;f=lib%2Fpleroma%2Fupload.ex;h=6547113514b15fe3d74770f2fde3869930265223;hb=f0dcc1ca692fb5d6a5aca4f8a9ccb255baef9c1d;hp=3061b2aed7fae26597419a2381d01f7d62702cc5;hpb=530fb5b29ebd414781c703e4b41d204135f3efe7;p=akkoma
diff --git a/lib/pleroma/upload.ex b/lib/pleroma/upload.ex
index 3061b2aed..654711351 100644
--- a/lib/pleroma/upload.ex
+++ b/lib/pleroma/upload.ex
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors
+# Copyright © 2017-2021 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Upload do
@@ -131,12 +131,7 @@ defmodule Pleroma.Upload do
uploader: Keyword.get(opts, :uploader, Pleroma.Config.get([__MODULE__, :uploader])),
filters: Keyword.get(opts, :filters, Pleroma.Config.get([__MODULE__, :filters])),
description: Keyword.get(opts, :description),
- base_url:
- Keyword.get(
- opts,
- :base_url,
- Pleroma.Config.get([__MODULE__, :base_url], Pleroma.Web.base_url())
- )
+ base_url: base_url()
}
end
@@ -217,14 +212,7 @@ defmodule Pleroma.Upload do
""
end
- prefix =
- if is_nil(Pleroma.Config.get([__MODULE__, :base_url])) do
- "media"
- else
- ""
- end
-
- [base_url, prefix, path]
+ [base_url, path]
|> Path.join()
end
@@ -237,22 +225,33 @@ defmodule Pleroma.Upload do
case uploader do
Pleroma.Uploaders.Local ->
- cond do
- !is_nil(upload_base_url) ->
- upload_base_url
+ upload_base_url || Pleroma.Web.base_url() <> "/media/"
- true ->
- Pleroma.Web.base_url() <> "/media/"
- end
+ Pleroma.Uploaders.S3 ->
+ bucket = Config.get([Pleroma.Uploaders.S3, :bucket])
+ truncated_namespace = Config.get([Pleroma.Uploaders.S3, :truncated_namespace])
+ namespace = Config.get([Pleroma.Uploaders.S3, :bucket_namespace])
- _ ->
- cond do
- !is_nil(public_endpoint) ->
- public_endpoint
+ bucket_with_namespace =
+ cond do
+ !is_nil(truncated_namespace) ->
+ truncated_namespace
- true ->
- upload_base_url
+ !is_nil(namespace) ->
+ namespace <> ":" <> bucket
+
+ true ->
+ bucket
+ end
+
+ if public_endpoint do
+ Path.join([public_endpoint, bucket_with_namespace])
+ else
+ Path.join([upload_base_url, bucket_with_namespace])
end
+
+ _ ->
+ public_endpoint || upload_base_url || Pleroma.Web.base_url() <> "/media/"
end
end
end