X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;ds=inline;f=lib%2Fpleroma%2Fupload.ex;h=6547113514b15fe3d74770f2fde3869930265223;hb=210aa42f74494864d70f97711204938cbcc4a19a;hp=db2cc1dae278009701222528e3bd159a7b7a494e;hpb=d8d4e962304c5424de4d171d25445b7135a67a09;p=akkoma
diff --git a/lib/pleroma/upload.ex b/lib/pleroma/upload.ex
index db2cc1dae..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
@@ -31,6 +31,7 @@ defmodule Pleroma.Upload do
"""
alias Ecto.UUID
+ alias Pleroma.Config
require Logger
@type source ::
@@ -130,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
@@ -216,16 +212,46 @@ 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
defp url_from_spec(_upload, _base_url, {:url, url}), do: url
+
+ def base_url do
+ uploader = Config.get([Pleroma.Upload, :uploader])
+ upload_base_url = Config.get([Pleroma.Upload, :base_url])
+ public_endpoint = Config.get([uploader, :public_endpoint])
+
+ case uploader do
+ Pleroma.Uploaders.Local ->
+ upload_base_url || Pleroma.Web.base_url() <> "/media/"
+
+ 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])
+
+ bucket_with_namespace =
+ cond do
+ !is_nil(truncated_namespace) ->
+ truncated_namespace
+
+ !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