добавил переменные окружения
This commit is contained in:
parent
feb8b5f168
commit
c4c1d5a9cb
|
|
@ -0,0 +1,4 @@
|
||||||
|
SECRET_KEY = 'django-insecure-z242=*-knp4h=0l1*o-nyid^y0bwt4bvg3tf*wvr(qszj&!8$c'
|
||||||
|
API_KEY = "49226d3488aac3f5:18d88659c6c1c5e131a0ce0a94d55235"
|
||||||
|
DEBUG = True
|
||||||
|
URL_PROD = http://82.97.242.49:10084
|
||||||
|
|
@ -6,6 +6,8 @@ from rest_framework import status
|
||||||
from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned
|
from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned
|
||||||
from django.shortcuts import get_object_or_404, get_list_or_404
|
from django.shortcuts import get_object_or_404, get_list_or_404
|
||||||
from rest_framework.permissions import IsAuthenticated
|
from rest_framework.permissions import IsAuthenticated
|
||||||
|
from decouple import config
|
||||||
|
from urllib.parse import urljoin
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from .schemas import SongSchema, DeleteSongSchema
|
from .schemas import SongSchema, DeleteSongSchema
|
||||||
|
|
@ -20,8 +22,11 @@ class SongViewSet(GenericViewSet):
|
||||||
}
|
}
|
||||||
|
|
||||||
def list(self, request):
|
def list(self, request):
|
||||||
songs_pk = FavoriteSong.objects.filter(user=request.user, song__isnull=False).values_list('song_id', flat=True)
|
try:
|
||||||
queryset = Song.objects.filter(id__in=songs_pk)
|
songs_pk = FavoriteSong.objects.filter(user=request.user, song__isnull=False).values_list('song_id', flat=True)
|
||||||
|
queryset = Song.objects.filter(id__in=songs_pk)
|
||||||
|
except ObjectDoesNotExist:
|
||||||
|
return Response({"error": 'Объекта не существует'}, status=status.HTTP_404_NOT_FOUND)
|
||||||
serializer = SongSerializer(queryset, many=True)
|
serializer = SongSerializer(queryset, many=True)
|
||||||
return Response(serializer.data)
|
return Response(serializer.data)
|
||||||
|
|
||||||
|
|
@ -31,8 +36,6 @@ class SongViewSet(GenericViewSet):
|
||||||
queryset = FavoriteSong.objects.get(user=request.user.pk, song=song_obj)
|
queryset = FavoriteSong.objects.get(user=request.user.pk, song=song_obj)
|
||||||
except ObjectDoesNotExist:
|
except ObjectDoesNotExist:
|
||||||
return Response({"error": 'Объекта не существует'}, status=status.HTTP_404_NOT_FOUND)
|
return Response({"error": 'Объекта не существует'}, status=status.HTTP_404_NOT_FOUND)
|
||||||
except MultipleObjectsReturned:
|
|
||||||
return Response({"error": 'Найдено более одного объекта'}, status=status.HTTP_400_BAD_REQUEST)
|
|
||||||
serializer = FavoriteSongSerializer(queryset)
|
serializer = FavoriteSongSerializer(queryset)
|
||||||
return Response(serializer.data)
|
return Response(serializer.data)
|
||||||
|
|
||||||
|
|
@ -48,10 +51,10 @@ class SongViewSet(GenericViewSet):
|
||||||
}
|
}
|
||||||
#Если трека нету в базе
|
#Если трека нету в базе
|
||||||
else:
|
else:
|
||||||
file_url = f"http://82.97.242.49:10084/api/station/it-radio/file/{request.data['azura_id']}"
|
file_url = urljoin(config('URL_PROD'), f'/api/station/it-radio/file/{request.data['azura_id']}')
|
||||||
api_key = "49226d3488aac3f5:18d88659c6c1c5e131a0ce0a94d55235"
|
API_KEY = config('API_KEY')
|
||||||
headers = {
|
headers = {
|
||||||
"Authorization": f"Bearer {api_key}"
|
"Authorization": f"Bearer {API_KEY}"
|
||||||
}
|
}
|
||||||
response = requests.get(file_url, headers=headers)
|
response = requests.get(file_url, headers=headers)
|
||||||
data = request.data
|
data = request.data
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import os
|
import os
|
||||||
|
from decouple import config
|
||||||
|
|
||||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||||
ROOT_DIR = BASE_DIR.parent.parent.parent
|
ROOT_DIR = BASE_DIR.parent.parent.parent
|
||||||
|
|
@ -14,10 +16,10 @@ MEDIA_URL = 'media/'
|
||||||
STATIC_ROOT = PROJECT_DIR / 'static'
|
STATIC_ROOT = PROJECT_DIR / 'static'
|
||||||
STATIC_URL = 'static/'
|
STATIC_URL = 'static/'
|
||||||
# SECURITY WARNING: keep the secret key used in production secret!
|
# SECURITY WARNING: keep the secret key used in production secret!
|
||||||
SECRET_KEY = 'django-insecure-z242=*-knp4h=0l1*o-nyid^y0bwt4bvg3tf*wvr(qszj&!8$c'
|
SECRET_KEY = config('SECRET_KEY')
|
||||||
|
|
||||||
# SECURITY WARNING: don't run with debug turned on in production!
|
# SECURITY WARNING: don't run with debug turned on in production!
|
||||||
DEBUG = True
|
DEBUG = config('DEBUG', cast=bool)
|
||||||
|
|
||||||
ALLOWED_HOSTS = ['*']
|
ALLOWED_HOSTS = ['*']
|
||||||
CORS_ORIGIN_ALLOW_ALL = True
|
CORS_ORIGIN_ALLOW_ALL = True
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue