Merge branch '73-file-upload' into 'develop'

Fixed #73: broken file upload

Closes #73

See merge request funkwhale/funkwhale!54
merge-requests/154/head
Eliot Berriot 2018-02-26 17:30:48 +00:00
commit 2ad735bf85
4 zmienionych plików z 32 dodań i 3 usunięć

Wyświetl plik

@ -4,6 +4,9 @@ Changelog
0.6 (Unreleased)
----------------
- Fixed broken file import due to wrong url (#73)
- More accurate mimetype detection
0.5.1 (2018-02-24)
------------------

Wyświetl plik

@ -1,4 +1,5 @@
import magic
import mimetypes
import re
from django.db.models import Q
@ -42,7 +43,13 @@ def get_query(query_string, search_fields):
def guess_mimetype(f):
b = min(100000, f.size)
return magic.from_buffer(f.read(b), mime=True)
t = magic.from_buffer(f.read(b), mime=True)
if t == 'application/octet-stream':
# failure, we try guessing by extension
mt, _ = mimetypes.guess_type(f.path)
if mt:
t = mt
return t
def compute_status(jobs):

Wyświetl plik

@ -0,0 +1,19 @@
from funkwhale_api.music import utils
def test_guess_mimetype_try_using_extension(factories, mocker):
mocker.patch(
'magic.from_buffer', return_value='audio/mpeg')
f = factories['music.TrackFile'].build(
audio_file__filename='test.ogg')
assert utils.guess_mimetype(f.audio_file) == 'audio/mpeg'
def test_guess_mimetype_try_using_extension_if_fail(factories, mocker):
mocker.patch(
'magic.from_buffer', return_value='application/octet-stream')
f = factories['music.TrackFile'].build(
audio_file__filename='test.mp3')
assert utils.guess_mimetype(f.audio_file) == 'audio/mpeg'

Wyświetl plik

@ -29,7 +29,7 @@
</button>
</div>
<div class="ui hidden divider"></div>
<p>
<p v-if="batch">
Once all your files are uploaded, simply head over <router-link :to="{name: 'library.import.batches.detail', params: {id: batch.id }}">import detail page</router-link> to check the import status.
</p>
<table class="ui single line table">
@ -73,7 +73,7 @@ export default {
data () {
return {
files: [],
uploadUrl: 'import-jobs/',
uploadUrl: '/api/v1/import-jobs/',
batch: null
}
},