Migrate badgesize badge to v2

pull/282/head
Amio 2019-06-01 12:16:52 +08:00
rodzic 075e0801fa
commit 4838f795df
3 zmienionych plików z 40 dodań i 1 usunięć

Wyświetl plik

@ -0,0 +1,38 @@
import got from '../libs/got'
import {
badgenServe,
BadgenServeMeta as Meta,
BadgenServeHandlers as Handlers,
BadgenServeHandlerArgs as Args
} from '../libs/badgen-serve'
export const meta: Meta = {
title: 'Badgesize',
examples: {
'/badgesize/normal/amio/emoji.json/master/emoji-compact.json': 'normal size',
'/badgesize/brotli/amio/emoji.json/master/emoji-compact.json': 'brotli size',
'/badgesize/gzip/amio/emoji.json/master/emoji-compact.json': 'gzip size',
'/badgesize/normal/https://unpkg.com/snarkdown/dist/snarkdown.js': 'arbitrary url',
}
}
export const handlers: Handlers = {
'/badgesize/:topic/:path+': handler
}
export default badgenServe(handlers)
async function handler ({ topic, path }: Args) {
const endpoint = `https://img.badgesize.io/${path}.json`
const { prettySize, color } = await got(endpoint, {
query: {
compression: topic === 'normal' ? '' : topic
}
}).then(res => res.body)
return {
subject: topic === 'normal' ? 'size' : `${topic} size`,
status: prettySize,
color: color
}
}

Wyświetl plik

@ -28,7 +28,7 @@ const server = http.createServer(async (req, res) => {
}
// handle endpoints
const handlerName = badgeHandlers.find(h => req.url!.startsWith(`/${h}`))
const handlerName = badgeHandlers.find(h => req.url!.startsWith(`/${h}/`))
try {
if (handlerName) {

Wyświetl plik

@ -35,6 +35,7 @@ export const liveBadgeList = [
'lgtm',
'uptime-robot',
'xo',
'badgesize',
// utilities
]