From 072492c29b4f159b736180b9b914a706579591c4 Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Tue, 16 Oct 2018 08:55:55 +0900 Subject: [PATCH] Implement /api/v1/instance/peers (#2913) * Implement /api/v1/instance/peers * Use punycode * Remove Cache-Control * Rename --- src/server/api/index.ts | 2 ++ src/server/api/mastodon.ts | 14 ++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 src/server/api/mastodon.ts diff --git a/src/server/api/index.ts b/src/server/api/index.ts index c68f109ae..33e98f650 100644 --- a/src/server/api/index.ts +++ b/src/server/api/index.ts @@ -46,6 +46,8 @@ router.post('/signin', require('./private/signin').default); router.use(require('./service/github').routes()); router.use(require('./service/twitter').routes()); +router.use(require('./mastodon').routes()); + // Return 404 for unknown API router.all('*', async ctx => { ctx.status = 404; diff --git a/src/server/api/mastodon.ts b/src/server/api/mastodon.ts new file mode 100644 index 000000000..f2ce1c384 --- /dev/null +++ b/src/server/api/mastodon.ts @@ -0,0 +1,14 @@ +import * as Router from 'koa-router'; +import User from '../../models/user'; +import { toASCII } from 'punycode'; + +// Init router +const router = new Router(); + +router.get('/v1/instance/peers', async ctx => { + const peers = await User.distinct('host', { host: { $ne: null } }) as any as string[]; + const punyCodes = peers.map(peer => toASCII(peer)); + ctx.body = punyCodes; +}); + +module.exports = router;