2019-11-04 23:54:47 +00:00
|
|
|
'use strict';
|
|
|
|
|
2019-12-09 04:00:49 +00:00
|
|
|
const config = require('config');
|
|
|
|
|
2019-11-04 23:54:47 +00:00
|
|
|
// pick {photoLimit} photos evenly distributed photos from a set with {photoTotal} photos, return array of indexes starting at 1
|
2019-12-09 04:00:49 +00:00
|
|
|
function pluckPhotos(photos, release, specifiedLimit) {
|
|
|
|
const limit = specifiedLimit || config.media.limit;
|
|
|
|
console.log(limit);
|
|
|
|
|
2019-11-28 04:36:22 +00:00
|
|
|
const plucked = [1]
|
|
|
|
.concat(
|
2019-12-09 04:00:49 +00:00
|
|
|
Array.from({ length: limit - 1 }, (value, index) => Math.round((index + 1) * (photos.length / (limit)))),
|
2019-11-28 04:36:22 +00:00
|
|
|
);
|
|
|
|
|
2019-12-09 04:00:49 +00:00
|
|
|
return Array.from(new Set(plucked)).map(photoIndex => photos[photoIndex]); // remove duplicates, may happen when photo total and photo limit are close
|
2019-11-04 23:54:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = pluckPhotos;
|