From f0a29721c9fb10f97faf386bc9d6b1b2fad97895 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 7 Apr 2019 21:50:36 +0900 Subject: Use PostgreSQL instead of MongoDB (#4572) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * wip * Update note.ts * Update timeline.ts * Update core.ts * wip * Update generate-visibility-query.ts * wip * wip * wip * wip * wip * Update global-timeline.ts * wip * wip * wip * Update vote.ts * wip * wip * Update create.ts * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * Update files.ts * wip * wip * Update CONTRIBUTING.md * wip * wip * wip * wip * wip * wip * wip * wip * Update read-notification.ts * wip * wip * wip * wip * wip * wip * wip * Update cancel.ts * wip * wip * wip * Update show.ts * wip * wip * Update gen-id.ts * Update create.ts * Update id.ts * wip * wip * wip * wip * wip * wip * wip * Docker: Update files about Docker (#4599) * Docker: Use cache if files used by `yarn install` was not updated This patch reduces the number of times to installing node_modules. For example, `yarn install` step will be skipped when only ".config/default.yml" is updated. * Docker: Migrate MongoDB to Postgresql Misskey uses Postgresql as a database instead of Mongodb since version 11. * Docker: Uncomment about data persistence This patch will save a lot of databases. * wip * wip * wip * Update activitypub.ts * wip * wip * wip * Update logs.ts * wip * Update drive-file.ts * Update register.ts * wip * wip * Update mentions.ts * wip * wip * wip * Update recommendation.ts * wip * Update index.ts * wip * Update recommendation.ts * Doc: Update docker.ja.md and docker.en.md (#1) (#4608) Update how to set up misskey. * wip * :v: * wip * Update note.ts * Update postgre.ts * wip * wip * wip * wip * Update add-file.ts * wip * wip * wip * Clean up * Update logs.ts * wip * :pizza: * wip * Ad notes * wip * Update api-visibility.ts * Update note.ts * Update add-file.ts * tests * tests * Update postgre.ts * Update utils.ts * wip * wip * Refactor * wip * Refactor * wip * wip * Update show-users.ts * Update update-instance.ts * wip * Update feed.ts * Update outbox.ts * Update outbox.ts * Update user.ts * wip * Update list.ts * Update update-hashtag.ts * wip * Update update-hashtag.ts * Refactor * Update update.ts * wip * wip * :v: * clean up * docs * Update push.ts * wip * Update api.ts * wip * :v: * Update make-pagination-query.ts * :v: * Delete hashtags.ts * Update instances.ts * Update instances.ts * Update create.ts * Update search.ts * Update reversi-game.ts * Update signup.ts * Update user.ts * id * Update example.yml * :art: * objectid * fix * reversi * reversi * Fix bug of chart engine * Add test of chart engine * Improve test * Better testing * Improve chart engine * Refactor * Add test of chart engine * Refactor * Add chart test * Fix bug * コミットし忘れ * Refactoring * :v: * Add tests * Add test * Extarct note tests * Refactor * 存在しないユーザーにメンションできなくなっていた問題を修正 * Fix bug * Update update-meta.ts * Fix bug * Update mention.vue * Fix bug * Update meta.ts * Update CONTRIBUTING.md * Fix bug * Fix bug * Fix bug * Clean up * Clean up * Update notification.ts * Clean up * Add mute tests * Add test * Refactor * Add test * Fix test * Refactor * Refactor * Add tests * Update utils.ts * Update utils.ts * Fix test * Update package.json * Update update.ts * Update manifest.ts * Fix bug * Fix bug * Add test * :art: * Update endpoint permissions * Updaye permisison * Update person.ts #4299 * データベースと同期しないように * Fix bug * Fix bug * Update reversi-game.ts * Use a feature of Node v11.7.0 to extract a public key (#4644) * wip * wip * :v: * Refactoring #1540 * test * test * test * test * test * test * test * Fix bug * Fix test * :sushi: * wip * #4471 * Add test for #4335 * Refactor * Fix test * Add tests * :clock4: * Fix bug * Add test * Add test * rename * Fix bug --- src/services/chart/charts/classes/instance.ts | 160 ++++++++++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 src/services/chart/charts/classes/instance.ts (limited to 'src/services/chart/charts/classes/instance.ts') diff --git a/src/services/chart/charts/classes/instance.ts b/src/services/chart/charts/classes/instance.ts new file mode 100644 index 0000000000..974eac036b --- /dev/null +++ b/src/services/chart/charts/classes/instance.ts @@ -0,0 +1,160 @@ +import autobind from 'autobind-decorator'; +import Chart, { Obj, DeepPartial } from '../../core'; +import { SchemaType } from '../../../../misc/schema'; +import { DriveFiles, Followings, Users, Notes } from '../../../../models'; +import { DriveFile } from '../../../../models/entities/drive-file'; +import { name, schema } from '../schemas/instance'; + +type InstanceLog = SchemaType; + +export default class InstanceChart extends Chart { + constructor() { + super(name, schema); + } + + @autobind + protected genNewLog(latest: InstanceLog): DeepPartial { + return { + notes: { + total: latest.notes.total, + }, + users: { + total: latest.users.total, + }, + following: { + total: latest.following.total, + }, + followers: { + total: latest.followers.total, + }, + drive: { + totalFiles: latest.drive.totalFiles, + totalUsage: latest.drive.totalUsage, + } + }; + } + + @autobind + protected async fetchActual(group: string): Promise> { + const [ + notesCount, + usersCount, + followingCount, + followersCount, + driveFiles, + driveUsage, + ] = await Promise.all([ + Notes.count({ userHost: group }), + Users.count({ host: group }), + Followings.count({ followerHost: group }), + Followings.count({ followeeHost: group }), + DriveFiles.count({ userHost: group }), + DriveFiles.clacDriveUsageOfHost(group), + ]); + + return { + notes: { + total: notesCount, + }, + users: { + total: usersCount, + }, + following: { + total: followingCount, + }, + followers: { + total: followersCount, + }, + drive: { + totalFiles: driveFiles, + totalUsage: driveUsage, + } + }; + } + + @autobind + public async requestReceived(host: string) { + await this.inc({ + requests: { + received: 1 + } + }, host); + } + + @autobind + public async requestSent(host: string, isSucceeded: boolean) { + const update: Obj = {}; + + if (isSucceeded) { + update.succeeded = 1; + } else { + update.failed = 1; + } + + await this.inc({ + requests: update + }, host); + } + + @autobind + public async newUser(host: string) { + await this.inc({ + users: { + total: 1, + inc: 1 + } + }, host); + } + + @autobind + public async updateNote(host: string, isAdditional: boolean) { + await this.inc({ + notes: { + total: isAdditional ? 1 : -1, + inc: isAdditional ? 1 : 0, + dec: isAdditional ? 0 : 1, + } + }, host); + } + + @autobind + public async updateFollowing(host: string, isAdditional: boolean) { + await this.inc({ + following: { + total: isAdditional ? 1 : -1, + inc: isAdditional ? 1 : 0, + dec: isAdditional ? 0 : 1, + } + }, host); + } + + @autobind + public async updateFollowers(host: string, isAdditional: boolean) { + await this.inc({ + followers: { + total: isAdditional ? 1 : -1, + inc: isAdditional ? 1 : 0, + dec: isAdditional ? 0 : 1, + } + }, host); + } + + @autobind + public async updateDrive(file: DriveFile, isAdditional: boolean) { + const update: Obj = {}; + + update.totalFiles = isAdditional ? 1 : -1; + update.totalUsage = isAdditional ? file.size : -file.size; + if (isAdditional) { + update.incFiles = 1; + update.incUsage = file.size; + } else { + update.decFiles = 1; + update.decUsage = file.size; + } + + await this.inc({ + drive: update + }, file.userHost); + } +} -- cgit v1.2.3-freya From 1a2229f8865e67efe840b7eeed14e233a3730dcd Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 8 Apr 2019 14:29:17 +0900 Subject: Improve instance chart --- src/services/chart/charts/classes/instance.ts | 14 +++++++++++++- src/services/chart/charts/schemas/instance.ts | 25 +++++++++++++++++++++++++ src/services/note/create.ts | 2 +- src/services/note/delete.ts | 2 +- 4 files changed, 40 insertions(+), 3 deletions(-) (limited to 'src/services/chart/charts/classes/instance.ts') diff --git a/src/services/chart/charts/classes/instance.ts b/src/services/chart/charts/classes/instance.ts index 974eac036b..55db534573 100644 --- a/src/services/chart/charts/classes/instance.ts +++ b/src/services/chart/charts/classes/instance.ts @@ -4,6 +4,7 @@ import { SchemaType } from '../../../../misc/schema'; import { DriveFiles, Followings, Users, Notes } from '../../../../models'; import { DriveFile } from '../../../../models/entities/drive-file'; import { name, schema } from '../schemas/instance'; +import { Note } from '../../../../models/entities/note'; type InstanceLog = SchemaType; @@ -107,12 +108,23 @@ export default class InstanceChart extends Chart { } @autobind - public async updateNote(host: string, isAdditional: boolean) { + public async updateNote(host: string, note: Note, isAdditional: boolean) { + const diffs = {} as any; + + if (note.replyId != null) { + diffs.reply = isAdditional ? 1 : -1; + } else if (note.renoteId != null) { + diffs.renote = isAdditional ? 1 : -1; + } else { + diffs.normal = isAdditional ? 1 : -1; + } + await this.inc({ notes: { total: isAdditional ? 1 : -1, inc: isAdditional ? 1 : 0, dec: isAdditional ? 0 : 1, + diffs: diffs } }, host); } diff --git a/src/services/chart/charts/schemas/instance.ts b/src/services/chart/charts/schemas/instance.ts index af46b33629..001f2428b5 100644 --- a/src/services/chart/charts/schemas/instance.ts +++ b/src/services/chart/charts/schemas/instance.ts @@ -21,6 +21,7 @@ export const schema = { }, } }, + notes: { type: 'object' as 'object', properties: { @@ -36,8 +37,29 @@ export const schema = { type: 'number' as 'number', description: '減少した投稿数' }, + + diffs: { + type: 'object' as 'object', + properties: { + normal: { + type: 'number' as 'number', + description: '通常の投稿数の差分' + }, + + reply: { + type: 'number' as 'number', + description: 'リプライの投稿数の差分' + }, + + renote: { + type: 'number' as 'number', + description: 'Renoteの投稿数の差分' + }, + } + }, } }, + users: { type: 'object' as 'object', properties: { @@ -55,6 +77,7 @@ export const schema = { }, } }, + following: { type: 'object' as 'object', properties: { @@ -72,6 +95,7 @@ export const schema = { }, } }, + followers: { type: 'object' as 'object', properties: { @@ -89,6 +113,7 @@ export const schema = { }, } }, + drive: { type: 'object' as 'object', properties: { diff --git a/src/services/note/create.ts b/src/services/note/create.ts index 305e173e16..05837a4daf 100644 --- a/src/services/note/create.ts +++ b/src/services/note/create.ts @@ -207,7 +207,7 @@ export default async (user: User, data: Option, silent = false) => new Promise { Instances.increment({ id: i.id }, 'notesCount', 1); - instanceChart.updateNote(i.host, true); + instanceChart.updateNote(i.host, note, true); }); } diff --git a/src/services/note/delete.ts b/src/services/note/delete.ts index 7f04d12cd5..c03c742ee1 100644 --- a/src/services/note/delete.ts +++ b/src/services/note/delete.ts @@ -56,7 +56,7 @@ export default async function(user: User, note: Note, quiet = false) { if (Users.isRemoteUser(user)) { registerOrFetchInstanceDoc(user.host).then(i => { Instances.decrement({ id: i.id }, 'notesCount', 1); - instanceChart.updateNote(i.host, false); + instanceChart.updateNote(i.host, note, false); }); } } -- cgit v1.2.3-freya From 236d72685dfec013135fc1450b890e33ec377de1 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 10 Apr 2019 00:59:41 +0900 Subject: More puny --- src/models/repositories/drive-file.ts | 3 ++- src/queue/processors/inbox.ts | 26 +++++++++++++--------- src/remote/activitypub/models/note.ts | 7 +++--- src/remote/activitypub/models/person.ts | 7 +++--- src/remote/activitypub/request.ts | 4 ++-- src/remote/resolve-user.ts | 19 ++++++---------- src/server/api/common/get-host-lower.ts | 6 ----- src/server/api/endpoints/admin/emoji/list.ts | 3 ++- .../endpoints/admin/federation/update-instance.ts | 5 +++-- .../api/endpoints/federation/show-instance.ts | 3 ++- src/server/api/endpoints/users/followers.ts | 3 ++- src/server/api/endpoints/users/following.ts | 3 ++- src/server/api/index.ts | 5 +---- src/services/chart/charts/classes/instance.ts | 13 ++++++----- 14 files changed, 52 insertions(+), 55 deletions(-) delete mode 100644 src/server/api/common/get-host-lower.ts (limited to 'src/services/chart/charts/classes/instance.ts') diff --git a/src/models/repositories/drive-file.ts b/src/models/repositories/drive-file.ts index fe0ca72bfb..817677fa3b 100644 --- a/src/models/repositories/drive-file.ts +++ b/src/models/repositories/drive-file.ts @@ -3,6 +3,7 @@ import { DriveFile } from '../entities/drive-file'; import { Users, DriveFolders } from '..'; import rap from '@prezzemolo/rap'; import { User } from '../entities/user'; +import { toPuny } from '../../misc/convert-host'; @EntityRepository(DriveFile) export class DriveFileRepository extends Repository { @@ -39,7 +40,7 @@ export class DriveFileRepository extends Repository { public async clacDriveUsageOfHost(host: string): Promise { const { sum } = await this .createQueryBuilder('file') - .where('file.userHost = :host', { host: host }) + .where('file.userHost = :host', { host: toPuny(host) }) .select('SUM(file.size)', 'sum') .getRawOne(); diff --git a/src/queue/processors/inbox.ts b/src/queue/processors/inbox.ts index 16badabcf7..481bcbb1c4 100644 --- a/src/queue/processors/inbox.ts +++ b/src/queue/processors/inbox.ts @@ -4,7 +4,6 @@ import parseAcct from '../../misc/acct/parse'; import { IRemoteUser } from '../../models/entities/user'; import perform from '../../remote/activitypub/perform'; import { resolvePerson, updatePerson } from '../../remote/activitypub/models/person'; -import { toUnicode } from 'punycode'; import { URL } from 'url'; import { publishApLogStream } from '../../services/stream'; import Logger from '../../services/logger'; @@ -13,6 +12,7 @@ import { Instances, Users, UserPublickeys } from '../../models'; import { instanceChart } from '../../services/chart'; import { UserPublickey } from '../../models/entities/user-publickey'; import fetchMeta from '../../misc/fetch-meta'; +import { toPuny } from '../../misc/convert-host'; const logger = new Logger('inbox'); @@ -33,7 +33,10 @@ export default async (job: Bull.Job): Promise => { let key: UserPublickey; if (keyIdLower.startsWith('acct:')) { - const { username, host } = parseAcct(keyIdLower.slice('acct:'.length)); + const acct = parseAcct(keyIdLower.slice('acct:'.length)); + const host = toPuny(acct.host); + const username = toPuny(acct.username); + if (host === null) { logger.warn(`request was made by local user: @${username}`); return; @@ -50,19 +53,22 @@ export default async (job: Bull.Job): Promise => { // ブロックしてたら中断 // TODO: いちいちデータベースにアクセスするのはコスト高そうなのでどっかにキャッシュしておく const meta = await fetchMeta(); - if (meta.blockedHosts.includes(host.toLowerCase())) { + if (meta.blockedHosts.includes(host)) { logger.info(`Blocked request: ${host}`); return; } - user = await Users.findOne({ usernameLower: username, host: host.toLowerCase() }) as IRemoteUser; + user = await Users.findOne({ + usernameLower: username.toLowerCase(), + host: host + }) as IRemoteUser; key = await UserPublickeys.findOne({ userId: user.id }); } else { // アクティビティ内のホストの検証 - const host = toUnicode(new URL(signature.keyId).hostname.toLowerCase()); + const host = toPuny(new URL(signature.keyId).hostname); try { ValidateActivity(activity, host); } catch (e) { @@ -73,7 +79,7 @@ export default async (job: Bull.Job): Promise => { // ブロックしてたら中断 // TODO: いちいちデータベースにアクセスするのはコスト高そうなのでどっかにキャッシュしておく const meta = await fetchMeta(); - if (meta.blockedHosts.includes(host.toLowerCase())) { + if (meta.blockedHosts.includes(host)) { logger.info(`Blocked request: ${host}`); return; } @@ -145,7 +151,7 @@ export default async (job: Bull.Job): Promise => { function ValidateActivity(activity: any, host: string) { // id (if exists) if (typeof activity.id === 'string') { - const uriHost = toUnicode(new URL(activity.id).hostname.toLowerCase()); + const uriHost = toPuny(new URL(activity.id).hostname); if (host !== uriHost) { const diag = activity.signature ? '. Has LD-Signature. Forwarded?' : ''; throw new Error(`activity.id(${activity.id}) has different host(${host})${diag}`); @@ -154,7 +160,7 @@ function ValidateActivity(activity: any, host: string) { // actor (if exists) if (typeof activity.actor === 'string') { - const uriHost = toUnicode(new URL(activity.actor).hostname.toLowerCase()); + const uriHost = toPuny(new URL(activity.actor).hostname); if (host !== uriHost) throw new Error('activity.actor has different host'); } @@ -162,13 +168,13 @@ function ValidateActivity(activity: any, host: string) { if (activity.type === 'Create' && activity.object) { // object.id (if exists) if (typeof activity.object.id === 'string') { - const uriHost = toUnicode(new URL(activity.object.id).hostname.toLowerCase()); + const uriHost = toPuny(new URL(activity.object.id).hostname); if (host !== uriHost) throw new Error('activity.object.id has different host'); } // object.attributedTo (if exists) if (typeof activity.object.attributedTo === 'string') { - const uriHost = toUnicode(new URL(activity.object.attributedTo).hostname.toLowerCase()); + const uriHost = toPuny(new URL(activity.object.attributedTo).hostname); if (host !== uriHost) throw new Error('activity.object.attributedTo has different host'); } } diff --git a/src/remote/activitypub/models/note.ts b/src/remote/activitypub/models/note.ts index cd587c51cf..07991d4eb2 100644 --- a/src/remote/activitypub/models/note.ts +++ b/src/remote/activitypub/models/note.ts @@ -8,14 +8,13 @@ import { resolveImage } from './image'; import { IRemoteUser, User } from '../../../models/entities/user'; import { fromHtml } from '../../../mfm/fromHtml'; import { ITag, extractHashtags } from './tag'; -import { toUnicode } from 'punycode'; import { unique, concat, difference } from '../../../prelude/array'; import { extractPollFromQuestion } from './question'; import vote from '../../../services/note/polls/vote'; import { apLogger } from '../logger'; import { DriveFile } from '../../../models/entities/drive-file'; import { deliverQuestionUpdate } from '../../../services/note/polls/update'; -import { extractDbHost } from '../../../misc/convert-host'; +import { extractDbHost, toPuny } from '../../../misc/convert-host'; import { Notes, Emojis, Polls } from '../../../models'; import { Note } from '../../../models/entities/note'; import { IObject, INote } from '../type'; @@ -246,8 +245,8 @@ export async function resolveNote(value: string | IObject, resolver?: Resolver): return await createNote(uri, resolver); } -export async function extractEmojis(tags: ITag[], host_: string) { - const host = toUnicode(host_.toLowerCase()); +export async function extractEmojis(tags: ITag[], host: string) { + host = toPuny(host); if (!tags) return []; diff --git a/src/remote/activitypub/models/person.ts b/src/remote/activitypub/models/person.ts index 2362455e02..715bae40e8 100644 --- a/src/remote/activitypub/models/person.ts +++ b/src/remote/activitypub/models/person.ts @@ -1,5 +1,4 @@ import * as promiseLimit from 'promise-limit'; -import { toUnicode } from 'punycode'; import config from '../../../config'; import Resolver from '../resolver'; @@ -33,7 +32,7 @@ const logger = apLogger; * @param uri Fetch target URI */ function validatePerson(x: any, uri: string) { - const expectHost = toUnicode(new URL(uri).hostname.toLowerCase()); + const expectHost = toPuny(new URL(uri).hostname); if (x == null) { return new Error('invalid person: object is null'); @@ -63,7 +62,7 @@ function validatePerson(x: any, uri: string) { return new Error('invalid person: id is not a string'); } - const idHost = toUnicode(new URL(x.id).hostname.toLowerCase()); + const idHost = toPuny(new URL(x.id).hostname); if (idHost !== expectHost) { return new Error('invalid person: id has different host'); } @@ -72,7 +71,7 @@ function validatePerson(x: any, uri: string) { return new Error('invalid person: publicKey.id is not a string'); } - const publicKeyIdHost = toUnicode(new URL(x.publicKey.id).hostname.toLowerCase()); + const publicKeyIdHost = toPuny(new URL(x.publicKey.id).hostname); if (publicKeyIdHost !== expectHost) { return new Error('invalid person: publicKey.id has different host'); } diff --git a/src/remote/activitypub/request.ts b/src/remote/activitypub/request.ts index c50d05e2a6..8aca5e8102 100644 --- a/src/remote/activitypub/request.ts +++ b/src/remote/activitypub/request.ts @@ -4,7 +4,6 @@ import { URL } from 'url'; import * as crypto from 'crypto'; import { lookup, IRunOptions } from 'lookup-dns-cache'; import * as promiseAny from 'promise-any'; -import { toUnicode } from 'punycode'; import config from '../../config'; import { ILocalUser } from '../../models/entities/user'; @@ -12,6 +11,7 @@ import { publishApLogStream } from '../../services/stream'; import { apLogger } from './logger'; import { UserKeypairs } from '../../models'; import fetchMeta from '../../misc/fetch-meta'; +import { toPuny } from '../../misc/convert-host'; export const logger = apLogger.createSubLogger('deliver'); @@ -25,7 +25,7 @@ export default async (user: ILocalUser, url: string, object: any) => { // ブロックしてたら中断 // TODO: いちいちデータベースにアクセスするのはコスト高そうなのでどっかにキャッシュしておく const meta = await fetchMeta(); - if (meta.blockedHosts.includes(toUnicode(host))) return; + if (meta.blockedHosts.includes(toPuny(host))) return; const data = JSON.stringify(object); diff --git a/src/remote/resolve-user.ts b/src/remote/resolve-user.ts index a10d3c2d84..e6a11bc0da 100644 --- a/src/remote/resolve-user.ts +++ b/src/remote/resolve-user.ts @@ -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 { +export async function resolveUser(username: string, host: string, option?: any, resync = false): Promise { 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`); } diff --git a/src/server/api/common/get-host-lower.ts b/src/server/api/common/get-host-lower.ts deleted file mode 100644 index 26ddf6c6d0..0000000000 --- a/src/server/api/common/get-host-lower.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { toUnicode } from 'punycode'; - -export default (host: string) => { - if (host == null) return null; - return toUnicode(host).toLowerCase(); -}; diff --git a/src/server/api/endpoints/admin/emoji/list.ts b/src/server/api/endpoints/admin/emoji/list.ts index 07174723b9..26385d4e23 100644 --- a/src/server/api/endpoints/admin/emoji/list.ts +++ b/src/server/api/endpoints/admin/emoji/list.ts @@ -1,6 +1,7 @@ import $ from 'cafy'; import define from '../../../define'; import { Emojis } from '../../../../../models'; +import { toPuny } from '../../../../../misc/convert-host'; export const meta = { desc: { @@ -22,7 +23,7 @@ export const meta = { export default define(meta, async (ps) => { const emojis = await Emojis.find({ - host: ps.host + host: toPuny(ps.host) }); return emojis.map(e => ({ diff --git a/src/server/api/endpoints/admin/federation/update-instance.ts b/src/server/api/endpoints/admin/federation/update-instance.ts index d1abe95a5b..90ab7a3ec5 100644 --- a/src/server/api/endpoints/admin/federation/update-instance.ts +++ b/src/server/api/endpoints/admin/federation/update-instance.ts @@ -1,6 +1,7 @@ import $ from 'cafy'; import define from '../../../define'; import { Instances } from '../../../../../models'; +import { toPuny } from '../../../../../misc/convert-host'; export const meta = { tags: ['admin'], @@ -20,13 +21,13 @@ export const meta = { }; export default define(meta, async (ps, me) => { - const instance = await Instances.findOne({ host: ps.host }); + const instance = await Instances.findOne({ host: toPuny(ps.host) }); if (instance == null) { throw new Error('instance not found'); } - Instances.update({ host: ps.host }, { + Instances.update({ host: toPuny(ps.host) }, { isMarkedAsClosed: ps.isClosed }); }); diff --git a/src/server/api/endpoints/federation/show-instance.ts b/src/server/api/endpoints/federation/show-instance.ts index 875afa05b2..9afcf28a7c 100644 --- a/src/server/api/endpoints/federation/show-instance.ts +++ b/src/server/api/endpoints/federation/show-instance.ts @@ -1,6 +1,7 @@ import $ from 'cafy'; import define from '../../define'; import { Instances } from '../../../../models'; +import { toPuny } from '../../../../misc/convert-host'; export const meta = { tags: ['federation'], @@ -16,7 +17,7 @@ export const meta = { export default define(meta, async (ps, me) => { const instance = await Instances - .findOne({ host: ps.host }); + .findOne({ host: toPuny(ps.host) }); return instance; }); diff --git a/src/server/api/endpoints/users/followers.ts b/src/server/api/endpoints/users/followers.ts index 51b007ddaa..64d63e2d03 100644 --- a/src/server/api/endpoints/users/followers.ts +++ b/src/server/api/endpoints/users/followers.ts @@ -4,6 +4,7 @@ import define from '../../define'; import { ApiError } from '../../error'; import { Users, Followings } from '../../../../models'; import { makePaginationQuery } from '../../common/make-pagination-query'; +import { toPuny } from '../../../../misc/convert-host'; export const meta = { desc: { @@ -65,7 +66,7 @@ export const meta = { export default define(meta, async (ps, me) => { const user = await Users.findOne(ps.userId != null ? { id: ps.userId } - : { usernameLower: ps.username.toLowerCase(), host: ps.host }); + : { usernameLower: ps.username.toLowerCase(), host: toPuny(ps.host) }); if (user == null) { throw new ApiError(meta.errors.noSuchUser); diff --git a/src/server/api/endpoints/users/following.ts b/src/server/api/endpoints/users/following.ts index 46550f0f77..0e28001680 100644 --- a/src/server/api/endpoints/users/following.ts +++ b/src/server/api/endpoints/users/following.ts @@ -4,6 +4,7 @@ import define from '../../define'; import { ApiError } from '../../error'; import { Users, Followings } from '../../../../models'; import { makePaginationQuery } from '../../common/make-pagination-query'; +import { toPuny } from '../../../../misc/convert-host'; export const meta = { desc: { @@ -65,7 +66,7 @@ export const meta = { export default define(meta, async (ps, me) => { const user = await Users.findOne(ps.userId != null ? { id: ps.userId } - : { usernameLower: ps.username.toLowerCase(), host: ps.host }); + : { usernameLower: ps.username.toLowerCase(), host: toPuny(ps.host) }); if (user == null) { throw new ApiError(meta.errors.noSuchUser); diff --git a/src/server/api/index.ts b/src/server/api/index.ts index 7858efd927..8c2b97775f 100644 --- a/src/server/api/index.ts +++ b/src/server/api/index.ts @@ -15,7 +15,6 @@ import signin from './private/signin'; import discord from './service/discord'; import github from './service/github'; import twitter from './service/twitter'; -import { toASCII } from 'punycode'; import { Instances } from '../../models'; // Init app @@ -71,9 +70,7 @@ router.get('/v1/instance/peers', async ctx => { select: ['host'] }); - const punyCodes = instances.map(instance => toASCII(instance.host)); - - ctx.body = punyCodes; + ctx.body = instances.map(instance => instance.host); }); // Return 404 for unknown API diff --git a/src/services/chart/charts/classes/instance.ts b/src/services/chart/charts/classes/instance.ts index 55db534573..f3d341f383 100644 --- a/src/services/chart/charts/classes/instance.ts +++ b/src/services/chart/charts/classes/instance.ts @@ -5,6 +5,7 @@ import { DriveFiles, Followings, Users, Notes } from '../../../../models'; import { DriveFile } from '../../../../models/entities/drive-file'; import { name, schema } from '../schemas/instance'; import { Note } from '../../../../models/entities/note'; +import { toPuny } from '../../../../misc/convert-host'; type InstanceLog = SchemaType; @@ -79,7 +80,7 @@ export default class InstanceChart extends Chart { requests: { received: 1 } - }, host); + }, toPuny(host)); } @autobind @@ -94,7 +95,7 @@ export default class InstanceChart extends Chart { await this.inc({ requests: update - }, host); + }, toPuny(host)); } @autobind @@ -104,7 +105,7 @@ export default class InstanceChart extends Chart { total: 1, inc: 1 } - }, host); + }, toPuny(host)); } @autobind @@ -126,7 +127,7 @@ export default class InstanceChart extends Chart { dec: isAdditional ? 0 : 1, diffs: diffs } - }, host); + }, toPuny(host)); } @autobind @@ -137,7 +138,7 @@ export default class InstanceChart extends Chart { inc: isAdditional ? 1 : 0, dec: isAdditional ? 0 : 1, } - }, host); + }, toPuny(host)); } @autobind @@ -148,7 +149,7 @@ export default class InstanceChart extends Chart { inc: isAdditional ? 1 : 0, dec: isAdditional ? 0 : 1, } - }, host); + }, toPuny(host)); } @autobind -- cgit v1.2.3-freya