More puny

This commit is contained in:
syuilo
2019-04-10 00:59:41 +09:00
parent 72a5f7b1e2
commit 236d72685d
14 changed files with 52 additions and 55 deletions

View File

@ -1,4 +1,3 @@
import { toUnicode, toASCII } from 'punycode';
import webFinger from './webfinger';
import config from '../config';
import { createPerson, updatePerson } from './activitypub/models/person';
@ -7,31 +6,27 @@ import { remoteLogger } from './logger';
import chalk from 'chalk';
import { User, IRemoteUser } from '../models/entities/user';
import { Users } from '../models';
import { toPuny } from '../misc/convert-host';
const logger = remoteLogger.createSubLogger('resolve-user');
export async function resolveUser(username: string, _host: string, option?: any, resync = false): Promise<User> {
export async function resolveUser(username: string, host: string, option?: any, resync = false): Promise<User> {
const usernameLower = username.toLowerCase();
host = toPuny(host);
if (_host == null) {
if (host == null) {
logger.info(`return local user: ${usernameLower}`);
return await Users.findOne({ usernameLower, host: null });
}
const configHostAscii = toASCII(config.host).toLowerCase();
const configHost = toUnicode(configHostAscii);
const hostAscii = toASCII(_host).toLowerCase();
const host = toUnicode(hostAscii);
if (configHost == host) {
if (config.host == host) {
logger.info(`return local user: ${usernameLower}`);
return await Users.findOne({ usernameLower, host: null });
}
const user = await Users.findOne({ usernameLower, host }, option);
const acctLower = `${usernameLower}@${hostAscii}`;
const acctLower = `${usernameLower}@${host}`;
if (user == null) {
const self = await resolveSelf(acctLower);
@ -51,7 +46,7 @@ export async function resolveUser(username: string, _host: string, option?: any,
// validate uri
const uri = new URL(self.href);
if (uri.hostname !== hostAscii) {
if (uri.hostname !== host) {
throw new Error(`Invalied uri`);
}