diff --git a/api/funkwhale_api/music/factories.py b/api/funkwhale_api/music/factories.py index a06ada808518f7b10014b803df23462546eb321b..8a7e84a925478c81ad02155f976bac99575fd2be 100644 --- a/api/funkwhale_api/music/factories.py +++ b/api/funkwhale_api/music/factories.py @@ -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" ) diff --git a/api/funkwhale_api/music/models.py b/api/funkwhale_api/music/models.py index a8f4530b4b55936f38a6d55f46dc4eb1db71dd08..97c74a9a8bd894fa33d13c18ab2352fd5600c09b 100644 --- a/api/funkwhale_api/music/models.py +++ b/api/funkwhale_api/music/models.py @@ -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] diff --git a/api/tests/music/test_models.py b/api/tests/music/test_models.py index 891a9984dd7e21730bfdb501a85ae36e46705cae..cabe1526009a90810c2cf5ff01264497a8555fc1 100644 --- a/api/tests/music/test_models.py +++ b/api/tests/music/test_models.py @@ -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 diff --git a/changes/changelog.d/621.bugfix b/changes/changelog.d/621.bugfix new file mode 100644 index 0000000000000000000000000000000000000000..cd15865ec027a701a8a0be5fe93574676c1a565d --- /dev/null +++ b/changes/changelog.d/621.bugfix @@ -0,0 +1 @@ +Fixed None extension when downloading an in-place imported file (#621)