Skip to content
Snippets Groups Projects
Commit ef5efc89 authored by ale's avatar ale
Browse files

add robust error checking on the /dl/ endpoint

parent 7d4607b2
Branches
No related tags found
No related merge requests found
......@@ -120,6 +120,30 @@ def download_song(sha1):
mp3 = MP3.query.get(sha1)
if not mp3:
abort(404)
# This is a good time to check round-trip inconsistencies: if the
# user is requesting a duplicate file, it means our SOLR index got
# out of sync, but we can still give him the file he wants.
if mp3.state == MP3.DUPLICATE:
dup_mp3 = MP3.query.get(mp3.duplicate_of)
if not dup_mp3:
log.error(
'SEVERE: duplicate_of %s points to non-existing mp3 %s' % (
mp3.sha1, mp3.duplicate_of))
abort(404)
log.error(
'inconsistency: user got duplicate song: %s (instead of %s)' % (
mp3.sha1, mp3.duplicate_of))
mp3 = dup_mp3
if mp3.state != MP3.READY:
log.error('inconsistency: user got non-ready song: %s' % mp3.sha1)
abort(404)
if not os.path.exists(mp3.path):
log.error('SEVERE: file has disappeared for song: %s' % mp3.sha1)
abort(404)
if use_xsendfile:
return download_song_xsendfile(mp3)
else:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment