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 | |
parent | d7922e195967eed3ad7d168f4c6ee44ef0568362 (diff) |
search, client: genericize artwork processing
Diffstat (limited to 'src')
-rw-r--r-- | src/static/js/client.js | 54 | ||||
-rw-r--r-- | src/util/search-spec.js | 31 |
2 files changed, 64 insertions, 21 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), }); } 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', ], }, |