From 899e97dedcd8f642fd127ffab83e9b0928813781 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Thu, 21 Sep 2023 13:33:55 +0100 Subject: [PATCH] Allow protocol to be configured for spotify proxy --- website/settings.py | 4 ++-- website/spotify/client.py | 6 +++--- website/spotify/healthchecks.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/website/settings.py b/website/settings.py index c216f87..9dfc50f 100644 --- a/website/settings.py +++ b/website/settings.py @@ -9,7 +9,7 @@ env = environ.Env( DEBUG=(bool, False), BASE_HOSTNAME=(str, "example.com"), UNSPLASH_CLIENT_ID=(str, ""), - SPOTIFY_PROXY_HOST=(str, ""), + SPOTIFY_PROXY_URL=(str, ""), SEO_INDEX=(bool, False), SENTRY_DSN=(str, ""), TEST=(bool, False), @@ -307,7 +307,7 @@ WAGTAIL_WORKFLOW_ENABLED = False WAGTAIL_MODERATION_ENABLED = False UNSPLASH_CLIENT_ID = env("UNSPLASH_CLIENT_ID") -SPOTIFY_PROXY_HOST = env("SPOTIFY_PROXY_HOST") +SPOTIFY_PROXY_URL = env("SPOTIFY_PROXY_URL") ACTIVITYPUB_HOST = env("ACTIVITYPUB_HOST") diff --git a/website/spotify/client.py b/website/spotify/client.py index ec968a9..fd666d4 100644 --- a/website/spotify/client.py +++ b/website/spotify/client.py @@ -7,13 +7,13 @@ API_LIMIT = 50 def is_valid_playlist(playlist_id: str) -> bool: return requests_session.get( - f"https://{settings.SPOTIFY_PROXY_HOST}/v1/playlists/{playlist_id}" + settings.SPOTIFY_PROXY_URL + f"/v1/playlists/{playlist_id}" ).ok def get_playlist(playlist_id: str) -> dict: playlist_response = requests_session.get( - f"https://{settings.SPOTIFY_PROXY_HOST}/v1/playlists/{playlist_id}", + settings.SPOTIFY_PROXY_URL + f"/v1/playlists/{playlist_id}", params={"fields": "name,external_urls.spotify,tracks.total,description"}, ) playlist_response.raise_for_status() @@ -22,7 +22,7 @@ def get_playlist(playlist_id: str) -> dict: tracks = [] for offset in range(0, playlist_data["tracks"]["total"], API_LIMIT): tracks_response = requests_session.get( - f"https://{settings.SPOTIFY_PROXY_HOST}/v1/playlists/{playlist_id}/tracks", + settings.SPOTIFY_PROXY_URL + f"/v1/playlists/{playlist_id}/tracks", params={ "offset": str(offset), "limit": str(API_LIMIT), diff --git a/website/spotify/healthchecks.py b/website/spotify/healthchecks.py index df3ad0c..21ccf77 100644 --- a/website/spotify/healthchecks.py +++ b/website/spotify/healthchecks.py @@ -8,7 +8,7 @@ class SpotifyHealthCheckBackend(BaseHealthCheckBackend): def check_status(self) -> None: try: requests_session.get( - f"https://{settings.SPOTIFY_PROXY_HOST}/.health/" + settings.SPOTIFY_PROXY_URL + "/.health/" ).raise_for_status() except Exception as e: self.add_error(str(e))