From 1faa4553540158a7e8b54f3aca11d96949e7352d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dario=20Vladovi=C4=87?= Date: Fri, 22 May 2020 06:15:07 +0200 Subject: [PATCH] badge: add Mastodon/Pleroma support (#396) * badge: add mastodon/pleroma support * badge(mastodon): avoid description overflow --- api/mastodon.ts | 26 ++++++++++++++++++++++++++ libs/badge-list.ts | 1 + 2 files changed, 27 insertions(+) create mode 100644 api/mastodon.ts diff --git a/api/mastodon.ts b/api/mastodon.ts new file mode 100644 index 0000000..0fb43c9 --- /dev/null +++ b/api/mastodon.ts @@ -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() + + return { + subject: `follow @${info.username}@${instance}`, + status: millify(info.followers_count), + color: '3487CE' + } +} diff --git a/libs/badge-list.ts b/libs/badge-list.ts index b370f05..ba6ab24 100644 --- a/libs/badge-list.ts +++ b/libs/badge-list.ts @@ -52,6 +52,7 @@ export const liveBadgeList = [ 'opencollective', 'keybase', 'twitter', + 'mastodon', 'tidelift', 'runkit', 'https',