mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-12-02 16:23:08 +02:00
Fix bug
This commit is contained in:
parent
0f7fbacb17
commit
dddd760efd
1 changed files with 35 additions and 27 deletions
|
@ -14,6 +14,34 @@ import htmlToMFM from '../../../mfm/html-to-mfm';
|
||||||
|
|
||||||
const log = debug('misskey:activitypub');
|
const log = debug('misskey:activitypub');
|
||||||
|
|
||||||
|
function validatePerson(x: any) {
|
||||||
|
if (x == null) {
|
||||||
|
return new Error('invalid person: object is null');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x.type != 'Person' && x.type != 'Service') {
|
||||||
|
return new Error(`invalid person: object is not a person or service '${x.type}'`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof x.preferredUsername !== 'string') {
|
||||||
|
return new Error('invalid person: preferredUsername is not a string');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof x.inbox !== 'string') {
|
||||||
|
return new Error('invalid person: inbox is not a string');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!validateUsername(x.preferredUsername)) {
|
||||||
|
return new Error('invalid person: invalid username');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isValidName(x.name == '' ? null : x.name)) {
|
||||||
|
return new Error('invalid person: invalid name');
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Personをフェッチします。
|
* Personをフェッチします。
|
||||||
*
|
*
|
||||||
|
@ -47,28 +75,10 @@ export async function createPerson(value: any, resolver?: Resolver): Promise<IUs
|
||||||
|
|
||||||
const object = await resolver.resolve(value) as any;
|
const object = await resolver.resolve(value) as any;
|
||||||
|
|
||||||
if (object == null) {
|
const err = validatePerson(object);
|
||||||
throw new Error('invalid person: object is null');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (object.type != 'Person' && object.type != 'Service') {
|
if (err) {
|
||||||
throw new Error(`invalid person: object is not a person or service '${object.type}'`);
|
throw err;
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof object.preferredUsername !== 'string') {
|
|
||||||
throw new Error('invalid person: preferredUsername is not a string');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof object.inbox !== 'string') {
|
|
||||||
throw new Error('invalid person: inbox is not a string');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!validateUsername(object.preferredUsername)) {
|
|
||||||
throw new Error('invalid person: invalid username');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isValidName(object.name == '' ? null : object.name)) {
|
|
||||||
throw new Error('invalid person: invalid name');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const person: IPerson = object;
|
const person: IPerson = object;
|
||||||
|
@ -198,12 +208,10 @@ export async function updatePerson(value: string | IObject, resolver?: Resolver)
|
||||||
|
|
||||||
const object = await resolver.resolve(value) as any;
|
const object = await resolver.resolve(value) as any;
|
||||||
|
|
||||||
if (
|
const err = validatePerson(object);
|
||||||
object == null ||
|
|
||||||
object.type !== 'Person'
|
if (err) {
|
||||||
) {
|
throw err;
|
||||||
log(`invalid person: ${JSON.stringify(object, null, 2)}`);
|
|
||||||
throw new Error('invalid person');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const person: IPerson = object;
|
const person: IPerson = object;
|
||||||
|
|
Loading…
Reference in a new issue