activitypub: more validation for polls

This commit is contained in:
Johann150 2024-11-21 19:57:24 +01:00
parent e384b1762b
commit 0dfd5d8bc0
Signed by: Johann150
GPG key ID: 9EE6577A2A06F8F1

View file

@ -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;