Add logging to API endpoints

This commit is contained in:
Lars van Rhijn
2023-11-24 22:35:16 +01:00
parent 66ac1076d3
commit 8da9672fc1
18 changed files with 398 additions and 107 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