Skip to content

Node Badges - Including GitHub Container Registry (GHCR) Image Size and Tags plus VirusTotal Badges

Notifications You must be signed in to change notification settings

smashedr/node-badges

Repository files navigation

Server Status Image Size Image Latest Image Tags GitHub Tag Major GitHub Tag Minor GitHub Release Version Deployments Swarm Workflow Build Workflow Lint Quality Gate Status GitHub Last Commit GitHub Repo Size GitHub Top Language GitHub Discussions GitHub Forks GitHub Repo Stars GitHub Org Stars Discord Ko-fi

Node Badges

This is a Work in Progress, but Works!

Supports both Simple Icon and Lucide Icon.

Badges include GitHub Container Registry (GHCR) Image Size and Tags, and more...

Visit the website for more details: https://smashedr.github.io/node-badges-docs/

Image Size Image Latest Image Tags YAML Command

Please let us know if you want to see a specific badge or feature....

Public Server Base URL:

https://badges.cssnr.com/

Server Status Uptime Deploy to Render

Important

This is currently in beta, expect breaking changes.

Badges

Available Badges:

Tip

Try out the new Badge Maker. This is a Work in Progress.

GHCR Image Size

Image Size

/ghcr/size/{owner}/{pacakge}
/ghcr/size/{owner}/{pacakge}/{tag}

Without the tag it defaults to latest, these are equivalent.

For more options see the Query Parameters.

Image Size

https://badges.cssnr.com/ghcr/size/smashedr/node-badges?labelColor=blueviolet&lucide=scale&color=seagreen&style=for-the-badge&label=node%20badges

GHCR Image Tags

Image Latest Image Tags

/ghcr/tags/{owner}/{pacakge}/latest
/ghcr/tags/{owner}/{pacakge}

Without latest it returns the n most recent tags, otherwise only the latest tag.

The n parameter defaults to 3, these are equivalent.

https://badges.cssnr.com/ghcr/tags/smashedr/node-badges
https://badges.cssnr.com/ghcr/tags/smashedr/node-badges?n=3

You can also change the sep parameter, add reversed and filter by valid semver tags.

Image Tags

https://badges.cssnr.com/ghcr/tags/smashedr/node-badges?labelColor=plum&lucide=activity&iconColor=black&color=paleturquoise&style=for-the-badge&label=last%20four&n=4&sep=-&reversed&semver

VirusTotal Release and Files

VT Hash VT Release

/vt/id/{hash}
/vt/{owner}/{repo}/{asset}
/vt/{owner}/{repo}/{asset}/{tag}

Warning

Going forward you need to use the file hash: SHA-256, SHA-1 or MD5.
File ID's (which end with ==) consume API calls where hashes do not.
You MUST also update the endpoint to: /vt/id/{hash}
File ID's will continue to work for existing badges; however, DO NOT ADD MORE!

The hash is the file's SHA-256, SHA-1 or MD5. The prefix is optional and can be sha256:xxxx or just xxxx.

The owner/repo/asset endpoints use the latest/tagged release asset for the repository.

If the tag parameter is omitted, the release tagged as latest in GitHub is used.

For the repo cssnr/zipline-android and the release asset app-release.apk the URL would be:

https://badges.cssnr.com/vt/cssnr/zipline-android/app-release.apk

The color of the badge is automatically determined based on the number of malicious+suspicious reports.

The default is #44cc11 (brightgreen) to #e05d44 (red) with 8 colors. Meaning 0 detections will be brightgreen and 8+ red. But 1-7 would be a color somewhere between brightgreen and red.

The start color end color and total n number of colors can be specified with query parameters.

This uses gka/chroma.js which accepts hex codes or css colors, but not badge-maker named colors.

There is currently a color tester at /color/N. This will produce a color between red and green.

https://badges.cssnr.com/colors/4?start=green&end=red&n=8
View Color Generation Code
function getRangedColor(req, index, options = {}) {
  const opts = { total: 8, start: '#44cc11', end: '#e05d44', ...options }
  opts.total = Number.parseInt(req.query.n || opts.total)
  opts.start = req.query.start || opts.start
  opts.end = req.query.end || opts.end
  const colors = chroma
    .scale([opts.start, opts.end])
    .mode('lab')
    .colors(opts.total + 1)
  const idx = Math.max(0, Math.min(opts.total, index))
  return colors[idx]
}

Note

This service does not upload the file to VirusTotal for analysis, it only fetches the result.
You can do this automatically with the cssnr/virustotal-action GitHub action.

JSON/YAML JSONPath

App Image

/json/{url}/{path}
/yaml/{url}/{path}

Both url and path are both URL Encoded.
The path is a JSONPath.

This endpoint accepts split and index.

Example showing the redis version from this docker-compose-swarm.yaml.

Redis Version

https://badges.cssnr.com/yaml/https%3A%2F%2Fraw.githubusercontent.com%2Fsmashedr%2Fnode-badges%2Frefs%2Fheads%2Fmaster%2Fdocker-compose-swarm.yaml/%24.services.redis.image?split=:&index=1&lucide=database&label=redis

