badge: add Mastodon/Pleroma support (#396)

* badge: add mastodon/pleroma support

* badge(mastodon): avoid description overflow
pull/400/head
Dario Vladović 2020-05-22 06:15:07 +02:00 zatwierdzone przez GitHub
rodzic 558836b93c
commit 1faa455354
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
2 zmienionych plików z 27 dodań i 0 usunięć

26
api/mastodon.ts 100644
Wyświetl plik

@ -0,0 +1,26 @@
import got from '../libs/got'
import { millify } from '../libs/utils'
import { createBadgenHandler, PathArgs } from '../libs/create-badgen-handler'
export default createBadgenHandler({
title: 'Mastodon/Pleroma',
examples: {
'/mastodon/follow/1': 'followers (mastodon.social)',
'/mastodon/follow/1/mas.to': 'followers (other Mastodon instance)',
'/mastodon/follow/1/pleroma.site': 'followers (Pleroma instance)',
},
handlers: {
'/mastodon/follow/:userId/:instance?': handler
}
})
async function handler ({ userId, instance = 'mastodon.social' }: PathArgs) {
const prefixUrl = `https://${instance}/api/v1/`
const info = await got(`accounts/${userId}`, { prefixUrl }).json<any>()
return {
subject: `follow @${info.username}@${instance}`,
status: millify(info.followers_count),
color: '3487CE'
}
}

Wyświetl plik

@ -52,6 +52,7 @@ export const liveBadgeList = [
'opencollective',
'keybase',
'twitter',
'mastodon',
'tidelift',
'runkit',
'https',