Relax activity validation

This commit is contained in:
Chocobozzz 2019-05-21 09:31:53 +02:00
parent b767c4a74a
commit 4550872bcc
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
1 changed files with 13 additions and 12 deletions

View File

@ -12,18 +12,19 @@ import { isFlagActivityValid } from './flag'
import { isPlaylistObjectValid } from './playlist' import { isPlaylistObjectValid } from './playlist'
function isRootActivityValid (activity: any) { function isRootActivityValid (activity: any) {
return Array.isArray(activity['@context']) && ( return isCollection(activity) || isActivity(activity)
( }
(activity.type === 'Collection' || activity.type === 'OrderedCollection') &&
validator.isInt(activity.totalItems, { min: 0 }) && function isCollection (activity: any) {
Array.isArray(activity.items) return (activity.type === 'Collection' || activity.type === 'OrderedCollection') &&
) || validator.isInt(activity.totalItems, { min: 0 }) &&
( Array.isArray(activity.items)
isActivityPubUrlValid(activity.id) && }
exists(activity.actor) &&
(isActivityPubUrlValid(activity.actor) || isActivityPubUrlValid(activity.actor.id)) function isActivity (activity: any) {
) return isActivityPubUrlValid(activity.id) &&
) exists(activity.actor) &&
(isActivityPubUrlValid(activity.actor) || isActivityPubUrlValid(activity.actor.id))
} }
const activityCheckers: { [ P in ActivityType ]: (activity: Activity) => boolean } = { const activityCheckers: { [ P in ActivityType ]: (activity: Activity) => boolean } = {