From 5131c2d7928bb93118b40008513488e3e8d98fc7 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sun, 5 May 2024 13:07:31 -0300 Subject: search, client: genericize artwork processing --- src/util/search-spec.js | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'src/util') diff --git a/src/util/search-spec.js b/src/util/search-spec.js index decfec7a..e8bc7571 100644 --- a/src/util/search-spec.js +++ b/src/util/search-spec.js @@ -1,5 +1,22 @@ // Index structures shared by client and server, and relevant interfaces. +function prepareArtwork(thing) { + switch (thing.constructor[Symbol.for('Thing.referenceType')]) { + case 'track': { + if (thing.hasUniqueCoverArt) { + return ['track', thing.album.directory]; + } else if (thing.album.hasCoverArt) { + return ['track-album', thing.album.directory]; + } else { + return undefined; + } + } + + default: + return undefined; + } +} + export const searchSpec = { generic: { query: ({ @@ -43,6 +60,9 @@ export const searchSpec = { .flatMap(key => thing[key]) .map(contrib => contrib.artist) .flatMap(artist => [artist.name, ...artist.aliasNames]), + + artwork: + prepareArtwork(thing), }), index: [ @@ -53,6 +73,7 @@ export const searchSpec = { store: [ 'primaryName', + 'artwork', ], }, @@ -98,12 +119,8 @@ export const searchSpec = { track.additionalNames .map(entry => entry.name), - artworkKind: - (track.hasUniqueCoverArt - ? 'track' - : track.album.hasCoverArt - ? 'album' - : 'none'), + artwork: + prepareArtwork(track), }), index: [ @@ -117,7 +134,7 @@ export const searchSpec = { 'color', 'name', 'albumDirectory', - 'artworkKind', + 'artwork', ], }, -- cgit 1.3.0-6-gf8a5