forked from AkkomaGang/akkoma
Don't error out if we're not using the local uploader
This commit is contained in:
parent
f592090206
commit
b5d97e7d85
3 changed files with 52 additions and 23 deletions
|
@ -42,6 +42,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
## Upgrade Notes
|
## Upgrade Notes
|
||||||
|
|
||||||
- As mentioned in "Changed", `Pleroma.Upload, :base_url` **MUST** be configured. Uploads will fail without it.
|
- 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.
|
- Same with media proxy.
|
||||||
|
|
||||||
## 2024.02
|
## 2024.02
|
||||||
|
|
|
@ -341,9 +341,10 @@ def check_uploders_s3_public_endpoint do
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_uploader_base_url_set() do
|
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])
|
base_url = Pleroma.Config.get([Pleroma.Upload, :base_url])
|
||||||
|
|
||||||
if base_url do
|
if base_url || !uses_local_uploader? do
|
||||||
:ok
|
:ok
|
||||||
else
|
else
|
||||||
Logger.error("""
|
Logger.error("""
|
||||||
|
@ -361,6 +362,8 @@ def check_uploader_base_url_set() do
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_uploader_base_url_is_not_base_domain() do
|
def check_uploader_base_url_is_not_base_domain() do
|
||||||
|
uses_local_uploader? = Config.get([Pleroma.Upload, :uploader]) == Pleroma.Uploaders.Local
|
||||||
|
|
||||||
uploader_host =
|
uploader_host =
|
||||||
[Pleroma.Upload, :base_url]
|
[Pleroma.Upload, :base_url]
|
||||||
|> Pleroma.Config.get()
|
|> Pleroma.Config.get()
|
||||||
|
@ -372,7 +375,7 @@ def check_uploader_base_url_is_not_base_domain() do
|
||||||
|> Pleroma.Config.get()
|
|> Pleroma.Config.get()
|
||||||
|> Keyword.get(:host)
|
|> Keyword.get(:host)
|
||||||
|
|
||||||
if uploader_host == akkoma_host do
|
if uploader_host == akkoma_host && uses_local_uploader? do
|
||||||
Logger.error("""
|
Logger.error("""
|
||||||
!!!WARNING!!!
|
!!!WARNING!!!
|
||||||
Your Akkoma Host and your Upload base_url's host are the same!
|
Your Akkoma Host and your Upload base_url's host are the same!
|
||||||
|
|
|
@ -290,38 +290,63 @@ test "check_http_adapter/0" do
|
||||||
Application.put_env(:tesla, :adapter, Tesla.Mock)
|
Application.put_env(:tesla, :adapter, Tesla.Mock)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "check_uploader_base_url_set/0" do
|
describe "check_uploader_base_url_set/0" do
|
||||||
clear_config([Pleroma.Upload, :base_url], nil)
|
test "should error if the base_url is not set" do
|
||||||
|
clear_config([Pleroma.Upload, :base_url], nil)
|
||||||
|
|
||||||
# we need to capture the error
|
# we need to capture the error
|
||||||
assert_raise ArgumentError, fn ->
|
assert_raise ArgumentError, fn ->
|
||||||
assert capture_log(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()
|
DeprecationWarnings.check_uploader_base_url_set()
|
||||||
end) =~ "Your config does not specify a base_url for uploads!"
|
end) =~ "Your config does not specify a base_url for uploads!"
|
||||||
end
|
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 ->
|
refute capture_log(fn ->
|
||||||
DeprecationWarnings.check_uploader_base_url_set()
|
DeprecationWarnings.check_uploader_base_url_set()
|
||||||
end) =~ "Your config does not specify a base_url for uploads!"
|
end) =~ "Your config does not specify a base_url for uploads!"
|
||||||
|
end
|
||||||
clear_config([Pleroma.Upload, :base_url])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "check_uploader_base_url_is_not_base_domain/0" do
|
describe "check_uploader_base_url_is_not_base_domain/0" do
|
||||||
clear_config([Pleroma.Upload, :base_url], "http://localhost")
|
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 ->
|
assert capture_log(fn ->
|
||||||
DeprecationWarnings.check_uploader_base_url_is_not_base_domain()
|
DeprecationWarnings.check_uploader_base_url_is_not_base_domain()
|
||||||
end) =~ "Your Akkoma Host and your Upload base_url's host are the same!"
|
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 ->
|
refute capture_log(fn ->
|
||||||
DeprecationWarnings.check_uploader_base_url_is_not_base_domain()
|
DeprecationWarnings.check_uploader_base_url_is_not_base_domain()
|
||||||
end) =~ "Your Akkoma Host and your Upload base_url's host are the same!"
|
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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue