Merge remote-tracking branch 'origin/master'

This commit is contained in:
Stepan Fedyanin 2024-06-18 17:56:18 +05:00
commit 6680fd8792
4 changed files with 9 additions and 12 deletions

View File

@ -8,7 +8,6 @@ from rest_framework.decorators import action
from rest_framework.permissions import AllowAny
class FetchAndServeFile(ViewSet):
#http://82.97.242.49:10084/api/station/it-radio/file/5196269acd9d54e86297557a6d9a7aab/
def list(self, request):
file_url = f"http://82.97.242.49:10084/api/station/it-radio/file/fc6377b2dae75d29358783bc"
api_key = "49226d3488aac3f5:18d88659c6c1c5e131a0ce0a94d55235"
@ -21,8 +20,7 @@ class FetchAndServeFile(ViewSet):
response = requests.get(file_url, headers=headers)
response.raise_for_status()
print(response.content)
# Create a response with the appropriate content type and headers
file_response = HttpResponse(response.content, content_type='audio/mpeg')
file_response['Content-Disposition'] = 'attachment; filename="output.mp3"'
return file_response

View File

@ -50,6 +50,6 @@ class DeleteSongSchema(AutoSchema):
name='azura_id',
location='form',
required=False,
schema=coreschema.String(description='ID трека')
schema=coreschema.String(description='ID трека с Азуры')
),
]

View File

@ -34,12 +34,10 @@ class SongViewSet(GenericViewSet):
try:
song_obj = Song.objects.get(azura_id=azura_id)
favorite_songs = FavoriteSong.objects.get(user=request.user, song=song_obj)
return Response({"is_favorite": True}, status=status.HTTP_200_OK)
except ObjectDoesNotExist:
return Response({"error": 'Объекта не существует'}, status=status.HTTP_404_NOT_FOUND)
serializer = FavoriteSongSerializer(favorite_songs)
return Response(serializer.data)
return Response({"is_favorite": False}, status=status.HTTP_200_OK)
@action(
detail=False,
methods=['get'],
@ -49,7 +47,7 @@ class SongViewSet(GenericViewSet):
def get_audio(self, request, azura_id):
try:
song_obj = Song.objects.get(azura_id=azura_id)
file_url = f"http://82.97.242.49:10084/api/station/it-radio/file/{song_obj.azura_id}/play"
file_url = song_obj.unique_id
API_KEY = "49226d3488aac3f5:18d88659c6c1c5e131a0ce0a94d55235"
headers = {
"Authorization": f"Bearer {API_KEY}"
@ -103,7 +101,8 @@ class SongViewSet(GenericViewSet):
@action(detail=False, methods=['post'], schema=DeleteSongSchema())
def delete_song(self, request):
try:
item = FavoriteSong.objects.get(user=request.user, song=request.data.get('azura_id'))
song = Song.objects.get(azura_id=request.data.get('azura_id'))
item = FavoriteSong.objects.get(user=request.user, song=song.pk)
item.delete()
return Response(status=status.HTTP_202_ACCEPTED)
except ObjectDoesNotExist:

View File

@ -183,7 +183,7 @@ CORS_ALLOWED_ORIGINS = [
from datetime import timedelta
SIMPLE_JWT = {
'ACCESS_TOKEN_LIFETIME': timedelta(minutes=180),
'ACCESS_TOKEN_LIFETIME': timedelta(days=1),
'REFRESH_TOKEN_LIFETIME': timedelta(days=30),
}