Note: the badge at the top is also from this docker-compose-swarm.yaml file.

Static Badge

Alt Text

/static/{message}
/static/{message}/{label}

Create a static badge with a custom message. The label can be optionally added after the message or in the query params.

Query Parameters

The following query parameters are supported on all badges.

Parameter Default Param Value Description of the Parameter
style flat plastic, flat, flat-square, for-the-badge, social
color brightgreen Badge Background Color (right side)
label¹ badge specific Label Text (left side)
labelColor #555 Label Background Color (left side)
icon¹ badge specific Name of a Simple Icon
lucide badge specific Name of a Lucide Icon
iconColor #fff Icon Color

¹ Allowed Empty. Set to an empty value to remove it from the badge.

Note: You can set icon or lucide but not both. To disable the icon, add it to the query with no value.

For more details see the documentation for the related library, badge-maker.

Badge Specific Parameters

These are specific to certain badges. Refer to the Badges for more details.

Parameter Example Description of the Parameter
n 3 Number of items to include in the badge.
sep | List item seperator where applicable.
semver - Filter items by valid semantic versions.
reversed - Reverse the order of returned items.
split - Split the item at the delimiter.
index 0 Index of item after splitting.
start 0 Starting item.
end 0 Ending Item.

Troubleshooting

This application caches most API responses for 1 hour. Some endpoints, that don't change frequently, like VirusTotal, cache for 24 hours. Only API responses are cached, not the badge. All query parameters changes will instantly update.

Your browser is also instructed to cache the response for 1 hour. To purge the server API cache, send a PURGE request to the badge URL.

curl -X PURGE 'https://badges.cssnr.com/ghcr/tags/smashedr/node-badges'

This returns a 200 with the number of keys purged in the response.

This tool is recommended: https://hoppscotch.io/

GitHub's media proxy also caches images for 1 hour. This is purged the same way.

curl -X PURGE 'https://camo.githubusercontent.com/xxx'

Developing

You can run the dev server with Docker compose or Node run.

The VirusTotal endpoint requires a VT_API_KEY environment variable and recommends a GITHUB_TOKEN.

With Docker

Docker includes Redis and live server reloading with the docker-compose-dev.yaml file.

docker compose -f "docker-compose-dev.yaml" up --build --remove-orphans --force-recreate

Then visit: http://localhost/

How Live Reloading Works in Docker

This mounts the ./src directory into the container for live reloading with nodemon.

To use a different source path set the APP_FILES environment variable to your source.

For more details, see the docker-compose-dev.yaml file.


Set Environment Variables in Docker
cp settings.env.example settings.env
vim settings.env
export SETTINGS=settings.env

With Node

Make sure you have a redis server running and set the REDIS_URL environment variable.

export REDIS_URL=redis://localhost:6379

npm i
npm run dev

Then visit: http://localhost:3000/

Set Environment Variables for Node
cp settings.env.example settings.env
vim settings.env
set -a
source settings.env

With Custom Port

To use a different port set the PORT environment variable then run the dev server.

export PORT=8080

Deploying

This is ready for deployment using both Docker and Node.

If using Node you need a Redis server.

To Docker

Deploy to Render

This is designed to be deployed with Docker Compose which includes redis.

To deploy to a Standalone Docker host, see docker-compose.yaml.

To deploy to a Swarm cluster using Traefik, see docker-compose-swarm.yaml.

To run directly, you need to set the REDIS_URL. You can NOT use localhost in docker.

docker run -e "REDIS_URL=redis://redis:6379" -p 80:3000 ghcr.io/smashedr/node-badges:latest

Change 80 to the host port you want the app to listen on.
The container port should be 3000 unless you set the PORT variable.

docker run -e "REDIS_URL=redis://redis:6379" -e "PORT=80" -p 80:80 ghcr.io/smashedr/node-badges:latest

To Node

This is ready to be deployed to services like Render using their Redis (Render Key Value) store. You can set the redis server url with the REDIS_URL environment variable. The default value is redis://redis:6379.

The server listens on the PORT environment variable and installs/starts normally.

npm install
npm start

To use without redis, install node-cache, comment out the redis lines, and uncomment the node-cache lines.

Resources

The app loads all Simple Icon and Lucide Icon into memory. This makes the base memory usage about 80 MB. Therefore, you should allocate at least 100 MB for request overhead.

NAME                        CPU %  MEM USAGE
smashedr-node-badges_app    0.00%  80.52MiB
smashedr-node-badges_nginx  0.00%  4.984MiB
smashedr-node-badges_redis  0.00%  4.879MiB

Support

For general help or to request a feature, see:

If you are experiencing an issue/bug or getting unexpected results, you can:

For more information, see the CSSNR SUPPORT.md.

Contributing

If you would like to submit a PR, please review the CONTRIBUTING.md.

Please consider making a donation to support the development of this project and additional open source projects.

Ko-fi

For a full list of current projects visit: https://cssnr.github.io/

About

Node Badges - Including GitHub Container Registry (GHCR) Image Size and Tags plus VirusTotal Badges

Resources

Contributing

Stars

Watchers

Forks

Sponsor this project

Packages