diff options
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 |
commit | 5131c2d7928bb93118b40008513488e3e8d98fc7 (patch) | |
tree | 6bc0e7422f4318570843bf8a731237a0c540ec2a /src/util | |
parent | d7922e195967eed3ad7d168f4c6ee44ef0568362 (diff) |
search, client: genericize artwork processing
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/search-spec.js | 31 |
1 files changed, 24 insertions, 7 deletions
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', ], }, |