From 712f471f1006a8061f93e2c0cc965cf7a64ff51d Mon Sep 17 00:00:00 2001
From: Agate <me@agate.blue>
Date: Fri, 28 Aug 2020 20:59:54 +0200
Subject: [PATCH] Fix #1205: Added a new, large thumbnail size for cover images

---
 api/config/settings/common.py           | 1 +
 api/funkwhale_api/common/models.py      | 7 +++++++
 api/funkwhale_api/common/serializers.py | 1 +
 api/funkwhale_api/common/views.py       | 2 +-
 api/tests/common/test_serializers.py    | 6 ++++++
 changes/changelog.d/1205.enhancement    | 1 +
 front/src/components/Queue.vue          | 4 ++--
 7 files changed, 19 insertions(+), 3 deletions(-)
 create mode 100644 changes/changelog.d/1205.enhancement

diff --git a/api/config/settings/common.py b/api/config/settings/common.py
index 06194348d7..b1283ea86d 100644
--- a/api/config/settings/common.py
+++ b/api/config/settings/common.py
@@ -1223,6 +1223,7 @@ VERSATILEIMAGEFIELD_RENDITION_KEY_SETS = {
     "attachment_square": [
         ("original", "url"),
         ("medium_square_crop", "crop__200x200"),
+        ("large_square_crop", "crop__600x600"),
     ],
 }
 VERSATILEIMAGEFIELD_SETTINGS = {
diff --git a/api/funkwhale_api/common/models.py b/api/funkwhale_api/common/models.py
index e0bd216198..688af54063 100644
--- a/api/funkwhale_api/common/models.py
+++ b/api/funkwhale_api/common/models.py
@@ -267,6 +267,13 @@ class Attachment(models.Model):
         proxy_url = reverse("api:v1:attachments-proxy", kwargs={"uuid": self.uuid})
         return federation_utils.full_url(proxy_url + "?next=medium_square_crop")
 
+    @property
+    def download_url_large_square_crop(self):
+        if self.file:
+            return utils.media_url(self.file.crop["600x600"].url)
+        proxy_url = reverse("api:v1:attachments-proxy", kwargs={"uuid": self.uuid})
+        return federation_utils.full_url(proxy_url + "?next=large_square_crop")
+
 
 class MutationAttachment(models.Model):
     """
diff --git a/api/funkwhale_api/common/serializers.py b/api/funkwhale_api/common/serializers.py
index 9210c0603c..fa194ea8aa 100644
--- a/api/funkwhale_api/common/serializers.py
+++ b/api/funkwhale_api/common/serializers.py
@@ -297,6 +297,7 @@ class AttachmentSerializer(serializers.Serializer):
         urls["source"] = o.url
         urls["original"] = o.download_url_original
         urls["medium_square_crop"] = o.download_url_medium_square_crop
+        urls["large_square_crop"] = o.download_url_large_square_crop
         return urls
 
     def create(self, validated_data):
diff --git a/api/funkwhale_api/common/views.py b/api/funkwhale_api/common/views.py
index a4818acd96..fe669ad215 100644
--- a/api/funkwhale_api/common/views.py
+++ b/api/funkwhale_api/common/views.py
@@ -175,7 +175,7 @@ class AttachmentViewSet(
             return r
 
         size = request.GET.get("next", "original").lower()
-        if size not in ["original", "medium_square_crop"]:
+        if size not in ["original", "medium_square_crop", "large_square_crop"]:
             size = "original"
 
         try:
diff --git a/api/tests/common/test_serializers.py b/api/tests/common/test_serializers.py
index 1d23efb661..e8ef04bca4 100644
--- a/api/tests/common/test_serializers.py
+++ b/api/tests/common/test_serializers.py
@@ -200,6 +200,9 @@ def test_attachment_serializer_existing_file(factories, to_api_date):
             "medium_square_crop": federation_utils.full_url(
                 attachment.file.crop["200x200"].url
             ),
+            "large_square_crop": federation_utils.full_url(
+                attachment.file.crop["600x600"].url
+            ),
         },
     }
 
@@ -227,6 +230,9 @@ def test_attachment_serializer_remote_file(factories, to_api_date):
             "medium_square_crop": federation_utils.full_url(
                 proxy_url + "?next=medium_square_crop"
             ),
+            "large_square_crop": federation_utils.full_url(
+                proxy_url + "?next=large_square_crop"
+            ),
         },
     }
 
diff --git a/changes/changelog.d/1205.enhancement b/changes/changelog.d/1205.enhancement
new file mode 100644
index 0000000000..a3ccf4dc37
--- /dev/null
+++ b/changes/changelog.d/1205.enhancement
@@ -0,0 +1 @@
+Added a new, large thumbnail size for cover images (#1205
\ No newline at end of file
diff --git a/front/src/components/Queue.vue b/front/src/components/Queue.vue
index 27365be14f..d55490656f 100644
--- a/front/src/components/Queue.vue
+++ b/front/src/components/Queue.vue
@@ -6,8 +6,8 @@
           <div class="ui six wide column current-track">
             <div class="ui basic segment" id="player">
               <template v-if="currentTrack">
-                <img ref="cover" alt="" v-if="currentTrack.cover && currentTrack.cover.urls.original" :src="$store.getters['instance/absoluteUrl'](currentTrack.cover.urls.original)">
-                <img ref="cover" alt="" v-else-if="currentTrack.album && currentTrack.album.cover && currentTrack.album.cover.urls.original" :src="$store.getters['instance/absoluteUrl'](currentTrack.album.cover.urls.original)">
+                <img ref="cover" alt="" v-if="currentTrack.cover && currentTrack.cover.urls.large_square_crop" :src="$store.getters['instance/absoluteUrl'](currentTrack.cover.urls.large_square_crop)">
+                <img ref="cover" alt="" v-else-if="currentTrack.album && currentTrack.album.cover && currentTrack.album.cover.urls.large_square_crop" :src="$store.getters['instance/absoluteUrl'](currentTrack.album.cover.urls.large_square_crop)">
                 <img class="ui image" alt="" v-else src="../assets/audio/default-cover.png">
                 <h1 class="ui header">
                   <div class="content ellipsis">
-- 
GitLab