mirror of
https://gitlab.science.ru.nl/technicie/MarietjeDjango.git
synced 2025-12-12 23:22:20 +01:00
Add logging for API endpoints
This commit is contained in:
29
marietje/playerapi/services.py
Normal file
29
marietje/playerapi/services.py
Normal file
@ -0,0 +1,29 @@
|
||||
def song_to_dict(song, include_hash=False, include_user=False, include_replaygain=False, **options):
|
||||
data = {
|
||||
"id": song.id,
|
||||
"artist": song.artist,
|
||||
"title": song.title,
|
||||
"duration": song.duration,
|
||||
}
|
||||
|
||||
if include_hash:
|
||||
data["hash"] = song.hash
|
||||
|
||||
if include_user is not None and song.user is not None and song.user.name:
|
||||
data["uploader_name"] = song.user.name
|
||||
|
||||
if include_replaygain:
|
||||
data["rg_gain"] = song.rg_gain
|
||||
data["rg_peak"] = song.rg_peak
|
||||
|
||||
return data
|
||||
|
||||
|
||||
def playlist_song_to_dict(playlist_song, **options):
|
||||
user = options.get("user")
|
||||
return {
|
||||
"id": playlist_song.id,
|
||||
"requested_by": "Marietje" if playlist_song.user is None else playlist_song.user.name,
|
||||
"song": song_to_dict(playlist_song.song, **options),
|
||||
"can_move_down": playlist_song.user is not None and playlist_song.user == user,
|
||||
}
|
||||
@ -4,11 +4,11 @@ from django.http import JsonResponse
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
|
||||
from marietje.utils import playlist_song_to_dict
|
||||
from queues.models import Queue
|
||||
from songs.models import Song
|
||||
|
||||
from .decorators import token_required
|
||||
from .services import playlist_song_to_dict
|
||||
|
||||
|
||||
@csrf_exempt
|
||||
|
||||
Reference in New Issue
Block a user