From d81c20f163f0884d04cd11e46221bfefc0ac9f22 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 14 Apr 2018 14:39:07 +0900 Subject: [PATCH] =?UTF-8?q?hostLower=E3=81=AF=E5=BB=83=E6=AD=A2=E3=81=97?= =?UTF-8?q?=E3=81=A6host=E3=81=ABlower=E3=81=97=E3=81=9F=E3=82=82=E3=81=AE?= =?UTF-8?q?=E3=82=92=E5=85=A5=E3=82=8C=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/models/note.ts | 1 - src/models/user.ts | 1 - src/queue/processors/http/process-inbox.ts | 2 +- src/remote/activitypub/objects/person.ts | 4 +--- src/remote/resolve-user.ts | 12 ++++++------ src/server/api/common/get-host-lower.ts | 2 +- src/server/api/endpoints/users/notes.ts | 2 +- src/server/api/private/signup.ts | 1 - src/services/note/create.ts | 1 - 9 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/models/note.ts b/src/models/note.ts index 3c1c2e18e..6d315db4c 100644 --- a/src/models/note.ts +++ b/src/models/note.ts @@ -66,7 +66,6 @@ export type INote = { }; _user: { host: string; - hostLower: string; account: { inbox?: string; }; diff --git a/src/models/user.ts b/src/models/user.ts index 97b7a997e..cf5a4a361 100644 --- a/src/models/user.ts +++ b/src/models/user.ts @@ -49,7 +49,6 @@ type IUserBase = { isSuspended: boolean; keywords: string[]; host: string; - hostLower: string; }; export interface ILocalUser extends IUserBase { diff --git a/src/queue/processors/http/process-inbox.ts b/src/queue/processors/http/process-inbox.ts index ce5b7d5a8..a2c6bf4f9 100644 --- a/src/queue/processors/http/process-inbox.ts +++ b/src/queue/processors/http/process-inbox.ts @@ -32,7 +32,7 @@ export default async (job: kue.Job, done): Promise => { return; } - user = await User.findOne({ usernameLower: username, hostLower: host }) as IRemoteUser; + user = await User.findOne({ usernameLower: username, host: host.toLowerCase() }) as IRemoteUser; } else { user = await User.findOne({ host: { $ne: null }, diff --git a/src/remote/activitypub/objects/person.ts b/src/remote/activitypub/objects/person.ts index f7ec064cd..6c060f879 100644 --- a/src/remote/activitypub/objects/person.ts +++ b/src/remote/activitypub/objects/person.ts @@ -74,8 +74,7 @@ export async function createPerson(value: any, resolver?: Resolver): Promise matched.toLowerCase()); + const host = toUnicode(finger.subject.replace(/^.*?@/, '')).toLowerCase(); const summaryDOM = JSDOM.fragment(person.summary); // Create user @@ -92,7 +91,6 @@ export async function createPerson(value: any, resolver?: Resolver): Promise { +export default async (username, _host, option) => { const usernameLower = username.toLowerCase(); - const hostLowerAscii = toASCII(host).toLowerCase(); - const hostLower = toUnicode(hostLowerAscii); + const hostAscii = toASCII(_host).toLowerCase(); + const host = toUnicode(hostAscii); - if (config.host == hostLower) { + if (config.host == host) { return await User.findOne({ usernameLower }); } - let user = await User.findOne({ usernameLower, hostLower }, option); + let user = await User.findOne({ usernameLower, host }, option); if (user === null) { - const acctLower = `${usernameLower}@${hostLowerAscii}`; + const acctLower = `${usernameLower}@${hostAscii}`; const finger = await webFinger(acctLower); const self = finger.links.find(link => link.rel && link.rel.toLowerCase() === 'self'); diff --git a/src/server/api/common/get-host-lower.ts b/src/server/api/common/get-host-lower.ts index fc4b30439..550c23300 100644 --- a/src/server/api/common/get-host-lower.ts +++ b/src/server/api/common/get-host-lower.ts @@ -1,5 +1,5 @@ import { toUnicode } from 'punycode'; export default host => { - return toUnicode(host).replace(/[A-Z]+/, match => match.toLowerCase()); + return toUnicode(host).toLowerCase(); }; diff --git a/src/server/api/endpoints/users/notes.ts b/src/server/api/endpoints/users/notes.ts index e91b75e1d..bd4247c79 100644 --- a/src/server/api/endpoints/users/notes.ts +++ b/src/server/api/endpoints/users/notes.ts @@ -65,7 +65,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => { const q = userId !== undefined ? { _id: userId } - : { usernameLower: username.toLowerCase(), hostLower: getHostLower(host) } ; + : { usernameLower: username.toLowerCase(), host: getHostLower(host) } ; // Lookup user const user = await User.findOne(q, { diff --git a/src/server/api/private/signup.ts b/src/server/api/private/signup.ts index 15257b869..cf51dec4d 100644 --- a/src/server/api/private/signup.ts +++ b/src/server/api/private/signup.ts @@ -118,7 +118,6 @@ export default async (ctx: Koa.Context) => { username: username, usernameLower: username.toLowerCase(), host: null, - hostLower: null, keypair: generateKeypair(), token: secret, email: null, diff --git a/src/services/note/create.ts b/src/services/note/create.ts index b238cd560..603851adb 100644 --- a/src/services/note/create.ts +++ b/src/services/note/create.ts @@ -78,7 +78,6 @@ export default async (user: IUser, data: { _renote: data.renote ? { userId: data.renote.userId } : null, _user: { host: user.host, - hostLower: user.hostLower, inbox: isRemoteUser(user) ? user.inbox : undefined } };