Merge branch '893-subsonic-content-type' into 'develop'
Fixed #893: empty contentType causing client crash in some Subsonic payloads Closes #893 See merge request funkwhale/funkwhale!868
This commit is contained in:
commit
19b8adb358
|
@ -5,6 +5,7 @@ from rest_framework import serializers
|
|||
|
||||
from funkwhale_api.history import models as history_models
|
||||
from funkwhale_api.music import models as music_models
|
||||
from funkwhale_api.music import utils as music_utils
|
||||
|
||||
|
||||
def get_artist_data(artist_values):
|
||||
|
@ -71,7 +72,14 @@ def get_track_data(album, track, upload):
|
|||
"artist": album.artist.name,
|
||||
"track": track.position or 1,
|
||||
"discNumber": track.disc_number or 1,
|
||||
"contentType": upload.mimetype,
|
||||
# Ugly fallback to mp3 but some subsonic clients fail if the value is empty or null, and we don't always
|
||||
# have the info on legacy uploads
|
||||
"contentType": upload.mimetype
|
||||
or (
|
||||
music_utils.get_type_from_ext(upload.extension)
|
||||
if upload.extension
|
||||
else "audio/mpeg"
|
||||
),
|
||||
"suffix": upload.extension or "",
|
||||
"duration": upload.duration or 0,
|
||||
"created": track.creation_date,
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import pytest
|
||||
|
||||
from funkwhale_api.music import models as music_models
|
||||
from funkwhale_api.subsonic import serializers
|
||||
|
||||
|
@ -61,6 +63,27 @@ def test_get_artist_serializer(factories):
|
|||
assert serializers.GetArtistSerializer(artist).data == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"mimetype, extension, expected",
|
||||
[
|
||||
("audio/ogg", "noop", "audio/ogg"),
|
||||
("", "ogg", "audio/ogg"),
|
||||
("", "mp3", "audio/mpeg"),
|
||||
("", "", "audio/mpeg"),
|
||||
],
|
||||
)
|
||||
def test_get_track_data_content_type(mimetype, extension, expected, factories):
|
||||
upload = factories["music.Upload"]()
|
||||
upload.mimetype = mimetype
|
||||
upload.audio_file = "test.{}".format(extension)
|
||||
|
||||
data = serializers.get_track_data(
|
||||
album=upload.track.album, track=upload.track, upload=upload
|
||||
)
|
||||
|
||||
assert data["contentType"] == expected
|
||||
|
||||
|
||||
def test_get_album_serializer(factories):
|
||||
artist = factories["music.Artist"]()
|
||||
album = factories["music.Album"](artist=artist)
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Fixed empty contentType causing client crash in some Subsonic payloads (#893)
|
Loading…
Reference in New Issue