diff options
author | Chocobozzz <me@florianbigard.com> | 2021-02-26 16:26:27 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-03-03 10:08:08 +0100 |
commit | 74d249bc1346c7cfaac7ee49bebbebcf2a01f82a (patch) | |
tree | d47bd163ae57ed8f15b445296634cc04f4f67b6f /server/helpers/custom-validators | |
parent | 095e2258043fcff8a79ab082d11edfbd8f13a8e2 (diff) | |
download | PeerTube-74d249bc1346c7cfaac7ee49bebbebcf2a01f82a.tar.gz PeerTube-74d249bc1346c7cfaac7ee49bebbebcf2a01f82a.tar.zst PeerTube-74d249bc1346c7cfaac7ee49bebbebcf2a01f82a.zip |
Add ability to cleanup remote AP interactions
Diffstat (limited to 'server/helpers/custom-validators')
-rw-r--r-- | server/helpers/custom-validators/activitypub/activity.ts | 26 | ||||
-rw-r--r-- | server/helpers/custom-validators/activitypub/rate.ts | 13 | ||||
-rw-r--r-- | server/helpers/custom-validators/activitypub/share.ts | 11 |
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 @@ | |||
1 | import validator from 'validator' | 1 | import validator from 'validator' |
2 | import { Activity, ActivityType } from '../../../../shared/models/activitypub' | 2 | import { Activity, ActivityType } from '../../../../shared/models/activitypub' |
3 | import { exists } from '../misc' | ||
3 | import { sanitizeAndCheckActorObject } from './actor' | 4 | import { sanitizeAndCheckActorObject } from './actor' |
5 | import { isCacheFileObjectValid } from './cache-file' | ||
6 | import { isFlagActivityValid } from './flag' | ||
4 | import { isActivityPubUrlValid, isBaseActivityValid, isObjectValid } from './misc' | 7 | import { isActivityPubUrlValid, isBaseActivityValid, isObjectValid } from './misc' |
5 | import { isDislikeActivityValid } from './rate' | 8 | import { isPlaylistObjectValid } from './playlist' |
9 | import { isDislikeActivityValid, isLikeActivityValid } from './rate' | ||
10 | import { isShareActivityValid } from './share' | ||
6 | import { sanitizeAndCheckVideoCommentObject } from './video-comments' | 11 | import { sanitizeAndCheckVideoCommentObject } from './video-comments' |
7 | import { sanitizeAndCheckVideoTorrentObject } from './videos' | 12 | import { sanitizeAndCheckVideoTorrentObject } from './videos' |
8 | import { isViewActivityValid } from './view' | 13 | import { isViewActivityValid } from './view' |
9 | import { exists } from '../misc' | ||
10 | import { isCacheFileObjectValid } from './cache-file' | ||
11 | import { isFlagActivityValid } from './flag' | ||
12 | import { isPlaylistObjectValid } from './playlist' | ||
13 | 14 | ||
14 | function isRootActivityValid (activity: any) { | 15 | function 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 | ||
72 | function checkDislikeActivity (activity: any) { | 73 | function checkDislikeActivity (activity: any) { |
73 | return isBaseActivityValid(activity, 'Dislike') && | 74 | return isDislikeActivityValid(activity) |
74 | isDislikeActivityValid(activity) | 75 | } |
76 | |||
77 | function checkLikeActivity (activity: any) { | ||
78 | return isLikeActivityValid(activity) | ||
75 | } | 79 | } |
76 | 80 | ||
77 | function checkCreateActivity (activity: any) { | 81 | function checkCreateActivity (activity: any) { |
@@ -118,8 +122,7 @@ function checkRejectActivity (activity: any) { | |||
118 | } | 122 | } |
119 | 123 | ||
120 | function checkAnnounceActivity (activity: any) { | 124 | function checkAnnounceActivity (activity: any) { |
121 | return isBaseActivityValid(activity, 'Announce') && | 125 | return isShareActivityValid(activity) |
122 | isObjectValid(activity.object) | ||
123 | } | 126 | } |
124 | 127 | ||
125 | function checkUndoActivity (activity: any) { | 128 | function checkUndoActivity (activity: any) { |
@@ -132,8 +135,3 @@ function checkUndoActivity (activity: any) { | |||
132 | checkCreateActivity(activity.object) | 135 | checkCreateActivity(activity.object) |
133 | ) | 136 | ) |
134 | } | 137 | } |
135 | |||
136 | function 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 @@ | |||
1 | import { isActivityPubUrlValid, isObjectValid } from './misc' | 1 | import { isBaseActivityValid, isObjectValid } from './misc' |
2 | |||
3 | function isLikeActivityValid (activity: any) { | ||
4 | return isBaseActivityValid(activity, 'Like') && | ||
5 | isObjectValid(activity.object) | ||
6 | } | ||
2 | 7 | ||
3 | function isDislikeActivityValid (activity: any) { | 8 | function 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 | ||
11 | export { | 15 | export { |
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 @@ | |||
1 | import { isBaseActivityValid, isObjectValid } from './misc' | ||
2 | |||
3 | function isShareActivityValid (activity: any) { | ||
4 | return isBaseActivityValid(activity, 'Announce') && | ||
5 | isObjectValid(activity.object) | ||
6 | } | ||
7 | // --------------------------------------------------------------------------- | ||
8 | |||
9 | export { | ||
10 | isShareActivityValid | ||
11 | } | ||