From b69e03084d142f530879a063f4844b1ee432e37a Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Mon, 13 May 2024 11:28:32 -0300 Subject: search: refactor generic process to use statements --- src/util/search-spec.js | 49 ++++++++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/src/util/search-spec.js b/src/util/search-spec.js index f9d2a035..dc58b276 100644 --- a/src/util/search-spec.js +++ b/src/util/search-spec.js @@ -109,42 +109,49 @@ export const searchSpec = { .filter(track => !track.originalReleaseTrack), ].flat(), - process: (thing, opts) => ({ - primaryName: - thing.name, + process(thing, opts) { + const fields = {}; - color: - thing.color, + fields.primaryName = + thing.name; - additionalNames: + fields.color = + thing.color; + + fields.additionalNames = (Object.hasOwn(thing, 'additionalNames') ? thing.additionalNames.map(entry => entry.name) : Object.hasOwn(thing, 'aliasNames') ? thing.aliasNames - : []), + : []); + + const contribKeys = [ + 'artistContribs', + 'bannerArtistContribs', + 'contributorContribs', + 'coverArtistContribs', + 'wallpaperArtistContribs', + ]; - contributors: - ([ - 'artistContribs', - 'bannerArtistContribs', - 'contributorContribs', - 'coverArtistContribs', - 'wallpaperArtistContribs', - ]).filter(key => Object.hasOwn(thing, key)) + fields.contributors = + contribKeys + .filter(key => Object.hasOwn(thing, key)) .flatMap(key => thing[key]) .map(contrib => contrib.artist) - .flatMap(artist => [artist.name, ...artist.aliasNames]), + .flatMap(artist => [artist.name, ...artist.aliasNames]); - groups: + fields.groups = (Object.hasOwn(thing, 'groups') ? thing.groups.map(group => group.name) : Object.hasOwn(thing, 'album') ? thing.album.groups.map(group => group.name) - : []), + : []); - artwork: - prepareArtwork(thing, opts), - }), + fields.artwork = + prepareArtwork(thing, opts); + + return fields; + }, index: [ 'primaryName', -- cgit 1.3.0-6-gf8a5