hostLowerは廃止してhostにlowerしたものを入れるように

This commit is contained in:
syuilo 2018-04-14 14:39:07 +09:00
parent 26c979bcec
commit d81c20f163
9 changed files with 10 additions and 16 deletions

View file

@ -66,7 +66,6 @@ export type INote = {
};
_user: {
host: string;
hostLower: string;
account: {
inbox?: string;
};

View file

@ -49,7 +49,6 @@ type IUserBase = {
isSuspended: boolean;
keywords: string[];
host: string;
hostLower: string;
};
export interface ILocalUser extends IUserBase {

View file

@ -32,7 +32,7 @@ export default async (job: kue.Job, done): Promise<void> => {
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 },

View file

@ -74,8 +74,7 @@ export async function createPerson(value: any, resolver?: Resolver): Promise<IUs
webFinger(person.id)
]);
const host = toUnicode(finger.subject.replace(/^.*?@/, ''));
const hostLower = host.replace(/[A-Z]+/, matched => 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<IUs
username: person.preferredUsername,
usernameLower: person.preferredUsername.toLowerCase(),
host,
hostLower,
publicKey: {
id: person.publicKey.id,
publicKeyPem: person.publicKey.publicKeyPem

View file

@ -4,19 +4,19 @@ import webFinger from './webfinger';
import config from '../config';
import { createPerson } from './activitypub/objects/person';
export default async (username, host, option) => {
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');

View file

@ -1,5 +1,5 @@
import { toUnicode } from 'punycode';
export default host => {
return toUnicode(host).replace(/[A-Z]+/, match => match.toLowerCase());
return toUnicode(host).toLowerCase();
};

View file

@ -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, {

View file

@ -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,

View file

@ -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
}
};