Merge branch 'feature/log-api-endpoints' into 'marietje-zuid'

Add logging for API endpoints

Closes #74

See merge request technicie/MarietjeDjango!83
This commit is contained in:
Lars van Rhijn
2024-02-28 14:12:22 +01:00
19 changed files with 399 additions and 108 deletions

View File

@ -1,4 +1,9 @@
from marietje.utils import send_to_bertha
import binascii
import socket
import struct
from django.conf import settings
from queues.models import PlaylistSong
from songs.models import Song
from django.db.models.functions import Coalesce
@ -11,6 +16,20 @@ class UploadException(Exception):
pass
def send_to_bertha(file):
"""Send a file to Berthad file storage."""
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(settings.BERTHA_HOST)
sock.sendall(struct.pack("<BQ", 4, file.size))
for chunk in file.chunks():
sock.sendall(chunk)
sock.shutdown(socket.SHUT_WR)
song_hash = binascii.hexlify(sock.recv(64))
sock.close()
return song_hash
def is_regular_queue(ps):
if not ps.played_at:
# Request is from the old times, assume good