diff options
Diffstat (limited to 'server/helpers/custom-validators/activitypub/videos.ts')
-rw-r--r-- | server/helpers/custom-validators/activitypub/videos.ts | 54 |
1 files changed, 8 insertions, 46 deletions
diff --git a/server/helpers/custom-validators/activitypub/videos.ts b/server/helpers/custom-validators/activitypub/videos.ts index 728511e3d..faeedd3df 100644 --- a/server/helpers/custom-validators/activitypub/videos.ts +++ b/server/helpers/custom-validators/activitypub/videos.ts | |||
@@ -1,7 +1,6 @@ | |||
1 | import * as validator from 'validator' | 1 | import * as validator from 'validator' |
2 | import { ACTIVITY_PUB } from '../../../initializers' | 2 | import { ACTIVITY_PUB } from '../../../initializers' |
3 | import { exists, isDateValid, isUUIDValid } from '../misc' | 3 | import { exists, isDateValid, isUUIDValid } from '../misc' |
4 | import { isVideoChannelDescriptionValid, isVideoChannelNameValid } from '../video-channels' | ||
5 | import { | 4 | import { |
6 | isVideoAbuseReasonValid, | 5 | isVideoAbuseReasonValid, |
7 | isVideoDurationValid, | 6 | isVideoDurationValid, |
@@ -28,6 +27,13 @@ function isVideoTorrentDeleteActivityValid (activity: any) { | |||
28 | return isBaseActivityValid(activity, 'Delete') | 27 | return isBaseActivityValid(activity, 'Delete') |
29 | } | 28 | } |
30 | 29 | ||
30 | function isVideoFlagValid (activity: any) { | ||
31 | return isBaseActivityValid(activity, 'Create') && | ||
32 | activity.object.type === 'Flag' && | ||
33 | isVideoAbuseReasonValid(activity.object.content) && | ||
34 | isActivityPubUrlValid(activity.object.object) | ||
35 | } | ||
36 | |||
31 | function isActivityPubVideoDurationValid (value: string) { | 37 | function isActivityPubVideoDurationValid (value: string) { |
32 | // https://www.w3.org/TR/activitystreams-vocabulary/#dfn-duration | 38 | // https://www.w3.org/TR/activitystreams-vocabulary/#dfn-duration |
33 | return exists(value) && | 39 | return exists(value) && |
@@ -57,57 +63,13 @@ function isVideoTorrentObjectValid (video: any) { | |||
57 | video.url.length !== 0 | 63 | video.url.length !== 0 |
58 | } | 64 | } |
59 | 65 | ||
60 | function isVideoFlagValid (activity: any) { | ||
61 | return isBaseActivityValid(activity, 'Create') && | ||
62 | activity.object.type === 'Flag' && | ||
63 | isVideoAbuseReasonValid(activity.object.content) && | ||
64 | isActivityPubUrlValid(activity.object.object) | ||
65 | } | ||
66 | |||
67 | function isAnnounceValid (activity: any) { | ||
68 | return isBaseActivityValid(activity, 'Announce') && | ||
69 | ( | ||
70 | isVideoChannelCreateActivityValid(activity.object) || | ||
71 | isVideoTorrentAddActivityValid(activity.object) | ||
72 | ) | ||
73 | } | ||
74 | |||
75 | function isVideoChannelCreateActivityValid (activity: any) { | ||
76 | return isBaseActivityValid(activity, 'Create') && | ||
77 | isVideoChannelObjectValid(activity.object) | ||
78 | } | ||
79 | |||
80 | function isVideoChannelUpdateActivityValid (activity: any) { | ||
81 | return isBaseActivityValid(activity, 'Update') && | ||
82 | isVideoChannelObjectValid(activity.object) | ||
83 | } | ||
84 | |||
85 | function isVideoChannelDeleteActivityValid (activity: any) { | ||
86 | return isBaseActivityValid(activity, 'Delete') | ||
87 | } | ||
88 | |||
89 | function isVideoChannelObjectValid (videoChannel: any) { | ||
90 | return videoChannel.type === 'VideoChannel' && | ||
91 | isActivityPubUrlValid(videoChannel.id) && | ||
92 | isVideoChannelNameValid(videoChannel.name) && | ||
93 | isVideoChannelDescriptionValid(videoChannel.content) && | ||
94 | isDateValid(videoChannel.published) && | ||
95 | isDateValid(videoChannel.updated) && | ||
96 | isUUIDValid(videoChannel.uuid) | ||
97 | } | ||
98 | |||
99 | // --------------------------------------------------------------------------- | 66 | // --------------------------------------------------------------------------- |
100 | 67 | ||
101 | export { | 68 | export { |
102 | isVideoTorrentAddActivityValid, | 69 | isVideoTorrentAddActivityValid, |
103 | isVideoChannelCreateActivityValid, | ||
104 | isVideoTorrentUpdateActivityValid, | 70 | isVideoTorrentUpdateActivityValid, |
105 | isVideoChannelUpdateActivityValid, | ||
106 | isVideoChannelDeleteActivityValid, | ||
107 | isVideoTorrentDeleteActivityValid, | 71 | isVideoTorrentDeleteActivityValid, |
108 | isVideoFlagValid, | 72 | isVideoFlagValid |
109 | isAnnounceValid, | ||
110 | isVideoChannelObjectValid | ||
111 | } | 73 | } |
112 | 74 | ||
113 | // --------------------------------------------------------------------------- | 75 | // --------------------------------------------------------------------------- |