activitypub: more validation for polls
This commit is contained in:
parent
e384b1762b
commit
0dfd5d8bc0
1 changed files with 5 additions and 1 deletions
|
@ -57,7 +57,7 @@ export async function updateQuestion(value: string | IObject, resolver: Resolver
|
|||
const question = await resolver.resolve(value) as IQuestion;
|
||||
apLogger.debug(`fetched question: ${JSON.stringify(question, null, 2)}`);
|
||||
|
||||
if (question.type !== 'Question') throw new Error('object is not a Question');
|
||||
if (!isQuestion(question)) throw new Error('object is not a Question');
|
||||
|
||||
const apChoices = question.oneOf || question.anyOf;
|
||||
|
||||
|
@ -67,6 +67,10 @@ export async function updateQuestion(value: string | IObject, resolver: Resolver
|
|||
const oldCount = poll.votes[poll.choices.indexOf(choice)];
|
||||
const newCount = apChoices!.filter(ap => ap.name === choice)[0].replies!.totalItems;
|
||||
|
||||
if (!Number.isInteger(newCount) || newcount < 0) {
|
||||
throw new Error(`invalid newCount: ${newCount}`);
|
||||
}
|
||||
|
||||
if (oldCount !== newCount) {
|
||||
changed = true;
|
||||
poll.votes[poll.choices.indexOf(choice)] = newCount;
|
||||
|
|
Loading…
Add table
Reference in a new issue