Migrate keybase badge to v2

pull/282/head
Amio 2019-06-01 13:21:10 +08:00
rodzic 7ce9d6bacb
commit f3300de66b
2 zmienionych plików z 47 dodań i 1 usunięć

Wyświetl plik

@ -0,0 +1,45 @@
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: 'Keybase',
examples: {
'/keybase/pgp/lukechilds': 'pgp key',
}
}
export const handlers: Handlers = {
'/keybase/:topic<pgp>/:username': handler
}
export default badgenServe(handlers)
async function handler ({ topic, username }: Args) {
const endpoint = `https://keybase.io/_/api/1.0/user/lookup.json`
const { body } = await got(endpoint, {
query: {
usernames: username,
fields: 'public_keys'
}
})
const fingerprint = body.them[0].public_keys.primary.key_fingerprint
switch (topic) {
case 'pgp':
return {
subject: 'PGP',
status: convertFingerprintTo64bit(fingerprint),
color: 'blue'
}
}
}
const convertFingerprintTo64bit = fingerprint => {
return fingerprint.slice(-16).toUpperCase().match(/.{4}/g).join(' ')
}

Wyświetl plik

@ -38,8 +38,9 @@ export const liveBadgeList = [
'xo',
'badgesize',
'jsdelivr',
'opencollective'
// utilities
'opencollective',
'keybase',
]
export async function loadExamples () {