diff --git a/src/server/api/index.ts b/src/server/api/index.ts index fac57ca06..28a191426 100644 --- a/src/server/api/index.ts +++ b/src/server/api/index.ts @@ -16,7 +16,8 @@ import discord from './service/discord'; import github from './service/github'; import twitter from './service/twitter'; import Instance from '../../models/instance'; -import { toASCII } from 'punycode'; +import { toApHost } from '../../misc/convert-host'; +import { unique } from '../../prelude/array'; // Init app const app = new Koa(); @@ -72,7 +73,7 @@ router.get('/v1/instance/peers', async ctx => { host: 1 }); - const punyCodes = instances.map(instance => toASCII(instance.host)); + const punyCodes = unique(instances.map(instance => toApHost(instance.host))); ctx.body = punyCodes; }); diff --git a/src/services/register-or-fetch-instance-doc.ts b/src/services/register-or-fetch-instance-doc.ts index d418cd12c..e18cc9c8b 100644 --- a/src/services/register-or-fetch-instance-doc.ts +++ b/src/services/register-or-fetch-instance-doc.ts @@ -1,9 +1,12 @@ import Instance, { IInstance } from '../models/instance'; import federationChart from '../services/chart/federation'; +import { toDbHost } from '../misc/convert-host'; export async function registerOrFetchInstanceDoc(host: string): Promise { if (host == null) return null; + host = toDbHost(host); + const index = await Instance.findOne({ host }); if (index == null) {