« get me outta code hell

inherit coverArtFileExtension more carefully - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2022-04-15 20:29:45 -0300
committer(quasar) nebula <qznebula@protonmail.com>2022-04-15 20:29:45 -0300
commit700d75cacd7fee23410dcaf13531ebc2b151d56a (patch)
treeb459cdfefce48948dc2363d0662f2685bb29383c
parent6cbd0236a3c94cd29a0eb419f0eaa22e93b9f320 (diff)
inherit coverArtFileExtension more carefully
-rw-r--r--src/data/things.js24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/data/things.js b/src/data/things.js
index 6ed0aa47..4cc5d061 100644
--- a/src/data/things.js
+++ b/src/data/things.js
@@ -630,6 +630,15 @@ Track.findAlbum = (track, albumData) => {
     return albumData?.find(album => album.tracks.includes(track));
 };
 
+// Another reused utility function. This one's logic is a bit more complicated.
+Track.hasCoverArt = (track, albumData, coverArtistContribsByRef, hasCoverArt) => {
+    return (
+        hasCoverArt ??
+        (coverArtistContribsByRef?.length > 0 || null) ??
+        Track.findAlbum(track, albumData)?.hasTrackArt ??
+        true);
+};
+
 Track.propertyDescriptors = {
     // Update & expose
 
@@ -661,10 +670,7 @@ Track.propertyDescriptors = {
         expose: {
             dependencies: ['albumData', 'coverArtistContribsByRef'],
             transform: (hasCoverArt, { albumData, coverArtistContribsByRef, [Track.instance]: track }) => (
-                hasCoverArt ??
-                (coverArtistContribsByRef?.length > 0 || null) ??
-                Track.findAlbum(track, albumData)?.hasTrackArt ??
-                true)
+                Track.hasCoverArt(track, albumData, coverArtistContribsByRef, hasCoverArt))
         }
     },
 
@@ -674,11 +680,13 @@ Track.propertyDescriptors = {
         update: {validate: isFileExtension},
 
         expose: {
-            dependencies: ['albumData'],
-            transform: (coverArtFileExtension, { albumData, [Track.instance]: track }) => (
+            dependencies: ['albumData', 'coverArtistContribsByRef'],
+            transform: (coverArtFileExtension, { albumData, coverArtistContribsByRef, hasCoverArt, [Track.instance]: track }) => (
                 coverArtFileExtension ??
-                Track.findAlbum(track, albumData)?.trackCoverArtFileExtension ??
-                true)
+                (Track.hasCoverArt(track, albumData, coverArtistContribsByRef, hasCoverArt)
+                    ? Track.findAlbum(track, albumData)?.trackCoverArtFileExtension
+                    : Track.findAlbum(track, albumData)?.coverArtFileExtension) ??
+                'jpg')
         }
     },