« get me outta code hell

search, client: genericize artwork processing - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/static/js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-05-05 13:07:31 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-05-31 12:11:49 -0300
commit5131c2d7928bb93118b40008513488e3e8d98fc7 (patch)
tree6bc0e7422f4318570843bf8a731237a0c540ec2a /src/static/js
parentd7922e195967eed3ad7d168f4c6ee44ef0568362 (diff)
search, client: genericize artwork processing
Diffstat (limited to 'src/static/js')
-rw-r--r--src/static/js/client.js54
1 files changed, 40 insertions, 14 deletions
diff --git a/src/static/js/client.js b/src/static/js/client.js
index 04c0cc41..d613bc6a 100644
--- a/src/static/js/client.js
+++ b/src/static/js/client.js
@@ -3702,6 +3702,7 @@ function showSidebarSearchResults(results) {
             index,
             field,
             reference: id ?? null,
+            referenceType: (id ? id.split(':')[0] : null),
             directory: (id ? id.split(':')[1] : null),
             data: doc,
           }))));
@@ -3718,6 +3719,44 @@ function showSidebarSearchResults(results) {
   }
 }
 
+function generateSidebarSearchResult(result) {
+  switch (result.referenceType) {
+    case 'track':
+      return generateSidebarSearchTrackResult(result);
+
+    default:
+      return null;
+  }
+}
+
+function getSearchResultImageSource(result) {
+  const {artwork} = result.data;
+
+  if (!artwork) return null;
+
+  const [kind, ...opts] = artwork;
+
+  switch (kind) {
+    case 'track':
+      return rebase(
+        (`album-art`
+       + `/${opts[0]}`
+       + `/${result.directory}`
+       + `.small.jpg`),
+        'rebaseThumb');
+
+    case 'track-album':
+      return rebase(
+         (`album-art`
+        + `/${opts[0]}`
+        + `/cover.small.jpg`),
+        'rebaseThumb');
+
+    default:
+      return null;
+  }
+}
+
 function generateSidebarSearchTrackResult(result) {
   return generateSidebarSearchResultTemplate({
     href:
@@ -3730,20 +3769,7 @@ function generateSidebarSearchTrackResult(result) {
       result.data.name,
 
     imageSource:
-      (result.data.artworkKind === 'track'
-        ? rebase(
-            (`album-art`
-           + `/${result.data.albumDirectory}`
-           + `/${result.directory}`
-           + `.small.jpg`),
-            'rebaseThumb')
-     : result.data.artworkKind === 'album'
-        ? rebase(
-            (`album-art`
-           + `/${result.data.albumDirectory}`
-           + `/cover.small.jpg`),
-            'rebaseThumb')
-        : null),
+      getSearchResultImageSource(result),
   });
 }