diff --git a/index.ts b/index.ts index 6b37840..7d261f9 100644 --- a/index.ts +++ b/index.ts @@ -24,6 +24,18 @@ const signer = async function (asset: string) { return await presigner.presign(new HttpRequest(s3ObjectUrl)); } +const shots = 5 +const reduceScreenshots = function (screenshots: Array) { + if (screenshots.length <= shots) + return screenshots + else + var sc = [] + for (let i = 0; i < shots; i++) { + sc.push(screenshots[i * Math.floor((screenshots.length - 1) / (shots - 1))]) + } + return sc +} + const getScreenshots = async function (resp: object, path: string): Promise { const screenshots = resp.screenshots ? resp.screenshots : [] if (path === '/details/') { @@ -34,7 +46,7 @@ const getScreenshots = async function (resp: object, path: string): Promise } }); } else if (path === '/initial/' || path === '/query/' || path === '/streaming/') { - return screenshots.splice(0, 5).map(async (x) => { + return reduceScreenshots(screenshots).map(async (x) => { return { thumb: formatUrl(await signer(`thumb/${x}`)), }