Don't pass 'all' subgenre in discover
This commit is contained in:
parent
ced83e862a
commit
eb64ea9c96
12
lib/index.js
12
lib/index.js
|
@ -15,7 +15,15 @@ async function discover(params, options = {}) {
|
|||
let resultParams;
|
||||
return sanitizeDiscoverParams(params)
|
||||
.then( sanitizedParams => {
|
||||
resultParams = sanitizedParams;
|
||||
resultParams = Object.assign({}, sanitizedParams);
|
||||
// Passing an 'all' type subgenre (e.g. 'all-metal') in the discover url
|
||||
// actually returns far fewer / zero results than without.
|
||||
// The Bandcamp site also does not seem to include it in its discover requests...
|
||||
if (sanitizedParams.time !== undefined) {
|
||||
// If 'time' exists in sanitized params, then we have an 'all' type subgenre
|
||||
// - refer to sanitizeDiscoverParams()
|
||||
delete sanitizedParams.subgenre;
|
||||
}
|
||||
return utils.getDiscoverUrl(sanitizedParams);
|
||||
})
|
||||
.then( url => fetch(url) )
|
||||
|
@ -54,6 +62,8 @@ async function sanitizeDiscoverParams(params) {
|
|||
if (subgenreOptions) { // false if genre is 'all'
|
||||
sanitized.subgenre = getOptionValue(subgenreOptions, params.subgenre);
|
||||
}
|
||||
// 'Time' option only available when there is effectively no subgenre (e.g. genre is 'all'
|
||||
// or subgenre is 'all-metal')
|
||||
const timeAllowed = sanitized.subgenre === undefined || sanitized.subgenre == subgenreOptions[0].value;
|
||||
if (timeAllowed) {
|
||||
sanitized.time = getOptionValue(options.times, params.time);
|
||||
|
|
Loading…
Reference in New Issue
Block a user