From f640a8fd5b095534a3230bc22c3adb2094c904d3 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 6 Apr 2018 20:52:38 +0900 Subject: [PATCH] Resolve local Person ID --- src/remote/activitypub/resolve-person.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/remote/activitypub/resolve-person.ts b/src/remote/activitypub/resolve-person.ts index 907f198342..9cca50e416 100644 --- a/src/remote/activitypub/resolve-person.ts +++ b/src/remote/activitypub/resolve-person.ts @@ -1,11 +1,20 @@ import { JSDOM } from 'jsdom'; import { toUnicode } from 'punycode'; +import parseAcct from '../../acct/parse'; +import config from '../../config'; import User, { validateUsername, isValidName, isValidDescription } from '../../models/user'; import webFinger from '../webfinger'; import Resolver from './resolver'; import uploadFromUrl from '../../services/drive/upload-from-url'; export default async (value, verifier?: string) => { + const id = value.id || value; + const localPrefix = config.url + '/@'; + + if (id.startsWith(localPrefix)) { + return User.findOne(parseAcct(id.slice(localPrefix))); + } + const resolver = new Resolver(); const object = await resolver.resolve(value) as any; @@ -21,7 +30,7 @@ export default async (value, verifier?: string) => { throw new Error('invalid person'); } - const finger = await webFinger(object.id, verifier); + const finger = await webFinger(id, verifier); const host = toUnicode(finger.subject.replace(/^.*?@/, '')); const hostLower = host.replace(/[A-Z]+/, matched => matched.toLowerCase()); @@ -48,7 +57,7 @@ export default async (value, verifier?: string) => { publicKeyPem: object.publicKey.publicKeyPem }, inbox: object.inbox, - uri: object.id, + uri: id, }, });