diff options
Diffstat (limited to 'server/helpers/custom-validators')
4 files changed, 43 insertions, 13 deletions
diff --git a/server/helpers/custom-validators/activitypub/activity.ts b/server/helpers/custom-validators/activitypub/activity.ts index 66e557d39..3a0e8197c 100644 --- a/server/helpers/custom-validators/activitypub/activity.ts +++ b/server/helpers/custom-validators/activitypub/activity.ts | |||
@@ -1,9 +1,9 @@ | |||
1 | import * as validator from 'validator' | 1 | import * as validator from 'validator' |
2 | import { Activity, ActivityType } from '../../../../shared/models/activitypub/activity' | 2 | import { Activity, ActivityType } from '../../../../shared/models/activitypub/activity' |
3 | import { isAccountAcceptActivityValid, isAccountDeleteActivityValid, isAccountFollowActivityValid } from './account' | 3 | import { isAccountAcceptActivityValid, isAccountDeleteActivityValid, isAccountFollowActivityValid } from './account' |
4 | import { isAnnounceValid } from './announce' | 4 | import { isAnnounceActivityValid } from './announce' |
5 | import { isActivityPubUrlValid } from './misc' | 5 | import { isActivityPubUrlValid } from './misc' |
6 | import { isUndoValid } from './undo' | 6 | import { isUndoActivityValid } from './undo' |
7 | import { isVideoChannelCreateActivityValid, isVideoChannelDeleteActivityValid, isVideoChannelUpdateActivityValid } from './video-channels' | 7 | import { isVideoChannelCreateActivityValid, isVideoChannelDeleteActivityValid, isVideoChannelUpdateActivityValid } from './video-channels' |
8 | import { | 8 | import { |
9 | isVideoFlagValid, | 9 | isVideoFlagValid, |
@@ -12,6 +12,7 @@ import { | |||
12 | isVideoTorrentUpdateActivityValid | 12 | isVideoTorrentUpdateActivityValid |
13 | } from './videos' | 13 | } from './videos' |
14 | import { isViewActivityValid } from './view' | 14 | import { isViewActivityValid } from './view' |
15 | import { isDislikeActivityValid, isLikeActivityValid } from './rate' | ||
15 | 16 | ||
16 | function isRootActivityValid (activity: any) { | 17 | function isRootActivityValid (activity: any) { |
17 | return Array.isArray(activity['@context']) && | 18 | return Array.isArray(activity['@context']) && |
@@ -34,7 +35,8 @@ const activityCheckers: { [ P in ActivityType ]: (activity: Activity) => boolean | |||
34 | Follow: checkFollowActivity, | 35 | Follow: checkFollowActivity, |
35 | Accept: checkAcceptActivity, | 36 | Accept: checkAcceptActivity, |
36 | Announce: checkAnnounceActivity, | 37 | Announce: checkAnnounceActivity, |
37 | Undo: checkUndoActivity | 38 | Undo: checkUndoActivity, |
39 | Like: checkLikeActivity | ||
38 | } | 40 | } |
39 | 41 | ||
40 | function isActivityValid (activity: any) { | 42 | function isActivityValid (activity: any) { |
@@ -55,9 +57,10 @@ export { | |||
55 | // --------------------------------------------------------------------------- | 57 | // --------------------------------------------------------------------------- |
56 | 58 | ||
57 | function checkCreateActivity (activity: any) { | 59 | function checkCreateActivity (activity: any) { |
58 | return isVideoChannelCreateActivityValid(activity) || | 60 | return isViewActivityValid(activity) || |
59 | isVideoFlagValid(activity) || | 61 | isDislikeActivityValid(activity) || |
60 | isViewActivityValid(activity) | 62 | isVideoChannelCreateActivityValid(activity) || |
63 | isVideoFlagValid(activity) | ||
61 | } | 64 | } |
62 | 65 | ||
63 | function checkAddActivity (activity: any) { | 66 | function checkAddActivity (activity: any) { |
@@ -84,9 +87,13 @@ function checkAcceptActivity (activity: any) { | |||
84 | } | 87 | } |
85 | 88 | ||
86 | function checkAnnounceActivity (activity: any) { | 89 | function checkAnnounceActivity (activity: any) { |
87 | return isAnnounceValid(activity) | 90 | return isAnnounceActivityValid(activity) |
88 | } | 91 | } |
89 | 92 | ||
90 | function checkUndoActivity (activity: any) { | 93 | function checkUndoActivity (activity: any) { |
91 | return isUndoValid(activity) | 94 | return isUndoActivityValid(activity) |
95 | } | ||
96 | |||
97 | function checkLikeActivity (activity: any) { | ||
98 | return isLikeActivityValid(activity) | ||
92 | } | 99 | } |
diff --git a/server/helpers/custom-validators/activitypub/announce.ts b/server/helpers/custom-validators/activitypub/announce.ts index 4ba99d1ea..45f6b05a0 100644 --- a/server/helpers/custom-validators/activitypub/announce.ts +++ b/server/helpers/custom-validators/activitypub/announce.ts | |||
@@ -2,7 +2,7 @@ import { isBaseActivityValid } from './misc' | |||
2 | import { isVideoTorrentAddActivityValid } from './videos' | 2 | import { isVideoTorrentAddActivityValid } from './videos' |
3 | import { isVideoChannelCreateActivityValid } from './video-channels' | 3 | import { isVideoChannelCreateActivityValid } from './video-channels' |
4 | 4 | ||
5 | function isAnnounceValid (activity: any) { | 5 | function isAnnounceActivityValid (activity: any) { |
6 | return isBaseActivityValid(activity, 'Announce') && | 6 | return isBaseActivityValid(activity, 'Announce') && |
7 | ( | 7 | ( |
8 | isVideoChannelCreateActivityValid(activity.object) || | 8 | isVideoChannelCreateActivityValid(activity.object) || |
@@ -11,5 +11,5 @@ function isAnnounceValid (activity: any) { | |||
11 | } | 11 | } |
12 | 12 | ||
13 | export { | 13 | export { |
14 | isAnnounceValid | 14 | isAnnounceActivityValid |
15 | } | 15 | } |
diff --git a/server/helpers/custom-validators/activitypub/rate.ts b/server/helpers/custom-validators/activitypub/rate.ts new file mode 100644 index 000000000..e70bd94b8 --- /dev/null +++ b/server/helpers/custom-validators/activitypub/rate.ts | |||
@@ -0,0 +1,20 @@ | |||
1 | import { isActivityPubUrlValid, isBaseActivityValid } from './misc' | ||
2 | |||
3 | function isLikeActivityValid (activity: any) { | ||
4 | return isBaseActivityValid(activity, 'Like') && | ||
5 | isActivityPubUrlValid(activity.object) | ||
6 | } | ||
7 | |||
8 | function isDislikeActivityValid (activity: any) { | ||
9 | return isBaseActivityValid(activity, 'Create') && | ||
10 | activity.object.type === 'Dislike' && | ||
11 | isActivityPubUrlValid(activity.object.actor) && | ||
12 | isActivityPubUrlValid(activity.object.object) | ||
13 | } | ||
14 | |||
15 | // --------------------------------------------------------------------------- | ||
16 | |||
17 | export { | ||
18 | isLikeActivityValid, | ||
19 | isDislikeActivityValid | ||
20 | } | ||
diff --git a/server/helpers/custom-validators/activitypub/undo.ts b/server/helpers/custom-validators/activitypub/undo.ts index a9a2a3a41..58043f8a1 100644 --- a/server/helpers/custom-validators/activitypub/undo.ts +++ b/server/helpers/custom-validators/activitypub/undo.ts | |||
@@ -1,13 +1,16 @@ | |||
1 | import { isAccountFollowActivityValid } from './account' | 1 | import { isAccountFollowActivityValid } from './account' |
2 | import { isBaseActivityValid } from './misc' | 2 | import { isBaseActivityValid } from './misc' |
3 | import { isDislikeActivityValid, isLikeActivityValid } from './rate' | ||
3 | 4 | ||
4 | function isUndoValid (activity: any) { | 5 | function isUndoActivityValid (activity: any) { |
5 | return isBaseActivityValid(activity, 'Undo') && | 6 | return isBaseActivityValid(activity, 'Undo') && |
6 | ( | 7 | ( |
7 | isAccountFollowActivityValid(activity.object) | 8 | isAccountFollowActivityValid(activity.object) || |
9 | isLikeActivityValid(activity.object) || | ||
10 | isDislikeActivityValid(activity.object) | ||
8 | ) | 11 | ) |
9 | } | 12 | } |
10 | 13 | ||
11 | export { | 14 | export { |
12 | isUndoValid | 15 | isUndoActivityValid |
13 | } | 16 | } |