aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/custom-validators')
-rw-r--r--server/helpers/custom-validators/activitypub/activity.ts23
-rw-r--r--server/helpers/custom-validators/activitypub/announce.ts4
-rw-r--r--server/helpers/custom-validators/activitypub/rate.ts20
-rw-r--r--server/helpers/custom-validators/activitypub/undo.ts9
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 @@
1import * as validator from 'validator' 1import * as validator from 'validator'
2import { Activity, ActivityType } from '../../../../shared/models/activitypub/activity' 2import { Activity, ActivityType } from '../../../../shared/models/activitypub/activity'
3import { isAccountAcceptActivityValid, isAccountDeleteActivityValid, isAccountFollowActivityValid } from './account' 3import { isAccountAcceptActivityValid, isAccountDeleteActivityValid, isAccountFollowActivityValid } from './account'
4import { isAnnounceValid } from './announce' 4import { isAnnounceActivityValid } from './announce'
5import { isActivityPubUrlValid } from './misc' 5import { isActivityPubUrlValid } from './misc'
6import { isUndoValid } from './undo' 6import { isUndoActivityValid } from './undo'
7import { isVideoChannelCreateActivityValid, isVideoChannelDeleteActivityValid, isVideoChannelUpdateActivityValid } from './video-channels' 7import { isVideoChannelCreateActivityValid, isVideoChannelDeleteActivityValid, isVideoChannelUpdateActivityValid } from './video-channels'
8import { 8import {
9 isVideoFlagValid, 9 isVideoFlagValid,
@@ -12,6 +12,7 @@ import {
12 isVideoTorrentUpdateActivityValid 12 isVideoTorrentUpdateActivityValid
13} from './videos' 13} from './videos'
14import { isViewActivityValid } from './view' 14import { isViewActivityValid } from './view'
15import { isDislikeActivityValid, isLikeActivityValid } from './rate'
15 16
16function isRootActivityValid (activity: any) { 17function 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
40function isActivityValid (activity: any) { 42function isActivityValid (activity: any) {
@@ -55,9 +57,10 @@ export {
55// --------------------------------------------------------------------------- 57// ---------------------------------------------------------------------------
56 58
57function checkCreateActivity (activity: any) { 59function 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
63function checkAddActivity (activity: any) { 66function checkAddActivity (activity: any) {
@@ -84,9 +87,13 @@ function checkAcceptActivity (activity: any) {
84} 87}
85 88
86function checkAnnounceActivity (activity: any) { 89function checkAnnounceActivity (activity: any) {
87 return isAnnounceValid(activity) 90 return isAnnounceActivityValid(activity)
88} 91}
89 92
90function checkUndoActivity (activity: any) { 93function checkUndoActivity (activity: any) {
91 return isUndoValid(activity) 94 return isUndoActivityValid(activity)
95}
96
97function 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'
2import { isVideoTorrentAddActivityValid } from './videos' 2import { isVideoTorrentAddActivityValid } from './videos'
3import { isVideoChannelCreateActivityValid } from './video-channels' 3import { isVideoChannelCreateActivityValid } from './video-channels'
4 4
5function isAnnounceValid (activity: any) { 5function 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
13export { 13export {
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 @@
1import { isActivityPubUrlValid, isBaseActivityValid } from './misc'
2
3function isLikeActivityValid (activity: any) {
4 return isBaseActivityValid(activity, 'Like') &&
5 isActivityPubUrlValid(activity.object)
6}
7
8function 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
17export {
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 @@
1import { isAccountFollowActivityValid } from './account' 1import { isAccountFollowActivityValid } from './account'
2import { isBaseActivityValid } from './misc' 2import { isBaseActivityValid } from './misc'
3import { isDislikeActivityValid, isLikeActivityValid } from './rate'
3 4
4function isUndoValid (activity: any) { 5function 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
11export { 14export {
12 isUndoValid 15 isUndoActivityValid
13} 16}