Allow protocol to be configured for spotify proxy

This commit is contained in:
Jake Howard 2023-09-21 13:33:55 +01:00
parent 29ecc9725d
commit 899e97dedc
Signed by: jake
GPG key ID: 57AFB45680EDD477
3 changed files with 6 additions and 6 deletions

View file

@ -9,7 +9,7 @@ env = environ.Env(
DEBUG=(bool, False), DEBUG=(bool, False),
BASE_HOSTNAME=(str, "example.com"), BASE_HOSTNAME=(str, "example.com"),
UNSPLASH_CLIENT_ID=(str, ""), UNSPLASH_CLIENT_ID=(str, ""),
SPOTIFY_PROXY_HOST=(str, ""), SPOTIFY_PROXY_URL=(str, ""),
SEO_INDEX=(bool, False), SEO_INDEX=(bool, False),
SENTRY_DSN=(str, ""), SENTRY_DSN=(str, ""),
TEST=(bool, False), TEST=(bool, False),
@ -307,7 +307,7 @@ WAGTAIL_WORKFLOW_ENABLED = False
WAGTAIL_MODERATION_ENABLED = False WAGTAIL_MODERATION_ENABLED = False
UNSPLASH_CLIENT_ID = env("UNSPLASH_CLIENT_ID") 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") ACTIVITYPUB_HOST = env("ACTIVITYPUB_HOST")

View file

@ -7,13 +7,13 @@ API_LIMIT = 50
def is_valid_playlist(playlist_id: str) -> bool: def is_valid_playlist(playlist_id: str) -> bool:
return requests_session.get( return requests_session.get(
f"https://{settings.SPOTIFY_PROXY_HOST}/v1/playlists/{playlist_id}" settings.SPOTIFY_PROXY_URL + f"/v1/playlists/{playlist_id}"
).ok ).ok
def get_playlist(playlist_id: str) -> dict: def get_playlist(playlist_id: str) -> dict:
playlist_response = requests_session.get( 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"}, params={"fields": "name,external_urls.spotify,tracks.total,description"},
) )
playlist_response.raise_for_status() playlist_response.raise_for_status()
@ -22,7 +22,7 @@ def get_playlist(playlist_id: str) -> dict:
tracks = [] tracks = []
for offset in range(0, playlist_data["tracks"]["total"], API_LIMIT): for offset in range(0, playlist_data["tracks"]["total"], API_LIMIT):
tracks_response = requests_session.get( 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={ params={
"offset": str(offset), "offset": str(offset),
"limit": str(API_LIMIT), "limit": str(API_LIMIT),

View file

@ -8,7 +8,7 @@ class SpotifyHealthCheckBackend(BaseHealthCheckBackend):
def check_status(self) -> None: def check_status(self) -> None:
try: try:
requests_session.get( requests_session.get(
f"https://{settings.SPOTIFY_PROXY_HOST}/.health/" settings.SPOTIFY_PROXY_URL + "/.health/"
).raise_for_status() ).raise_for_status()
except Exception as e: except Exception as e:
self.add_error(str(e)) self.add_error(str(e))