From 960a180a10a515f65188162dad72e9ee6f3c0ac4 Mon Sep 17 00:00:00 2001 From: lhalbert Date: Mon, 19 Oct 2020 00:32:18 -0400 Subject: [PATCH] feat(docker): add image variant handler (#439) --- api/docker.ts | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/api/docker.ts b/api/docker.ts index 76252bc..f09cfe8 100644 --- a/api/docker.ts +++ b/api/docker.ts @@ -11,10 +11,11 @@ export default createBadgenHandler({ '/docker/pulls/amio/node-chrome': 'pulls (scoped)', '/docker/stars/library/mongo?icon=docker&label=stars': 'stars (icon & label)', '/docker/size/lukechilds/bitcoind/latest/amd64': 'size (scoped/tag/architecture)', + '/docker/size/lucashalbert/curl/latest/arm/v6': 'size (scoped/tag/architecture/variant)', }, handlers: { '/docker/:topic/:scope/:name': starPullHandler, - '/docker/size/:scope/:name/:tag?/:architecture?': sizeHandler + '/docker/size/:scope/:name/:tag?/:architecture?/:variant?': sizeHandler } }) @@ -47,9 +48,10 @@ async function starPullHandler ({ topic, scope, name }: PathArgs) { } } -async function sizeHandler ({ scope, name, tag, architecture }: PathArgs) { +async function sizeHandler ({ scope, name, tag, architecture, variant }: PathArgs) { tag = tag ? tag : 'latest' architecture = architecture ? architecture : 'amd64' + variant = variant ? variant : '' /* eslint-disable camelcase */ const endpoint = `https://hub.docker.com/v2/repositories/${scope}/${name}/tags` let body = await got(endpoint).json() @@ -70,7 +72,7 @@ async function sizeHandler ({ scope, name, tag, architecture }: PathArgs) { } } - const imageData = tagData.images.find(image => image.architecture === architecture) + let imageData = tagData.images.find(image => image.architecture === architecture) if (!imageData) { return { @@ -80,6 +82,18 @@ async function sizeHandler ({ scope, name, tag, architecture }: PathArgs) { } } + if (variant) { + imageData = tagData.images.filter(image => image.architecture === architecture).find(image => image.variant === variant) + + if (!imageData) { + return { + subject: 'docker', + status: 'unknown variant', + color: 'grey' + } + } + } + const sizeInMegabytes = (imageData.size / 1024 / 1024).toFixed(2) return {