From 37e9e061d4ad470760e7537b43ef526fca43e9ea Mon Sep 17 00:00:00 2001 From: Erki Aas Date: Fri, 16 Dec 2022 13:54:53 +0200 Subject: [PATCH] Display 5 thinned out screenshots as thumbnails --- index.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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}`)), }