1
0
Fork 0
peertube/server/helpers/custom-validators/activitypub/activity.ts

50 lines
1.6 KiB
TypeScript
Raw Normal View History

2017-11-10 08:34:45 -05:00
import * as validator from 'validator'
2017-11-14 11:31:26 -05:00
import { isAccountAcceptActivityValid, isAccountDeleteActivityValid, isAccountFollowActivityValid } from './account'
import { isActivityPubUrlValid } from './misc'
2017-11-10 08:34:45 -05:00
import {
2017-11-15 11:56:21 -05:00
isVideoAnnounceValid,
isVideoChannelAnnounceValid,
2017-11-10 08:34:45 -05:00
isVideoChannelCreateActivityValid,
2017-11-14 11:31:26 -05:00
isVideoChannelDeleteActivityValid,
isVideoChannelUpdateActivityValid,
2017-11-15 11:56:21 -05:00
isVideoFlagValid,
2017-11-10 08:34:45 -05:00
isVideoTorrentAddActivityValid,
2017-11-14 11:31:26 -05:00
isVideoTorrentDeleteActivityValid,
isVideoTorrentUpdateActivityValid
2017-11-10 08:34:45 -05:00
} from './videos'
function isRootActivityValid (activity: any) {
return Array.isArray(activity['@context']) &&
(
(activity.type === 'Collection' || activity.type === 'OrderedCollection') &&
validator.isInt(activity.totalItems, { min: 0 }) &&
Array.isArray(activity.items)
) ||
(
2017-11-14 11:31:26 -05:00
isActivityPubUrlValid(activity.id) &&
isActivityPubUrlValid(activity.actor)
2017-11-10 08:34:45 -05:00
)
}
function isActivityValid (activity: any) {
return isVideoTorrentAddActivityValid(activity) ||
isVideoChannelCreateActivityValid(activity) ||
isVideoTorrentUpdateActivityValid(activity) ||
2017-11-14 11:31:26 -05:00
isVideoChannelUpdateActivityValid(activity) ||
isVideoTorrentDeleteActivityValid(activity) ||
isVideoChannelDeleteActivityValid(activity) ||
isAccountDeleteActivityValid(activity) ||
isAccountFollowActivityValid(activity) ||
2017-11-15 11:56:21 -05:00
isAccountAcceptActivityValid(activity) ||
isVideoFlagValid(activity) ||
isVideoAnnounceValid(activity) ||
isVideoChannelAnnounceValid(activity)
2017-11-10 08:34:45 -05:00
}
// ---------------------------------------------------------------------------
export {
isRootActivityValid,
isActivityValid
}