Merge branch '621-in-place-extensions' into 'develop'
Fixed #621: None extension when downloading an in-place imported file Closes #621 See merge request funkwhale/funkwhale!485
This commit is contained in:
commit
16aef2e597
|
@ -121,7 +121,7 @@ class UploadFactory(factory.django.DjangoModelFactory):
|
|||
model = "music.Upload"
|
||||
|
||||
class Params:
|
||||
in_place = factory.Trait(audio_file=None)
|
||||
in_place = factory.Trait(audio_file=None, mimetype=None)
|
||||
playable = factory.Trait(
|
||||
import_status="finished", library__privacy_level="everyone"
|
||||
)
|
||||
|
|
|
@ -738,9 +738,10 @@ class Upload(models.Model):
|
|||
return utils.MIMETYPE_TO_EXTENSION[self.mimetype]
|
||||
except KeyError:
|
||||
pass
|
||||
if not self.audio_file:
|
||||
return
|
||||
return os.path.splitext(self.audio_file.name)[-1].replace(".", "", 1)
|
||||
if self.audio_file:
|
||||
return os.path.splitext(self.audio_file.name)[-1].replace(".", "", 1)
|
||||
if self.in_place_path:
|
||||
return os.path.splitext(self.in_place_path)[-1].replace(".", "", 1)
|
||||
|
||||
def get_file_size(self):
|
||||
if self.audio_file:
|
||||
|
@ -823,6 +824,12 @@ class Upload(models.Model):
|
|||
|
||||
return version
|
||||
|
||||
@property
|
||||
def in_place_path(self):
|
||||
if not self.source or not self.source.startswith("file://"):
|
||||
return
|
||||
return self.source.lstrip("file://")
|
||||
|
||||
|
||||
MIMETYPE_CHOICES = [(mt, ext) for ext, mt in utils.AUDIO_EXTENSIONS_AND_MIMETYPE]
|
||||
|
||||
|
|
|
@ -490,6 +490,7 @@ def test_fid_is_populated(factories, model, factory_args, namespace):
|
|||
[
|
||||
({"audio_file__filename": "test.mp3", "mimetype": None}, "mp3"),
|
||||
({"mimetype": "audio/mpeg"}, "mp3"),
|
||||
({"in_place": True, "source": "file:///test.mp3"}, "mp3"),
|
||||
({"audio_file__filename": "test.None", "mimetype": "audio/mpeg"}, "mp3"),
|
||||
({"audio_file__filename": "test.None", "mimetype": "audio/flac"}, "flac"),
|
||||
({"audio_file__filename": "test.None", "mimetype": "audio/x-flac"}, "flac"),
|
||||
|
@ -497,6 +498,7 @@ def test_fid_is_populated(factories, model, factory_args, namespace):
|
|||
)
|
||||
def test_upload_extension(factory_args, factories, expected):
|
||||
upload = factories["music.Upload"].build(**factory_args)
|
||||
|
||||
assert upload.extension == expected
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Fixed None extension when downloading an in-place imported file (#621)
|
Loading…
Reference in New Issue