Resolve local Person ID
This commit is contained in:
parent
46e8fd44c1
commit
6752594578
|
@ -1,5 +1,7 @@
|
||||||
import { JSDOM } from 'jsdom';
|
import { JSDOM } from 'jsdom';
|
||||||
import { toUnicode } from 'punycode';
|
import { toUnicode } from 'punycode';
|
||||||
|
import parseAcct from '../../acct/parse';
|
||||||
|
import config from '../../config';
|
||||||
import User, { validateUsername, isValidName, isValidDescription } from '../../models/user';
|
import User, { validateUsername, isValidName, isValidDescription } from '../../models/user';
|
||||||
import { createHttp } from '../../queue';
|
import { createHttp } from '../../queue';
|
||||||
import webFinger from '../webfinger';
|
import webFinger from '../webfinger';
|
||||||
|
@ -10,10 +12,18 @@ async function isCollection(collection) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async (parentResolver, value, verifier?: string) => {
|
export default async (parentResolver, 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, object } = await parentResolver.resolveOne(value);
|
const { resolver, object } = await parentResolver.resolveOne(value);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
object === null ||
|
object === null ||
|
||||||
|
object.id !== id ||
|
||||||
object.type !== 'Person' ||
|
object.type !== 'Person' ||
|
||||||
typeof object.preferredUsername !== 'string' ||
|
typeof object.preferredUsername !== 'string' ||
|
||||||
!validateUsername(object.preferredUsername) ||
|
!validateUsername(object.preferredUsername) ||
|
||||||
|
@ -36,7 +46,7 @@ export default async (parentResolver, value, verifier?: string) => {
|
||||||
resolved => isCollection(resolved.object) ? resolved.object : null,
|
resolved => isCollection(resolved.object) ? resolved.object : null,
|
||||||
() => null
|
() => null
|
||||||
),
|
),
|
||||||
webFinger(object.id, verifier),
|
webFinger(id, verifier),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const host = toUnicode(finger.subject.replace(/^.*?@/, ''));
|
const host = toUnicode(finger.subject.replace(/^.*?@/, ''));
|
||||||
|
@ -64,7 +74,7 @@ export default async (parentResolver, value, verifier?: string) => {
|
||||||
publicKeyPem: object.publicKey.publicKeyPem
|
publicKeyPem: object.publicKey.publicKeyPem
|
||||||
},
|
},
|
||||||
inbox: object.inbox,
|
inbox: object.inbox,
|
||||||
uri: object.id,
|
uri: id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue