1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
import * as validator from 'validator'
import { Activity, ActivityType } from '../../../../shared/models/activitypub/activity'
import { isAccountAcceptActivityValid, isAccountDeleteActivityValid, isAccountFollowActivityValid } from './account'
import { isAnnounceValid } from './announce'
import { isActivityPubUrlValid } from './misc'
import { isUndoValid } from './undo'
import { isVideoChannelCreateActivityValid, isVideoChannelDeleteActivityValid, isVideoChannelUpdateActivityValid } from './video-channels'
import {
isVideoFlagValid,
isVideoTorrentAddActivityValid,
isVideoTorrentDeleteActivityValid,
isVideoTorrentUpdateActivityValid
} 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)
) ||
(
isActivityPubUrlValid(activity.id) &&
isActivityPubUrlValid(activity.actor)
)
}
const activityCheckers: { [ P in ActivityType ]: (activity: Activity) => boolean } = {
Create: checkCreateActivity,
Add: checkAddActivity,
Update: checkUpdateActivity,
Delete: checkDeleteActivity,
Follow: checkFollowActivity,
Accept: checkAcceptActivity,
Announce: checkAnnounceActivity,
Undo: checkUndoActivity
}
function isActivityValid (activity: any) {
const checker = activityCheckers[activity.type]
// Unknown activity type
if (!checker) return false
return checker(activity)
}
// ---------------------------------------------------------------------------
export {
isRootActivityValid,
isActivityValid
}
// ---------------------------------------------------------------------------
function checkCreateActivity (activity: any) {
return isVideoChannelCreateActivityValid(activity) ||
isVideoFlagValid(activity)
}
function checkAddActivity (activity: any) {
return isVideoTorrentAddActivityValid(activity)
}
function checkUpdateActivity (activity: any) {
return isVideoTorrentUpdateActivityValid(activity) ||
isVideoChannelUpdateActivityValid(activity)
}
function checkDeleteActivity (activity: any) {
return isVideoTorrentDeleteActivityValid(activity) ||
isVideoChannelDeleteActivityValid(activity) ||
isAccountDeleteActivityValid(activity)
}
function checkFollowActivity (activity: any) {
return isAccountFollowActivityValid(activity)
}
function checkAcceptActivity (activity: any) {
return isAccountAcceptActivityValid(activity)
}
function checkAnnounceActivity (activity: any) {
return isAnnounceValid(activity)
}
function checkUndoActivity (activity: any) {
return isUndoValid(activity)
}
|