2017-11-10 07:34:45 -06:00
|
|
|
import * as validator from 'validator'
|
2017-11-14 10:31:26 -06:00
|
|
|
import { isAccountAcceptActivityValid, isAccountDeleteActivityValid, isAccountFollowActivityValid } from './account'
|
|
|
|
import { isActivityPubUrlValid } from './misc'
|
2017-11-10 07:34:45 -06:00
|
|
|
import {
|
2017-11-15 10:56:21 -06:00
|
|
|
isVideoAnnounceValid,
|
|
|
|
isVideoChannelAnnounceValid,
|
2017-11-10 07:34:45 -06:00
|
|
|
isVideoChannelCreateActivityValid,
|
2017-11-14 10:31:26 -06:00
|
|
|
isVideoChannelDeleteActivityValid,
|
|
|
|
isVideoChannelUpdateActivityValid,
|
2017-11-15 10:56:21 -06:00
|
|
|
isVideoFlagValid,
|
2017-11-10 07:34:45 -06:00
|
|
|
isVideoTorrentAddActivityValid,
|
2017-11-14 10:31:26 -06:00
|
|
|
isVideoTorrentDeleteActivityValid,
|
|
|
|
isVideoTorrentUpdateActivityValid
|
2017-11-10 07:34:45 -06: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 10:31:26 -06:00
|
|
|
isActivityPubUrlValid(activity.id) &&
|
|
|
|
isActivityPubUrlValid(activity.actor)
|
2017-11-10 07:34:45 -06:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
function isActivityValid (activity: any) {
|
|
|
|
return isVideoTorrentAddActivityValid(activity) ||
|
|
|
|
isVideoChannelCreateActivityValid(activity) ||
|
|
|
|
isVideoTorrentUpdateActivityValid(activity) ||
|
2017-11-14 10:31:26 -06:00
|
|
|
isVideoChannelUpdateActivityValid(activity) ||
|
|
|
|
isVideoTorrentDeleteActivityValid(activity) ||
|
|
|
|
isVideoChannelDeleteActivityValid(activity) ||
|
|
|
|
isAccountDeleteActivityValid(activity) ||
|
|
|
|
isAccountFollowActivityValid(activity) ||
|
2017-11-15 10:56:21 -06:00
|
|
|
isAccountAcceptActivityValid(activity) ||
|
|
|
|
isVideoFlagValid(activity) ||
|
|
|
|
isVideoAnnounceValid(activity) ||
|
|
|
|
isVideoChannelAnnounceValid(activity)
|
2017-11-10 07:34:45 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
isRootActivityValid,
|
|
|
|
isActivityValid
|
|
|
|
}
|