diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2019-04-10 00:59:41 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2019-04-10 00:59:41 +0900 |
| commit | 236d72685dfec013135fc1450b890e33ec377de1 (patch) | |
| tree | b4d06e3587da7de4b35a822d6dcfe74367bdfa38 /src/remote | |
| parent | Fix bug (diff) | |
| download | sharkey-236d72685dfec013135fc1450b890e33ec377de1.tar.gz sharkey-236d72685dfec013135fc1450b890e33ec377de1.tar.bz2 sharkey-236d72685dfec013135fc1450b890e33ec377de1.zip | |
More puny
Diffstat (limited to 'src/remote')
| -rw-r--r-- | src/remote/activitypub/models/note.ts | 7 | ||||
| -rw-r--r-- | src/remote/activitypub/models/person.ts | 7 | ||||
| -rw-r--r-- | src/remote/activitypub/request.ts | 4 | ||||
| -rw-r--r-- | src/remote/resolve-user.ts | 19 |
4 files changed, 15 insertions, 22 deletions
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<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`); } |