From 64d0d628783814d1d04b889a14aff436c9994147 Mon Sep 17 00:00:00 2001 From: Alex Shnitman Date: Tue, 16 Jun 2026 21:47:07 +0300 Subject: [PATCH] fix empty PUBLIC_HOST_AUDIO_URL handling (closes #1010) --- app/main.py | 7 +++++++ app/tests/test_config.py | 13 +++++++++++++ 2 files changed, 20 insertions(+) diff --git a/app/main.py b/app/main.py index f6aed10..d2283ca 100644 --- a/app/main.py +++ b/app/main.py @@ -112,6 +112,13 @@ class Config: if not self.URL_PREFIX.endswith('/'): self.URL_PREFIX += '/' + # A blank PUBLIC_HOST_AUDIO_URL (e.g. set empty in a compose file) bypasses the + # default via os.environ.get, which would leave audio links root-relative and 404. + # Fall back to the 'audio_download/' route that serves AUDIO_DOWNLOAD_DIR. When + # PUBLIC_HOST_URL is also blank we leave it blank to preserve serving from web root. + if not self.PUBLIC_HOST_AUDIO_URL and self.PUBLIC_HOST_URL: + self.PUBLIC_HOST_AUDIO_URL = self._DEFAULTS['PUBLIC_HOST_AUDIO_URL'] + for attr in ('PUBLIC_HOST_URL', 'PUBLIC_HOST_AUDIO_URL'): val = getattr(self, attr) if val and not val.endswith('/'): diff --git a/app/tests/test_config.py b/app/tests/test_config.py index bbb6c6d..b918a93 100644 --- a/app/tests/test_config.py +++ b/app/tests/test_config.py @@ -51,6 +51,19 @@ class ConfigTests(unittest.TestCase): self.assertEqual(c.PUBLIC_HOST_URL, "") self.assertEqual(c.PUBLIC_HOST_AUDIO_URL, "") + def test_blank_audio_host_falls_back_to_audio_download_route(self): + # Regression: a present-but-blank PUBLIC_HOST_AUDIO_URL must not stay empty + # (which produced root-relative, 404ing audio links). It falls back to the + # 'audio_download/' route that serves AUDIO_DOWNLOAD_DIR. + with patch.dict( + os.environ, + _base_env(PUBLIC_HOST_URL="https://ytdl.example.com", PUBLIC_HOST_AUDIO_URL=""), + clear=False, + ): + c = Config() + self.assertEqual(c.PUBLIC_HOST_URL, "https://ytdl.example.com/") + self.assertEqual(c.PUBLIC_HOST_AUDIO_URL, "audio_download/") + def test_public_host_url_already_slashed_unchanged(self): with patch.dict( os.environ,