mirror of
https://github.com/alexta69/metube.git
synced 2026-06-13 16:40:05 +00:00
fix PUBLIC_HOST_URL without a trailing slash (closes #959)
This commit is contained in:
@@ -92,6 +92,11 @@ class Config:
|
|||||||
if not self.URL_PREFIX.endswith('/'):
|
if not self.URL_PREFIX.endswith('/'):
|
||||||
self.URL_PREFIX += '/'
|
self.URL_PREFIX += '/'
|
||||||
|
|
||||||
|
for attr in ('PUBLIC_HOST_URL', 'PUBLIC_HOST_AUDIO_URL'):
|
||||||
|
val = getattr(self, attr)
|
||||||
|
if val and not val.endswith('/'):
|
||||||
|
setattr(self, attr, val + '/')
|
||||||
|
|
||||||
# Convert relative addresses to absolute addresses to prevent the failure of file address comparison
|
# Convert relative addresses to absolute addresses to prevent the failure of file address comparison
|
||||||
if self.YTDL_OPTIONS_FILE and self.YTDL_OPTIONS_FILE.startswith('.'):
|
if self.YTDL_OPTIONS_FILE and self.YTDL_OPTIONS_FILE.startswith('.'):
|
||||||
self.YTDL_OPTIONS_FILE = str(Path(self.YTDL_OPTIONS_FILE).resolve())
|
self.YTDL_OPTIONS_FILE = str(Path(self.YTDL_OPTIONS_FILE).resolve())
|
||||||
|
|||||||
@@ -23,6 +23,47 @@ class ConfigTests(unittest.TestCase):
|
|||||||
c = Config()
|
c = Config()
|
||||||
self.assertEqual(c.URL_PREFIX, "foo/")
|
self.assertEqual(c.URL_PREFIX, "foo/")
|
||||||
|
|
||||||
|
def test_public_host_url_gets_trailing_slash(self):
|
||||||
|
with patch.dict(
|
||||||
|
os.environ,
|
||||||
|
_base_env(PUBLIC_HOST_URL="https://ytdl.example.com"),
|
||||||
|
clear=False,
|
||||||
|
):
|
||||||
|
c = Config()
|
||||||
|
self.assertEqual(c.PUBLIC_HOST_URL, "https://ytdl.example.com/")
|
||||||
|
|
||||||
|
def test_public_host_audio_url_gets_trailing_slash(self):
|
||||||
|
with patch.dict(
|
||||||
|
os.environ,
|
||||||
|
_base_env(PUBLIC_HOST_AUDIO_URL="https://audio.example.com"),
|
||||||
|
clear=False,
|
||||||
|
):
|
||||||
|
c = Config()
|
||||||
|
self.assertEqual(c.PUBLIC_HOST_AUDIO_URL, "https://audio.example.com/")
|
||||||
|
|
||||||
|
def test_public_host_url_empty_stays_empty(self):
|
||||||
|
with patch.dict(
|
||||||
|
os.environ,
|
||||||
|
_base_env(PUBLIC_HOST_URL="", PUBLIC_HOST_AUDIO_URL=""),
|
||||||
|
clear=False,
|
||||||
|
):
|
||||||
|
c = Config()
|
||||||
|
self.assertEqual(c.PUBLIC_HOST_URL, "")
|
||||||
|
self.assertEqual(c.PUBLIC_HOST_AUDIO_URL, "")
|
||||||
|
|
||||||
|
def test_public_host_url_already_slashed_unchanged(self):
|
||||||
|
with patch.dict(
|
||||||
|
os.environ,
|
||||||
|
_base_env(
|
||||||
|
PUBLIC_HOST_URL="https://ytdl.example.com/",
|
||||||
|
PUBLIC_HOST_AUDIO_URL="https://audio.example.com/",
|
||||||
|
),
|
||||||
|
clear=False,
|
||||||
|
):
|
||||||
|
c = Config()
|
||||||
|
self.assertEqual(c.PUBLIC_HOST_URL, "https://ytdl.example.com/")
|
||||||
|
self.assertEqual(c.PUBLIC_HOST_AUDIO_URL, "https://audio.example.com/")
|
||||||
|
|
||||||
def test_ytdl_options_json_loaded(self):
|
def test_ytdl_options_json_loaded(self):
|
||||||
opts = {"quiet": True, "no_warnings": True}
|
opts = {"quiet": True, "no_warnings": True}
|
||||||
with patch.dict(
|
with patch.dict(
|
||||||
|
|||||||
Reference in New Issue
Block a user