Fix song ratio check

This commit is contained in:
root
2018-04-06 18:19:23 +02:00
parent 6ec09cc5d4
commit 32f2aaac7a

View File

@ -245,11 +245,17 @@ def upload(request):
# - U = duration * songs uploaded
# - Q = duration * songs queued
# - If 3*U < Q: allow upload (otherwise don't)
stats = upload_stats(request.user)
ratio = stats['minutes_queued'] / (3.0 * stats['minutes_upload'])
try:
stats = upload_stats(request.user)
ratio = stats['minutes_queued'] / (3.0 * stats['minutes_upload'])
ratiostr = '{:.2f}'.format(ratio)
except ZeroDivisionError:
ratio = 99999.0 # high enough
ratiostr = ""
if not request.user.is_superuser and ratio < 1.0:
msg = 'Queue-to-upload ratio too high. Please queue some more before uploading. ({:.2f})'
return JsonResponse({'success': False, 'errorMessage': msg.format(ratio)})
msg = 'Queue-to-upload ratio too high. Please queue some more before uploading. ({})'
return JsonResponse({'success': False, 'errorMessage': msg.format(ratiostr)})
for i, file in enumerate(files):
duration = File(file).info.length