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