ドメインは常にPunycodeで保存するように
This commit is contained in:
parent
4d64fd665e
commit
33a9783ae5
@ -7,6 +7,7 @@ import { URL } from 'url';
|
||||
import * as yaml from 'js-yaml';
|
||||
import { Source, Mixin } from './types';
|
||||
import * as pkg from '../../package.json';
|
||||
import { toPuny } from '../misc/convert-host';
|
||||
|
||||
/**
|
||||
* Path of configuration directory
|
||||
@ -27,12 +28,12 @@ export default function load() {
|
||||
|
||||
const url = validateUrl(config.url);
|
||||
|
||||
config.url = normalizeUrl(config.url);
|
||||
config.url = toPuny(normalizeUrl(config.url));
|
||||
|
||||
config.port = config.port || parseInt(process.env.PORT, 10);
|
||||
|
||||
mixin.host = url.host;
|
||||
mixin.hostname = url.hostname;
|
||||
mixin.host = toPuny(url.host);
|
||||
mixin.hostname = toPuny(url.hostname);
|
||||
mixin.scheme = url.protocol.replace(/:$/, '');
|
||||
mixin.wsScheme = mixin.scheme.replace('http', 'ws');
|
||||
mixin.wsUrl = `${mixin.wsScheme}://${mixin.host}`;
|
||||
|
@ -25,6 +25,7 @@ import { UserPublickey } from './models/entities/user-publickey';
|
||||
import { UserKeypair } from './models/entities/user-keypair';
|
||||
import { extractPublic } from './crypto_key';
|
||||
import { Emoji } from './models/entities/emoji';
|
||||
import { toPuny } from './misc/convert-host';
|
||||
|
||||
const u = (config as any).mongodb.user ? encodeURIComponent((config as any).mongodb.user) : null;
|
||||
const p = (config as any).mongodb.pass ? encodeURIComponent((config as any).mongodb.pass) : null;
|
||||
@ -87,7 +88,7 @@ async function main() {
|
||||
createdAt: user.createdAt || new Date(),
|
||||
username: user.username,
|
||||
usernameLower: user.username.toLowerCase(),
|
||||
host: user.host,
|
||||
host: toPuny(user.host),
|
||||
token: generateUserToken(),
|
||||
password: user.password,
|
||||
isAdmin: user.isAdmin,
|
||||
@ -133,10 +134,10 @@ async function main() {
|
||||
followeeId: following.followeeId.toHexString(),
|
||||
|
||||
// 非正規化
|
||||
followerHost: following._follower ? following._follower.host : null,
|
||||
followerHost: following._follower ? toPuny(following._follower.host) : null,
|
||||
followerInbox: following._follower ? following._follower.inbox : null,
|
||||
followerSharedInbox: following._follower ? following._follower.sharedInbox : null,
|
||||
followeeHost: following._followee ? following._followee.host : null,
|
||||
followeeHost: following._followee ? toPuny(following._followee.host) : null,
|
||||
followeeInbox: following._followee ? following._followee.inbox : null,
|
||||
followeeSharedInbox: following._followee ? following._followee.sharedInbo : null
|
||||
});
|
||||
@ -159,7 +160,7 @@ async function main() {
|
||||
await DriveFiles.save({
|
||||
id: file._id.toHexString(),
|
||||
userId: user._id.toHexString(),
|
||||
userHost: user.host,
|
||||
userHost: toPuny(user.host),
|
||||
createdAt: file.uploadDate || new Date(),
|
||||
md5: file.md5,
|
||||
name: file.filename,
|
||||
@ -191,7 +192,7 @@ async function main() {
|
||||
await DriveFiles.save({
|
||||
id: file._id.toHexString(),
|
||||
userId: user._id.toHexString(),
|
||||
userHost: user.host,
|
||||
userHost: toPuny(user.host),
|
||||
createdAt: file.uploadDate || new Date(),
|
||||
md5: file.md5,
|
||||
name: file.filename,
|
||||
@ -210,7 +211,7 @@ async function main() {
|
||||
await DriveFiles.save({
|
||||
id: file._id.toHexString(),
|
||||
userId: user._id.toHexString(),
|
||||
userHost: user.host,
|
||||
userHost: toPuny(user.host),
|
||||
createdAt: file.uploadDate || new Date(),
|
||||
md5: file.md5,
|
||||
name: file.filename,
|
||||
@ -313,7 +314,7 @@ async function main() {
|
||||
aliases: emoji.aliases,
|
||||
url: emoji.url,
|
||||
uri: emoji.uri,
|
||||
host: emoji.host,
|
||||
host: toPuny(emoji.host),
|
||||
name: emoji.name
|
||||
});
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
import Acct from './type';
|
||||
|
||||
export default (user: Acct) => {
|
||||
return user.host === null ? user.username : `${user.username}@${user.host}`;
|
||||
return user.host == null ? user.username : `${user.username}@${user.host}`;
|
||||
};
|
||||
|
@ -1,27 +1,22 @@
|
||||
import config from '../config';
|
||||
import { toUnicode, toASCII } from 'punycode';
|
||||
import { toASCII } from 'punycode';
|
||||
import { URL } from 'url';
|
||||
|
||||
export function getFullApAccount(username: string, host: string) {
|
||||
return host ? `${username}@${toApHost(host)}` : `${username}@${toApHost(config.host)}`;
|
||||
return host ? `${username}@${toPuny(host)}` : `${username}@${toPuny(config.host)}`;
|
||||
}
|
||||
|
||||
export function isSelfHost(host: string) {
|
||||
if (host == null) return true;
|
||||
return toApHost(config.host) === toApHost(host);
|
||||
return toPuny(config.host) === toPuny(host);
|
||||
}
|
||||
|
||||
export function extractDbHost(uri: string) {
|
||||
const url = new URL(uri);
|
||||
return toDbHost(url.hostname);
|
||||
return toPuny(url.hostname);
|
||||
}
|
||||
|
||||
export function toDbHost(host: string) {
|
||||
if (host == null) return null;
|
||||
return toUnicode(host.toLowerCase());
|
||||
}
|
||||
|
||||
export function toApHost(host: string) {
|
||||
export function toPuny(host: string) {
|
||||
if (host == null) return null;
|
||||
return toASCII(host.toLowerCase());
|
||||
}
|
||||
|
@ -166,7 +166,7 @@ export class UserRepository extends Repository<User> {
|
||||
}
|
||||
|
||||
public isLocalUser(user: User): user is ILocalUser {
|
||||
return user.host === null;
|
||||
return user.host == null;
|
||||
}
|
||||
|
||||
public isRemoteUser(user: User): user is IRemoteUser {
|
||||
|
@ -5,7 +5,7 @@ import follow from '../../../services/following/create';
|
||||
import parseAcct from '../../../misc/acct/parse';
|
||||
import { resolveUser } from '../../../remote/resolve-user';
|
||||
import { downloadTextFile } from '../../../misc/download-text-file';
|
||||
import { isSelfHost, toDbHost } from '../../../misc/convert-host';
|
||||
import { isSelfHost, toPuny } from '../../../misc/convert-host';
|
||||
import { Users, DriveFiles } from '../../../models';
|
||||
|
||||
const logger = queueLogger.createSubLogger('import-following');
|
||||
@ -35,7 +35,7 @@ export async function importFollowing(job: Bull.Job, done: any): Promise<void> {
|
||||
host: null,
|
||||
usernameLower: username.toLowerCase()
|
||||
}) : await Users.findOne({
|
||||
host: toDbHost(host),
|
||||
host: toPuny(host),
|
||||
usernameLower: username.toLowerCase()
|
||||
});
|
||||
|
||||
|
@ -5,7 +5,7 @@ import parseAcct from '../../../misc/acct/parse';
|
||||
import { resolveUser } from '../../../remote/resolve-user';
|
||||
import { pushUserToUserList } from '../../../services/user-list/push';
|
||||
import { downloadTextFile } from '../../../misc/download-text-file';
|
||||
import { isSelfHost, toDbHost } from '../../../misc/convert-host';
|
||||
import { isSelfHost, toPuny } from '../../../misc/convert-host';
|
||||
import { DriveFiles, Users, UserLists, UserListJoinings } from '../../../models';
|
||||
import { genId } from '../../../misc/gen-id';
|
||||
|
||||
@ -47,7 +47,7 @@ export async function importUserLists(job: Bull.Job, done: any): Promise<void> {
|
||||
host: null,
|
||||
usernameLower: username.toLowerCase()
|
||||
}) : await Users.findOne({
|
||||
host: toDbHost(host),
|
||||
host: toPuny(host),
|
||||
usernameLower: username.toLowerCase()
|
||||
});
|
||||
|
||||
|
@ -24,6 +24,7 @@ import { UserServiceLinking } from '../../../models/entities/user-service-linkin
|
||||
import { instanceChart, usersChart } from '../../../services/chart';
|
||||
import { UserPublickey } from '../../../models/entities/user-publickey';
|
||||
import { isDuplicateKeyValueError } from '../../../misc/is-duplicate-key-value-error';
|
||||
import { toPuny } from '../../../misc/convert-host';
|
||||
const logger = apLogger;
|
||||
|
||||
/**
|
||||
@ -124,7 +125,7 @@ export async function createPerson(uri: string, resolver?: Resolver): Promise<Us
|
||||
|
||||
logger.info(`Creating the Person: ${person.id}`);
|
||||
|
||||
const host = toUnicode(new URL(object.id).hostname.toLowerCase());
|
||||
const host = toPuny(new URL(object.id).hostname);
|
||||
|
||||
const { fields, services } = analyzeAttachments(person.attachment);
|
||||
|
||||
|
@ -11,6 +11,7 @@ import { usersChart } from '../../../services/chart';
|
||||
import { UserServiceLinking } from '../../../models/entities/user-service-linking';
|
||||
import { User } from '../../../models/entities/user';
|
||||
import { UserKeypair } from '../../../models/entities/user-keypair';
|
||||
import { toPuny } from '../../../misc/convert-host';
|
||||
|
||||
export default async (ctx: Koa.BaseContext) => {
|
||||
const body = ctx.request.body as any;
|
||||
@ -103,7 +104,7 @@ export default async (ctx: Koa.BaseContext) => {
|
||||
createdAt: new Date(),
|
||||
username: username,
|
||||
usernameLower: username.toLowerCase(),
|
||||
host: host,
|
||||
host: toPuny(host),
|
||||
token: secret,
|
||||
password: hash,
|
||||
isAdmin: config.autoAdmin && usersCount === 0,
|
||||
|
@ -24,7 +24,7 @@ export default class extends Channel {
|
||||
if (!(
|
||||
this.user.id === note.userId ||
|
||||
this.following.includes(note.userId) ||
|
||||
note.user.host === null
|
||||
note.user.host == null
|
||||
)) return;
|
||||
|
||||
if (['followers', 'specified'].includes(note.visibility)) {
|
||||
|
@ -2,10 +2,13 @@ import { Instance } from '../models/entities/instance';
|
||||
import { Instances } from '../models';
|
||||
import { federationChart } from './chart';
|
||||
import { genId } from '../misc/gen-id';
|
||||
import { toPuny } from '../misc/convert-host';
|
||||
|
||||
export async function registerOrFetchInstanceDoc(host: string): Promise<Instance> {
|
||||
if (host == null) return null;
|
||||
|
||||
host = toPuny(host);
|
||||
|
||||
const index = await Instances.findOne({ host });
|
||||
|
||||
if (index == null) {
|
||||
|
Loading…
Reference in New Issue
Block a user