Fix #266: Ensure we do not store bad mimetypes

This commit is contained in:
Eliot Berriot 2018-06-03 18:07:59 +02:00
parent a00a6162c0
commit 5afc3e4637
No known key found for this signature in database
GPG key ID: DD6965E2476E5C27
3 changed files with 9 additions and 4 deletions

View file

@ -43,9 +43,9 @@ def get_query(query_string, search_fields):
def guess_mimetype(f):
b = min(100000, f.size)
b = min(1000000, f.size)
t = magic.from_buffer(f.read(b), mime=True)
if t == 'application/octet-stream':
if not t.startswith('audio/'):
# failure, we try guessing by extension
mt, _ = mimetypes.guess_type(f.path)
if mt: