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 @@ defmodule Pleroma.Config.DeprecationWarnings 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 @@ defmodule Pleroma.Config.DeprecationWarnings 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 @@ defmodule Pleroma.Config.DeprecationWarnings 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,38 +290,63 @@ defmodule Pleroma.Config.DeprecationWarningsTest do
Application.put_env(:tesla, :adapter, Tesla.Mock)
end
test "check_uploader_base_url_set/0" do
clear_config([Pleroma.Upload, :base_url], nil)
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
assert_raise ArgumentError, fn ->
assert capture_log(fn ->
# we need to capture the error
assert_raise ArgumentError, fn ->
assert capture_log(fn ->
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!"
end
clear_config([Pleroma.Upload, :base_url], "https://example.com")
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!"
clear_config([Pleroma.Upload, :base_url])
refute capture_log(fn ->
DeprecationWarnings.check_uploader_base_url_set()
end) =~ "Your config does not specify a base_url for uploads!"
end
end
test "check_uploader_base_url_is_not_base_domain/0" do
clear_config([Pleroma.Upload, :base_url], "http://localhost")
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!"
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
clear_config([Pleroma.Upload, :base_url], "https://media.localhost")
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!"
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
clear_config([Pleroma.Upload, :base_url])
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()
end) =~ "Your Akkoma Host and your Upload base_url's host are the same!"
clear_config([Pleroma.Upload, :base_url])
end
end
end