mirror of
https://github.com/alexta69/metube.git
synced 2026-06-17 00:30:07 +00:00
fix empty PUBLIC_HOST_AUDIO_URL handling (closes #1010)
This commit is contained in:
@@ -112,6 +112,13 @@ class Config:
|
|||||||
if not self.URL_PREFIX.endswith('/'):
|
if not self.URL_PREFIX.endswith('/'):
|
||||||
self.URL_PREFIX += '/'
|
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'):
|
for attr in ('PUBLIC_HOST_URL', 'PUBLIC_HOST_AUDIO_URL'):
|
||||||
val = getattr(self, attr)
|
val = getattr(self, attr)
|
||||||
if val and not val.endswith('/'):
|
if val and not val.endswith('/'):
|
||||||
|
|||||||
@@ -51,6 +51,19 @@ class ConfigTests(unittest.TestCase):
|
|||||||
self.assertEqual(c.PUBLIC_HOST_URL, "")
|
self.assertEqual(c.PUBLIC_HOST_URL, "")
|
||||||
self.assertEqual(c.PUBLIC_HOST_AUDIO_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):
|
def test_public_host_url_already_slashed_unchanged(self):
|
||||||
with patch.dict(
|
with patch.dict(
|
||||||
os.environ,
|
os.environ,
|
||||||
|
|||||||
Reference in New Issue
Block a user