diff options
| author | MeiMei <30769358+mei23@users.noreply.github.com> | 2018-10-16 08:55:55 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2018-10-16 08:55:55 +0900 |
| commit | 072492c29b4f159b736180b9b914a706579591c4 (patch) | |
| tree | 5667675455867d35c870a663acabc77749df0613 /src/server/api | |
| parent | Add some tests and some fixes (diff) | |
| download | sharkey-072492c29b4f159b736180b9b914a706579591c4.tar.gz sharkey-072492c29b4f159b736180b9b914a706579591c4.tar.bz2 sharkey-072492c29b4f159b736180b9b914a706579591c4.zip | |
Implement /api/v1/instance/peers (#2913)
* Implement /api/v1/instance/peers
* Use punycode
* Remove Cache-Control
* Rename
Diffstat (limited to 'src/server/api')
| -rw-r--r-- | src/server/api/index.ts | 2 | ||||
| -rw-r--r-- | src/server/api/mastodon.ts | 14 |
2 files changed, 16 insertions, 0 deletions
diff --git a/src/server/api/index.ts b/src/server/api/index.ts index c68f109ae1..33e98f650a 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 0000000000..f2ce1c384f --- /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; |