mirror of
https://github.com/knightcrawler-stremio/knightcrawler.git
synced 2024-12-20 03:29:51 +00:00
fix limit being applied incorrectly
This commit is contained in:
@@ -53,9 +53,9 @@ function sortStreams(streams, config, type) {
|
|||||||
function _sortStreams(streams, config, type) {
|
function _sortStreams(streams, config, type) {
|
||||||
const sort = config.sort && config.sort.toLowerCase() || undefined;
|
const sort = config.sort && config.sort.toLowerCase() || undefined;
|
||||||
const limit = /^[1-9][0-9]*$/.test(config.limit) && parseInt(config.limit) || undefined;
|
const limit = /^[1-9][0-9]*$/.test(config.limit) && parseInt(config.limit) || undefined;
|
||||||
const sortedStreams = sortBySeeders(streams, config, type, limit);
|
const sortedStreams = sortBySeeders(streams, config, type);
|
||||||
if (sort === SortOptions.options.seeders.key) {
|
if (sort === SortOptions.options.seeders.key) {
|
||||||
return sortedStreams
|
return sortedStreams.slice(0, limit);
|
||||||
} else if (sort === SortOptions.options.size.key) {
|
} else if (sort === SortOptions.options.size.key) {
|
||||||
return sortBySize(sortedStreams, limit);
|
return sortBySize(sortedStreams, limit);
|
||||||
}
|
}
|
||||||
@@ -67,19 +67,19 @@ function noopSort(streams) {
|
|||||||
return streams;
|
return streams;
|
||||||
}
|
}
|
||||||
|
|
||||||
function sortBySeeders(streams, config, type, limit) {
|
function sortBySeeders(streams, config, type) {
|
||||||
// streams are already presorted by seeders and upload date
|
// streams are already presorted by seeders and upload date
|
||||||
const healthy = streams.filter(stream => extractSeeders(stream.title) >= HEALTHY_SEEDERS);
|
const healthy = streams.filter(stream => extractSeeders(stream.title) >= HEALTHY_SEEDERS);
|
||||||
const seeded = streams.filter(stream => extractSeeders(stream.title) >= SEEDED_SEEDERS);
|
const seeded = streams.filter(stream => extractSeeders(stream.title) >= SEEDED_SEEDERS);
|
||||||
|
|
||||||
if (type === Type.SERIES && hasMochConfigured(config)) {
|
if (type === Type.SERIES && hasMochConfigured(config)) {
|
||||||
return streams.slice(0, limit);
|
return streams;
|
||||||
} else if (healthy.length >= MIN_HEALTHY_COUNT) {
|
} else if (healthy.length >= MIN_HEALTHY_COUNT) {
|
||||||
return healthy.slice(0, limit);
|
return healthy;
|
||||||
} else if (seeded.length >= MAX_UNHEALTHY_COUNT) {
|
} else if (seeded.length >= MAX_UNHEALTHY_COUNT) {
|
||||||
return seeded.slice(0, MIN_HEALTHY_COUNT).slice(0, limit);
|
return seeded.slice(0, MIN_HEALTHY_COUNT);
|
||||||
}
|
}
|
||||||
return streams.slice(0, MAX_UNHEALTHY_COUNT).slice(0, limit);
|
return streams.slice(0, MAX_UNHEALTHY_COUNT);
|
||||||
}
|
}
|
||||||
|
|
||||||
function sortBySize(streams, limit) {
|
function sortBySize(streams, limit) {
|
||||||
|
|||||||
Reference in New Issue
Block a user