diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-11-20 09:43:39 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-11-27 19:40:52 +0100 |
commit | 54141398354e6e7b94aa3065a705a1251390111c (patch) | |
tree | 8d30d1b9ea8acbe04f6d404125b04fc0c9897b70 /server/helpers/custom-validators/activitypub/activity.ts | |
parent | eb8b27c93e61a896a08923dc1ca3c87ba8cf4948 (diff) | |
download | PeerTube-54141398354e6e7b94aa3065a705a1251390111c.tar.gz PeerTube-54141398354e6e7b94aa3065a705a1251390111c.tar.zst PeerTube-54141398354e6e7b94aa3065a705a1251390111c.zip |
Refractor activity pub lib/helpers
Diffstat (limited to 'server/helpers/custom-validators/activitypub/activity.ts')
-rw-r--r-- | server/helpers/custom-validators/activitypub/activity.ts | 73 |
1 files changed, 58 insertions, 15 deletions
diff --git a/server/helpers/custom-validators/activitypub/activity.ts b/server/helpers/custom-validators/activitypub/activity.ts index 8084cf7b0..9305e092c 100644 --- a/server/helpers/custom-validators/activitypub/activity.ts +++ b/server/helpers/custom-validators/activitypub/activity.ts | |||
@@ -1,11 +1,11 @@ | |||
1 | import * as validator from 'validator' | 1 | import * as validator from 'validator' |
2 | import { Activity, ActivityType } from '../../../../shared/models/activitypub/activity' | ||
2 | import { isAccountAcceptActivityValid, isAccountDeleteActivityValid, isAccountFollowActivityValid } from './account' | 3 | import { isAccountAcceptActivityValid, isAccountDeleteActivityValid, isAccountFollowActivityValid } from './account' |
4 | import { isAnnounceValid } from './announce' | ||
3 | import { isActivityPubUrlValid } from './misc' | 5 | import { isActivityPubUrlValid } from './misc' |
6 | import { isUndoValid } from './undo' | ||
7 | import { isVideoChannelCreateActivityValid, isVideoChannelDeleteActivityValid, isVideoChannelUpdateActivityValid } from './video-channels' | ||
4 | import { | 8 | import { |
5 | isAnnounceValid, | ||
6 | isVideoChannelCreateActivityValid, | ||
7 | isVideoChannelDeleteActivityValid, | ||
8 | isVideoChannelUpdateActivityValid, | ||
9 | isVideoFlagValid, | 9 | isVideoFlagValid, |
10 | isVideoTorrentAddActivityValid, | 10 | isVideoTorrentAddActivityValid, |
11 | isVideoTorrentDeleteActivityValid, | 11 | isVideoTorrentDeleteActivityValid, |
@@ -25,18 +25,23 @@ function isRootActivityValid (activity: any) { | |||
25 | ) | 25 | ) |
26 | } | 26 | } |
27 | 27 | ||
28 | const activityCheckers: { [ P in ActivityType ]: (activity: Activity) => boolean } = { | ||
29 | Create: checkCreateActivity, | ||
30 | Add: checkAddActivity, | ||
31 | Update: checkUpdateActivity, | ||
32 | Delete: checkDeleteActivity, | ||
33 | Follow: checkFollowActivity, | ||
34 | Accept: checkAcceptActivity, | ||
35 | Announce: checkAnnounceActivity, | ||
36 | Undo: checkUndoActivity | ||
37 | } | ||
38 | |||
28 | function isActivityValid (activity: any) { | 39 | function isActivityValid (activity: any) { |
29 | return isVideoTorrentAddActivityValid(activity) || | 40 | const checker = activityCheckers[activity.type] |
30 | isVideoChannelCreateActivityValid(activity) || | 41 | // Unknown activity type |
31 | isVideoTorrentUpdateActivityValid(activity) || | 42 | if (!checker) return false |
32 | isVideoChannelUpdateActivityValid(activity) || | 43 | |
33 | isVideoTorrentDeleteActivityValid(activity) || | 44 | return checker(activity) |
34 | isVideoChannelDeleteActivityValid(activity) || | ||
35 | isAccountDeleteActivityValid(activity) || | ||
36 | isAccountFollowActivityValid(activity) || | ||
37 | isAccountAcceptActivityValid(activity) || | ||
38 | isVideoFlagValid(activity) || | ||
39 | isAnnounceValid(activity) | ||
40 | } | 45 | } |
41 | 46 | ||
42 | // --------------------------------------------------------------------------- | 47 | // --------------------------------------------------------------------------- |
@@ -45,3 +50,41 @@ export { | |||
45 | isRootActivityValid, | 50 | isRootActivityValid, |
46 | isActivityValid | 51 | isActivityValid |
47 | } | 52 | } |
53 | |||
54 | // --------------------------------------------------------------------------- | ||
55 | |||
56 | function checkCreateActivity (activity: any) { | ||
57 | return isVideoChannelCreateActivityValid(activity) || | ||
58 | isVideoFlagValid(activity) | ||
59 | } | ||
60 | |||
61 | function checkAddActivity (activity: any) { | ||
62 | return isVideoTorrentAddActivityValid(activity) | ||
63 | } | ||
64 | |||
65 | function checkUpdateActivity (activity: any) { | ||
66 | return isVideoTorrentUpdateActivityValid(activity) || | ||
67 | isVideoChannelUpdateActivityValid(activity) | ||
68 | } | ||
69 | |||
70 | function checkDeleteActivity (activity: any) { | ||
71 | return isVideoTorrentDeleteActivityValid(activity) || | ||
72 | isVideoChannelDeleteActivityValid(activity) || | ||
73 | isAccountDeleteActivityValid(activity) | ||
74 | } | ||
75 | |||
76 | function checkFollowActivity (activity: any) { | ||
77 | return isAccountFollowActivityValid(activity) | ||
78 | } | ||
79 | |||
80 | function checkAcceptActivity (activity: any) { | ||
81 | return isAccountAcceptActivityValid(activity) | ||
82 | } | ||
83 | |||
84 | function checkAnnounceActivity (activity: any) { | ||
85 | return isAnnounceValid(activity) | ||
86 | } | ||
87 | |||
88 | function checkUndoActivity (activity: any) { | ||
89 | return isUndoValid(activity) | ||
90 | } | ||