diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2025-07-30 14:02:26 -0300 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2025-07-30 14:03:08 -0300 |
commit | cbd75344f4e149e5e7895de361af40b1dc7098e6 (patch) | |
tree | 37545813e19262f48c240970d4a90a1487b9424b | |
parent | eb76345819a30594b3d433985b379c58ab795a67 (diff) |
search: Artwork object integration
- show the first artwork - tracks without unique show the first album artwork - searchable art tags are from all artworks
-rw-r--r-- | src/common-util/search-spec.js | 79 |
1 files changed, 30 insertions, 49 deletions
diff --git a/src/common-util/search-spec.js b/src/common-util/search-spec.js index 4ea0eed2..5ff18ac2 100644 --- a/src/common-util/search-spec.js +++ b/src/common-util/search-spec.js @@ -1,57 +1,19 @@ // Index structures shared by client and server, and relevant interfaces. -function getArtworkPath(thing) { - switch (thing.constructor[Symbol.for('Thing.referenceType')]) { - case 'album': { - return [ - 'media.albumCover', - thing.directory, - thing.coverArtFileExtension, - ]; - } - - case 'flash': { - return [ - 'media.flashArt', - thing.directory, - thing.coverArtFileExtension, - ]; - } - - case 'track': { - if (thing.hasUniqueCoverArt) { - return [ - 'media.trackCover', - thing.album.directory, - thing.directory, - thing.coverArtFileExtension, - ]; - } else if (thing.album.hasCoverArt) { - return [ - 'media.albumCover', - thing.album.directory, - thing.album.coverArtFileExtension, - ]; - } else { - return null; - } - } - - default: - return null; - } -} - -function prepareArtwork(thing, { +function prepareArtwork(artwork, thing, { checkIfImagePathHasCachedThumbnails, getThumbnailEqualOrSmaller, urls, }) { + if (!artwork) { + return undefined; + } + const hasWarnings = - thing.artTags?.some(artTag => artTag.isContentWarning); + artwork.artTags?.some(artTag => artTag.isContentWarning); const artworkPath = - getArtworkPath(thing); + artwork.path; if (!artworkPath) { return undefined; @@ -92,7 +54,7 @@ function baselineProcess(thing, opts) { thing.name; fields.artwork = - prepareArtwork(thing, opts); + null; fields.color = thing.color; @@ -136,6 +98,20 @@ function genericProcess(thing, opts) { const kind = thing.constructor[Symbol.for('Thing.referenceType')]; + const boundPrepareArtwork = artwork => + prepareArtwork(artwork, thing, opts); + + fields.artwork = + (kind === 'track' && thing.hasUniqueCoverArt + ? boundPrepareArtwork(thing.trackArtworks[0]) + : kind === 'track' + ? boundPrepareArtwork(thing.album.coverArtworks[0]) + : kind === 'album' + ? boundPrepareArtwork(thing.coverArtworks[0]) + : kind === 'flash' + ? boundPrepareArtwork(thing.coverArtwork) + : null); + fields.parentName = (kind === 'track' ? thing.album.name @@ -149,9 +125,14 @@ function genericProcess(thing, opts) { fields.parentName; fields.artTags = - (thing.constructor.hasPropertyDescriptor('artTags') - ? thing.artTags.map(artTag => artTag.nameShort) - : []); + (Array.from(new Set( + (kind === 'track' + ? thing.trackArtworks.flatMap(artwork => artwork.artTags) + : kind === 'album' + ? thing.coverArtworks.flatMap(artwork => artwork.artTags) + : [])))) + + .map(artTag => artTag.nameShort); fields.additionalNames = (thing.constructor.hasPropertyDescriptor('additionalNames') |