Skip to content
Snippets Groups Projects
Commit 390dcfd0 authored by Eliot Berriot's avatar Eliot Berriot
Browse files

Merge branch '266-application-empty' into 'develop'

Resolve "Ogg files end up with a application/x-empty mimetype on import"

Closes #266

See merge request funkwhale/funkwhale!224
parents f33dfdad 5afc3e46
No related branches found
No related tags found
No related merge requests found
......@@ -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:
......
......@@ -15,9 +15,13 @@ def test_guess_mimetype_try_using_extension(factories, mocker):
assert utils.guess_mimetype(f.audio_file) == 'audio/mpeg'
def test_guess_mimetype_try_using_extension_if_fail(factories, mocker):
@pytest.mark.parametrize('wrong', [
'application/octet-stream',
'application/x-empty',
])
def test_guess_mimetype_try_using_extension_if_fail(wrong, factories, mocker):
mocker.patch(
'magic.from_buffer', return_value='application/octet-stream')
'magic.from_buffer', return_value=wrong)
f = factories['music.TrackFile'].build(
audio_file__filename='test.mp3')
......
Ensure we do not store bad mimetypes (such as application/x-empty) (#266)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment