mirror of
https://activitypub.software/TransFem-org/Sharkey
synced 2024-12-04 03:37:27 +00:00
avoid potential crash if Question activity is corrupt
This commit is contained in:
parent
ab97b91606
commit
2afbd251e1
2 changed files with 15 additions and 3 deletions
|
@ -13,7 +13,7 @@ import type { MiRemoteUser } from '@/models/User.js';
|
||||||
import type Logger from '@/logger.js';
|
import type Logger from '@/logger.js';
|
||||||
import { bindThis } from '@/decorators.js';
|
import { bindThis } from '@/decorators.js';
|
||||||
import { UtilityService } from '@/core/UtilityService.js';
|
import { UtilityService } from '@/core/UtilityService.js';
|
||||||
import { getApId, getApType, getOneApId, isQuestion } from '../type.js';
|
import { getApId, getApType, getNullableApId, getOneApId, isQuestion } from '../type.js';
|
||||||
import { ApLoggerService } from '../ApLoggerService.js';
|
import { ApLoggerService } from '../ApLoggerService.js';
|
||||||
import { ApResolverService } from '../ApResolverService.js';
|
import { ApResolverService } from '../ApResolverService.js';
|
||||||
import type { Resolver } from '../ApResolverService.js';
|
import type { Resolver } from '../ApResolverService.js';
|
||||||
|
@ -49,10 +49,10 @@ export class ApQuestionService {
|
||||||
if (resolver == null) resolver = this.apResolverService.createResolver();
|
if (resolver == null) resolver = this.apResolverService.createResolver();
|
||||||
|
|
||||||
const question = await resolver.resolve(source);
|
const question = await resolver.resolve(source);
|
||||||
if (!isQuestion(question)) throw new UnrecoverableError(`invalid type ${getApType(question)}: ${getApId(source)}`);
|
if (!isQuestion(question)) throw new UnrecoverableError(`invalid type ${getApType(question)}: ${getNullableApId(question)}`);
|
||||||
|
|
||||||
const multiple = question.oneOf === undefined;
|
const multiple = question.oneOf === undefined;
|
||||||
if (multiple && question.anyOf === undefined) throw new Error(`invalid question - neither oneOf nor anyOf is defined: ${getApId(source)}`);
|
if (multiple && question.anyOf === undefined) throw new Error(`invalid question - neither oneOf nor anyOf is defined: ${getNullableApId(question)}`);
|
||||||
|
|
||||||
const expiresAt = question.endTime ? new Date(question.endTime) : question.closed ? new Date(question.closed) : null;
|
const expiresAt = question.endTime ? new Date(question.endTime) : question.closed ? new Date(question.closed) : null;
|
||||||
|
|
||||||
|
|
|
@ -65,6 +65,18 @@ export function getApId(value: string | IObject | [string | IObject]): string {
|
||||||
throw new UnrecoverableError('cannot determine id');
|
throw new UnrecoverableError('cannot determine id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get ActivityStreams Object id
|
||||||
|
*/
|
||||||
|
export function getNullableApId(value: string | IObject | [string | IObject]): string | null {
|
||||||
|
// eslint-disable-next-line no-param-reassign
|
||||||
|
value = fromTuple(value);
|
||||||
|
|
||||||
|
if (typeof value === 'string') return value;
|
||||||
|
if (typeof value.id === 'string') return value.id;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get ActivityStreams Object type
|
* Get ActivityStreams Object type
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue