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.ts26
-rw-r--r--server/helpers/custom-validators/activitypub/rate.ts13
-rw-r--r--server/helpers/custom-validators/activitypub/share.ts11
3 files changed, 32 insertions, 18 deletions
diff --git a/server/helpers/custom-validators/activitypub/activity.ts b/server/helpers/custom-validators/activitypub/activity.ts
index 8b8c0685f..da79b2782 100644
--- a/server/helpers/custom-validators/activitypub/activity.ts
+++ b/server/helpers/custom-validators/activitypub/activity.ts
@@ -1,15 +1,16 @@
1import validator from 'validator' 1import validator from 'validator'
2import { Activity, ActivityType } from '../../../../shared/models/activitypub' 2import { Activity, ActivityType } from '../../../../shared/models/activitypub'
3import { exists } from '../misc'
3import { sanitizeAndCheckActorObject } from './actor' 4import { sanitizeAndCheckActorObject } from './actor'
5import { isCacheFileObjectValid } from './cache-file'
6import { isFlagActivityValid } from './flag'
4import { isActivityPubUrlValid, isBaseActivityValid, isObjectValid } from './misc' 7import { isActivityPubUrlValid, isBaseActivityValid, isObjectValid } from './misc'
5import { isDislikeActivityValid } from './rate' 8import { isPlaylistObjectValid } from './playlist'
9import { isDislikeActivityValid, isLikeActivityValid } from './rate'
10import { isShareActivityValid } from './share'
6import { sanitizeAndCheckVideoCommentObject } from './video-comments' 11import { sanitizeAndCheckVideoCommentObject } from './video-comments'
7import { sanitizeAndCheckVideoTorrentObject } from './videos' 12import { sanitizeAndCheckVideoTorrentObject } from './videos'
8import { isViewActivityValid } from './view' 13import { isViewActivityValid } from './view'
9import { exists } from '../misc'
10import { isCacheFileObjectValid } from './cache-file'
11import { isFlagActivityValid } from './flag'
12import { isPlaylistObjectValid } from './playlist'
13 14
14function isRootActivityValid (activity: any) { 15function isRootActivityValid (activity: any) {
15 return isCollection(activity) || isActivity(activity) 16 return isCollection(activity) || isActivity(activity)
@@ -70,8 +71,11 @@ function checkFlagActivity (activity: any) {
70} 71}
71 72
72function checkDislikeActivity (activity: any) { 73function checkDislikeActivity (activity: any) {
73 return isBaseActivityValid(activity, 'Dislike') && 74 return isDislikeActivityValid(activity)
74 isDislikeActivityValid(activity) 75}
76
77function checkLikeActivity (activity: any) {
78 return isLikeActivityValid(activity)
75} 79}
76 80
77function checkCreateActivity (activity: any) { 81function checkCreateActivity (activity: any) {
@@ -118,8 +122,7 @@ function checkRejectActivity (activity: any) {
118} 122}
119 123
120function checkAnnounceActivity (activity: any) { 124function checkAnnounceActivity (activity: any) {
121 return isBaseActivityValid(activity, 'Announce') && 125 return isShareActivityValid(activity)
122 isObjectValid(activity.object)
123} 126}
124 127
125function checkUndoActivity (activity: any) { 128function checkUndoActivity (activity: any) {
@@ -132,8 +135,3 @@ function checkUndoActivity (activity: any) {
132 checkCreateActivity(activity.object) 135 checkCreateActivity(activity.object)
133 ) 136 )
134} 137}
135
136function checkLikeActivity (activity: any) {
137 return isBaseActivityValid(activity, 'Like') &&
138 isObjectValid(activity.object)
139}
diff --git a/server/helpers/custom-validators/activitypub/rate.ts b/server/helpers/custom-validators/activitypub/rate.ts
index ba68e8074..aafdda443 100644
--- a/server/helpers/custom-validators/activitypub/rate.ts
+++ b/server/helpers/custom-validators/activitypub/rate.ts
@@ -1,13 +1,18 @@
1import { isActivityPubUrlValid, isObjectValid } from './misc' 1import { isBaseActivityValid, isObjectValid } from './misc'
2
3function isLikeActivityValid (activity: any) {
4 return isBaseActivityValid(activity, 'Like') &&
5 isObjectValid(activity.object)
6}
2 7
3function isDislikeActivityValid (activity: any) { 8function isDislikeActivityValid (activity: any) {
4 return activity.type === 'Dislike' && 9 return isBaseActivityValid(activity, 'Dislike') &&
5 isActivityPubUrlValid(activity.actor) &&
6 isObjectValid(activity.object) 10 isObjectValid(activity.object)
7} 11}
8 12
9// --------------------------------------------------------------------------- 13// ---------------------------------------------------------------------------
10 14
11export { 15export {
12 isDislikeActivityValid 16 isDislikeActivityValid,
17 isLikeActivityValid
13} 18}
diff --git a/server/helpers/custom-validators/activitypub/share.ts b/server/helpers/custom-validators/activitypub/share.ts
new file mode 100644
index 000000000..fb5e4c05e
--- /dev/null
+++ b/server/helpers/custom-validators/activitypub/share.ts
@@ -0,0 +1,11 @@
1import { isBaseActivityValid, isObjectValid } from './misc'
2
3function isShareActivityValid (activity: any) {
4 return isBaseActivityValid(activity, 'Announce') &&
5 isObjectValid(activity.object)
6}
7// ---------------------------------------------------------------------------
8
9export {
10 isShareActivityValid
11}