Attachments

This commit is contained in:
Eliot Berriot 2019-11-25 09:49:06 +01:00
parent 421b441dbe
commit c84396e669
50 changed files with 879 additions and 261 deletions

View file

@ -89,7 +89,7 @@ class GetArtistSerializer(serializers.Serializer):
"created": to_subsonic_date(album.creation_date),
"songCount": len(album.tracks.all()),
}
if album.cover:
if album.attachment_cover_id:
album_data["coverArt"] = "al-{}".format(album.id)
if album.release_date:
album_data["year"] = album.release_date.year
@ -122,7 +122,7 @@ def get_track_data(album, track, upload):
"artistId": album.artist.pk,
"type": "music",
}
if track.album.cover:
if track.album.attachment_cover_id:
data["coverArt"] = "al-{}".format(track.album.id)
if upload.bitrate:
data["bitrate"] = int(upload.bitrate / 1000)
@ -141,7 +141,7 @@ def get_album2_data(album):
"artist": album.artist.name,
"created": to_subsonic_date(album.creation_date),
}
if album.cover:
if album.attachment_cover_id:
payload["coverArt"] = "al-{}".format(album.id)
try:

View file

@ -16,7 +16,12 @@ from rest_framework.serializers import ValidationError
import funkwhale_api
from funkwhale_api.activity import record
from funkwhale_api.common import fields, preferences, utils as common_utils
from funkwhale_api.common import (
fields,
preferences,
utils as common_utils,
tasks as common_tasks,
)
from funkwhale_api.favorites.models import TrackFavorite
from funkwhale_api.moderation import filters as moderation_filters
from funkwhale_api.music import models as music_models
@ -732,20 +737,23 @@ class SubsonicViewSet(viewsets.GenericViewSet):
try:
album_id = int(id.replace("al-", ""))
album = (
music_models.Album.objects.exclude(cover__isnull=True)
.exclude(cover="")
music_models.Album.objects.exclude(attachment_cover=None)
.select_related("attachment_cover")
.get(pk=album_id)
)
except (TypeError, ValueError, music_models.Album.DoesNotExist):
return response.Response(
{"error": {"code": 70, "message": "cover art not found."}}
)
cover = album.cover
attachment = album.attachment_cover
else:
return response.Response(
{"error": {"code": 70, "message": "cover art not found."}}
)
if not attachment.file:
common_tasks.fetch_remote_attachment(attachment)
cover = attachment.file
mapping = {"nginx": "X-Accel-Redirect", "apache2": "X-Sendfile"}
path = music_views.get_file_path(cover)
file_header = mapping[settings.REVERSE_PROXY_TYPE]