Fixed #73: broken file upload
This commit is contained in:
parent
8283a73a7f
commit
8c7e943013
|
@ -4,6 +4,9 @@ Changelog
|
||||||
0.6 (Unreleased)
|
0.6 (Unreleased)
|
||||||
----------------
|
----------------
|
||||||
|
|
||||||
|
- Fixed broken file import due to wrong url (#73)
|
||||||
|
- More accurate mimetype detection
|
||||||
|
|
||||||
|
|
||||||
0.5.1 (2018-02-24)
|
0.5.1 (2018-02-24)
|
||||||
------------------
|
------------------
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import magic
|
import magic
|
||||||
|
import mimetypes
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
|
@ -42,7 +43,13 @@ def get_query(query_string, search_fields):
|
||||||
|
|
||||||
def guess_mimetype(f):
|
def guess_mimetype(f):
|
||||||
b = min(100000, f.size)
|
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):
|
def compute_status(jobs):
|
||||||
|
|
|
@ -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'
|
|
@ -29,7 +29,7 @@
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="ui hidden divider"></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.
|
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>
|
</p>
|
||||||
<table class="ui single line table">
|
<table class="ui single line table">
|
||||||
|
@ -73,7 +73,7 @@ export default {
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
files: [],
|
files: [],
|
||||||
uploadUrl: 'import-jobs/',
|
uploadUrl: '/api/v1/import-jobs/',
|
||||||
batch: null
|
batch: null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue