Fixed off-by-one in photo plucker. Fixed source duplicate photo function not handling fallback sources.

This commit is contained in:
2019-12-12 04:04:35 +01:00
parent dbaf1a9a9c
commit 0b819713b5
5 changed files with 30 additions and 36 deletions

View File

@@ -1,21 +0,0 @@
'use strict';
const config = require('config');
// pick {photoLimit} photos evenly distributed photos from a set with {photoTotal} photos, return array of indexes starting at 1
function pluckPhotos(photos, release, specifiedLimit) {
const limit = specifiedLimit || config.media.limit;
if (photos.length <= limit) {
return photos;
}
const plucked = [1]
.concat(
Array.from({ length: limit }, (value, index) => Math.round((index + 1) * (photos.length / (limit)))),
);
return Array.from(new Set(plucked)).map(photoIndex => photos[photoIndex - 1]); // remove duplicates, may happen when photo total and photo limit are close
}
module.exports = pluckPhotos;