diff --git a/diora/settings.py b/diora/settings.py index 7c64f01..e320eeb 100644 --- a/diora/settings.py +++ b/diora/settings.py @@ -98,3 +98,4 @@ LASTFM_API_SECRET = os.environ.get('LASTFM_API_SECRET', '') # Amazon affiliate AMAZON_AFFILIATE_TAG = os.environ.get('AMAZON_AFFILIATE_TAG', 'diora-20') +AMAZON_AFFILIATE_ENABLED = os.environ.get('AMAZON_AFFILIATE_ENABLED', 'True') == 'True' diff --git a/radio/views.py b/radio/views.py index 20e7744..78bd409 100644 --- a/radio/views.py +++ b/radio/views.py @@ -47,6 +47,7 @@ def index(request): context = { 'saved_stations': saved_stations, 'history': history, + 'amazon_enabled': settings.AMAZON_AFFILIATE_ENABLED, } return render(request, 'radio/player.html', context) @@ -144,6 +145,9 @@ def record_track(request): # --------------------------------------------------------------------------- def affiliate_links(request): + if not settings.AMAZON_AFFILIATE_ENABLED: + return JsonResponse({'amazon_url': None, 'itunes_data': {}}) + track = request.GET.get('track', '').strip() if not track: return JsonResponse({'error': 'track parameter required'}, status=400) diff --git a/static/js/app.js b/static/js/app.js index be365db..6917697 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -282,6 +282,7 @@ async function deleteHistoryEntry(id, btn) { async function fetchAffiliateLinks(track) { const section = $('affiliate-section'); + if (section && section.dataset.disabled) return; try { const res = await fetch('/radio/affiliate/?track=' + encodeURIComponent(track)); if (!res.ok) return; diff --git a/templates/radio/player.html b/templates/radio/player.html index 6d4fcae..e341e56 100644 --- a/templates/radio/player.html +++ b/templates/radio/player.html @@ -29,7 +29,7 @@ -