From ae16b45c1170cd4361b8fac9fadc225101803f9a Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 13 Apr 2019 16:54:21 +0900 Subject: [PATCH] Fix bug --- src/misc/convert-host.ts | 5 +++++ src/queue/processors/inbox.ts | 4 ++-- src/server/api/endpoints/admin/emoji/list.ts | 4 ++-- src/server/api/endpoints/users/followers.ts | 4 ++-- src/server/api/endpoints/users/following.ts | 4 ++-- src/server/api/private/signup.ts | 4 ++-- 6 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/misc/convert-host.ts b/src/misc/convert-host.ts index dbf7864550..a5fb15c66f 100644 --- a/src/misc/convert-host.ts +++ b/src/misc/convert-host.ts @@ -19,3 +19,8 @@ export function extractDbHost(uri: string) { export function toPuny(host: string) { return toASCII(host.toLowerCase()); } + +export function toPunyNullable(host: string | null | undefined): string | null { + if (host == null) return null; + return toASCII(host.toLowerCase()); +} diff --git a/src/queue/processors/inbox.ts b/src/queue/processors/inbox.ts index 4deaef2ae3..05fed0566d 100644 --- a/src/queue/processors/inbox.ts +++ b/src/queue/processors/inbox.ts @@ -12,7 +12,7 @@ import { Instances, Users, UserPublickeys } from '../../models'; import { instanceChart } from '../../services/chart'; import { UserPublickey } from '../../models/entities/user-publickey'; import fetchMeta from '../../misc/fetch-meta'; -import { toPuny } from '../../misc/convert-host'; +import { toPuny, toPunyNullable } from '../../misc/convert-host'; import { validActor } from '../../remote/activitypub/type'; import { ensure } from '../../prelude/ensure'; @@ -36,7 +36,7 @@ export default async (job: Bull.Job): Promise => { if (keyIdLower.startsWith('acct:')) { const acct = parseAcct(keyIdLower.slice('acct:'.length)); - const host = acct.host ? toPuny(acct.host) : null; + const host = toPunyNullable(acct.host); const username = toPuny(acct.username); if (host === null) { diff --git a/src/server/api/endpoints/admin/emoji/list.ts b/src/server/api/endpoints/admin/emoji/list.ts index cf73e4cc75..54686a5c5a 100644 --- a/src/server/api/endpoints/admin/emoji/list.ts +++ b/src/server/api/endpoints/admin/emoji/list.ts @@ -1,7 +1,7 @@ import $ from 'cafy'; import define from '../../../define'; import { Emojis } from '../../../../../models'; -import { toPuny } from '../../../../../misc/convert-host'; +import { toPunyNullable } from '../../../../../misc/convert-host'; export const meta = { desc: { @@ -23,7 +23,7 @@ export const meta = { export default define(meta, async (ps) => { const emojis = await Emojis.find({ - host: ps.host ? toPuny(ps.host) : null + host: toPunyNullable(ps.host) }); return emojis.map(e => ({ diff --git a/src/server/api/endpoints/users/followers.ts b/src/server/api/endpoints/users/followers.ts index 88a474be7c..0cb68353ca 100644 --- a/src/server/api/endpoints/users/followers.ts +++ b/src/server/api/endpoints/users/followers.ts @@ -4,7 +4,7 @@ import define from '../../define'; import { ApiError } from '../../error'; import { Users, Followings } from '../../../../models'; import { makePaginationQuery } from '../../common/make-pagination-query'; -import { toPuny } from '../../../../misc/convert-host'; +import { toPunyNullable } from '../../../../misc/convert-host'; export const meta = { desc: { @@ -66,7 +66,7 @@ export const meta = { export default define(meta, async (ps, me) => { const user = await Users.findOne(ps.userId != null ? { id: ps.userId } - : { usernameLower: ps.username!.toLowerCase(), host: toPuny(ps.host!) }); + : { usernameLower: ps.username!.toLowerCase(), host: toPunyNullable(ps.host) }); if (user == null) { throw new ApiError(meta.errors.noSuchUser); diff --git a/src/server/api/endpoints/users/following.ts b/src/server/api/endpoints/users/following.ts index 5e017150e8..2e273dc0c2 100644 --- a/src/server/api/endpoints/users/following.ts +++ b/src/server/api/endpoints/users/following.ts @@ -4,7 +4,7 @@ import define from '../../define'; import { ApiError } from '../../error'; import { Users, Followings } from '../../../../models'; import { makePaginationQuery } from '../../common/make-pagination-query'; -import { toPuny } from '../../../../misc/convert-host'; +import { toPunyNullable } from '../../../../misc/convert-host'; export const meta = { desc: { @@ -66,7 +66,7 @@ export const meta = { export default define(meta, async (ps, me) => { const user = await Users.findOne(ps.userId != null ? { id: ps.userId } - : { usernameLower: ps.username!.toLowerCase(), host: toPuny(ps.host!) }); + : { usernameLower: ps.username!.toLowerCase(), host: toPunyNullable(ps.host) }); if (user == null) { throw new ApiError(meta.errors.noSuchUser); diff --git a/src/server/api/private/signup.ts b/src/server/api/private/signup.ts index 80f2d87b12..f8dba2eb29 100644 --- a/src/server/api/private/signup.ts +++ b/src/server/api/private/signup.ts @@ -10,7 +10,7 @@ import { genId } from '../../../misc/gen-id'; import { usersChart } from '../../../services/chart'; import { User } from '../../../models/entities/user'; import { UserKeypair } from '../../../models/entities/user-keypair'; -import { toPuny } from '../../../misc/convert-host'; +import { toPunyNullable } from '../../../misc/convert-host'; import { UserProfile } from '../../../models/entities/user-profile'; import { getConnection } from 'typeorm'; @@ -109,7 +109,7 @@ export default async (ctx: Koa.BaseContext) => { createdAt: new Date(), username: username, usernameLower: username.toLowerCase(), - host: host ? toPuny(host) : null, + host: toPunyNullable(host), token: secret, isAdmin: config.autoAdmin && usersCount === 0, }));