mirror of
https://gitlab.science.ru.nl/technicie/MarietjeDjango.git
synced 2025-12-12 23:52:21 +01:00
Add logging to API endpoints
This commit is contained in:
@ -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
|
||||
|
||||
Reference in New Issue
Block a user