Don't error out if we're not using the local uploader

This commit is contained in:
FloatingGhost 2024-04-02 11:36:26 +01:00
parent f592090206
commit b5d97e7d85
3 changed files with 52 additions and 23 deletions

View file

@ -42,6 +42,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## Upgrade Notes
- As mentioned in "Changed", `Pleroma.Upload, :base_url` **MUST** be configured. Uploads will fail without it.
- Akkoma will refuse to start if this is not set.
- Same with media proxy.
## 2024.02

View file

@ -341,9 +341,10 @@ def check_uploders_s3_public_endpoint do
end
def check_uploader_base_url_set() do
uses_local_uploader? = Config.get([Pleroma.Upload, :uploader]) == Pleroma.Uploaders.Local
base_url = Pleroma.Config.get([Pleroma.Upload, :base_url])
if base_url do
if base_url || !uses_local_uploader? do
:ok
else
Logger.error("""
@ -361,6 +362,8 @@ def check_uploader_base_url_set() do
end
def check_uploader_base_url_is_not_base_domain() do
uses_local_uploader? = Config.get([Pleroma.Upload, :uploader]) == Pleroma.Uploaders.Local
uploader_host =
[Pleroma.Upload, :base_url]
|> Pleroma.Config.get()
@ -372,7 +375,7 @@ def check_uploader_base_url_is_not_base_domain() do
|> Pleroma.Config.get()
|> Keyword.get(:host)
if uploader_host == akkoma_host do
if uploader_host == akkoma_host && uses_local_uploader? do
Logger.error("""
!!!WARNING!!!
Your Akkoma Host and your Upload base_url's host are the same!

View file

@ -290,7 +290,8 @@ test "check_http_adapter/0" do
Application.put_env(:tesla, :adapter, Tesla.Mock)
end
test "check_uploader_base_url_set/0" do
describe "check_uploader_base_url_set/0" do
test "should error if the base_url is not set" do
clear_config([Pleroma.Upload, :base_url], nil)
# we need to capture the error
@ -299,24 +300,47 @@ test "check_uploader_base_url_set/0" do
DeprecationWarnings.check_uploader_base_url_set()
end) =~ "Your config does not specify a base_url for uploads!"
end
end
test "should not error if the base_url is set" do
clear_config([Pleroma.Upload, :base_url], "https://example.com")
refute capture_log(fn ->
DeprecationWarnings.check_uploader_base_url_set()
end) =~ "Your config does not specify a base_url for uploads!"
clear_config([Pleroma.Upload, :base_url])
end
test "check_uploader_base_url_is_not_base_domain/0" do
test "should not error if local uploader is not used" do
clear_config([Pleroma.Upload, :base_url], nil)
clear_config([Pleroma.Upload, :uploader], Pleroma.Uploaders.S3)
refute capture_log(fn ->
DeprecationWarnings.check_uploader_base_url_set()
end) =~ "Your config does not specify a base_url for uploads!"
end
end
describe "check_uploader_base_url_is_not_base_domain/0" do
test "should error if the akkoma domain is the same as the upload domain" do
clear_config([Pleroma.Upload, :base_url], "http://localhost")
assert capture_log(fn ->
DeprecationWarnings.check_uploader_base_url_is_not_base_domain()
end) =~ "Your Akkoma Host and your Upload base_url's host are the same!"
end
test "should not error if the local uploader is not used" do
clear_config([Pleroma.Upload, :base_url], "http://localhost")
clear_config([Pleroma.Upload, :uploader], Pleroma.Uploaders.S3)
refute capture_log(fn ->
DeprecationWarnings.check_uploader_base_url_is_not_base_domain()
end) =~ "Your Akkoma Host and your Upload base_url's host are the same!"
end
test "should not error if the akkoma domain is different from the upload domain" do
clear_config([Pleroma.Upload, :base_url], "https://media.localhost")
clear_config([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local)
refute capture_log(fn ->
DeprecationWarnings.check_uploader_base_url_is_not_base_domain()
@ -324,4 +348,5 @@ test "check_uploader_base_url_is_not_base_domain/0" do
clear_config([Pleroma.Upload, :base_url])
end
end
end