From 81006566a590574bf028357c724e8917d1e8793a Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Fri, 12 Apr 2019 20:03:00 +0900 Subject: [PATCH] =?UTF-8?q?Fix:=20Punycode=E3=81=AA=E3=82=A4=E3=83=B3?= =?UTF-8?q?=E3=82=B9=E3=82=BF=E3=83=B3=E3=82=B9=E3=81=8C=E9=87=8D=E8=A4=87?= =?UTF-8?q?=E7=99=BB=E9=8C=B2=E3=81=95=E3=82=8C=E3=82=8B=20(#4667)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/server/api/index.ts | 5 +++-- src/services/register-or-fetch-instance-doc.ts | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) 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) {