fix(front): consistent image urls generation in all sizes
This commit is contained in:
parent
3b1b707cff
commit
8cfead746d
|
@ -1398,6 +1398,7 @@ VERSATILEIMAGEFIELD_RENDITION_KEY_SETS = {
|
|||
],
|
||||
"attachment_square": [
|
||||
("original", "url"),
|
||||
("small_square_crop", "crop__50x50"),
|
||||
("medium_square_crop", "crop__200x200"),
|
||||
("large_square_crop", "crop__600x600"),
|
||||
],
|
||||
|
|
|
@ -257,6 +257,13 @@ class Attachment(models.Model):
|
|||
proxy_url = reverse("api:v1:attachments-proxy", kwargs={"uuid": self.uuid})
|
||||
return federation_utils.full_url(proxy_url + "?next=original")
|
||||
|
||||
@property
|
||||
def download_url_small_square_crop(self):
|
||||
if self.file:
|
||||
return utils.media_url(self.file.crop["50x50"].url)
|
||||
proxy_url = reverse("api:v1:attachments-proxy", kwargs={"uuid": self.uuid})
|
||||
return federation_utils.full_url(proxy_url + "?next=small_square_crop")
|
||||
|
||||
@property
|
||||
def download_url_medium_square_crop(self):
|
||||
if self.file:
|
||||
|
|
|
@ -298,6 +298,7 @@ class AttachmentSerializer(serializers.Serializer):
|
|||
urls = {}
|
||||
urls["source"] = o.url
|
||||
urls["original"] = o.download_url_original
|
||||
urls["small_square_crop"] = o.download_url_small_square_crop
|
||||
urls["medium_square_crop"] = o.download_url_medium_square_crop
|
||||
urls["large_square_crop"] = o.download_url_large_square_crop
|
||||
return urls
|
||||
|
|
|
@ -176,7 +176,12 @@ class AttachmentViewSet(
|
|||
return r
|
||||
|
||||
size = request.GET.get("next", "original").lower()
|
||||
if size not in ["original", "medium_square_crop", "large_square_crop"]:
|
||||
if size not in [
|
||||
"original",
|
||||
"small_square_crop",
|
||||
"medium_square_crop",
|
||||
"large_square_crop",
|
||||
]:
|
||||
size = "original"
|
||||
|
||||
try:
|
||||
|
|
|
@ -111,6 +111,9 @@ class GetArtistInfo2Serializer(serializers.Serializer):
|
|||
if artist.mbid:
|
||||
payload["musicBrainzId"] = TagValue(artist.mbid)
|
||||
if artist.attachment_cover:
|
||||
payload["smallImageUrl"] = TagValue(
|
||||
artist.attachment_cover.download_url_small_square_crop
|
||||
)
|
||||
payload["mediumImageUrl"] = TagValue(
|
||||
artist.attachment_cover.download_url_medium_square_crop
|
||||
)
|
||||
|
|
|
@ -195,6 +195,9 @@ def test_attachment_serializer_existing_file(factories, to_api_date):
|
|||
"urls": {
|
||||
"source": attachment.url,
|
||||
"original": federation_utils.full_url(attachment.file.url),
|
||||
"small_square_crop": federation_utils.full_url(
|
||||
attachment.file.crop["50x50"].url
|
||||
),
|
||||
"medium_square_crop": federation_utils.full_url(
|
||||
attachment.file.crop["200x200"].url
|
||||
),
|
||||
|
|
|
@ -156,6 +156,9 @@ def test_get_artist_info_2_serializer(factories):
|
|||
|
||||
expected = {
|
||||
"musicBrainzId": artist.mbid,
|
||||
"smallImageUrl": renderers.TagValue(
|
||||
artist.attachment_cover.download_url_small_square_crop
|
||||
),
|
||||
"mediumImageUrl": renderers.TagValue(
|
||||
artist.attachment_cover.download_url_medium_square_crop
|
||||
),
|
||||
|
|
|
@ -32,7 +32,7 @@ const firstArtist = artist_credit.length > 0 ? artist_credit[0].artist : null
|
|||
|
||||
const store = useStore()
|
||||
const imageUrl = computed(() => props.album.cover?.urls.original
|
||||
? store.getters['instance/absoluteUrl'](props.album.cover?.urls.large_square_crop)
|
||||
? store.getters['instance/absoluteUrl'](props.album.cover?.urls.medium_square_crop)
|
||||
: defaultCover
|
||||
)
|
||||
</script>
|
||||
|
|
|
@ -25,11 +25,11 @@ const cover = computed(() => {
|
|||
const artistCover = artist.attachment_cover ?? undefined
|
||||
|
||||
const albumCover = albums.value?.find(
|
||||
(album: Album) => album.cover?.urls.medium_square_crop
|
||||
(album: Album) => album.cover?.urls
|
||||
)?.cover
|
||||
|
||||
const trackCover = tracks.value?.find(
|
||||
(track: Track) => track.cover
|
||||
(track: Track) => track.cover?.urls
|
||||
)?.cover
|
||||
|
||||
const fallback: Cover = {
|
||||
|
|
Loading…
Reference in New Issue