aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators/remote/videos.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/custom-validators/remote/videos.ts')
-rw-r--r--server/helpers/custom-validators/remote/videos.ts104
1 files changed, 67 insertions, 37 deletions
diff --git a/server/helpers/custom-validators/remote/videos.ts b/server/helpers/custom-validators/remote/videos.ts
index e261e05a8..057996f1c 100644
--- a/server/helpers/custom-validators/remote/videos.ts
+++ b/server/helpers/custom-validators/remote/videos.ts
@@ -6,18 +6,15 @@ import {
6 REQUEST_ENDPOINT_ACTIONS, 6 REQUEST_ENDPOINT_ACTIONS,
7 REQUEST_VIDEO_EVENT_TYPES 7 REQUEST_VIDEO_EVENT_TYPES
8} from '../../../initializers' 8} from '../../../initializers'
9import { isArray } from '../misc' 9import { isArray, isDateValid, isUUIDValid } from '../misc'
10import { 10import {
11 isVideoAuthorValid,
12 isVideoThumbnailDataValid, 11 isVideoThumbnailDataValid,
13 isVideoUUIDValid,
14 isVideoAbuseReasonValid, 12 isVideoAbuseReasonValid,
15 isVideoAbuseReporterUsernameValid, 13 isVideoAbuseReporterUsernameValid,
16 isVideoViewsValid, 14 isVideoViewsValid,
17 isVideoLikesValid, 15 isVideoLikesValid,
18 isVideoDislikesValid, 16 isVideoDislikesValid,
19 isVideoEventCountValid, 17 isVideoEventCountValid,
20 isVideoDateValid,
21 isVideoCategoryValid, 18 isVideoCategoryValid,
22 isVideoLicenceValid, 19 isVideoLicenceValid,
23 isVideoLanguageValid, 20 isVideoLanguageValid,
@@ -30,9 +27,22 @@ import {
30 isVideoFileExtnameValid, 27 isVideoFileExtnameValid,
31 isVideoFileResolutionValid 28 isVideoFileResolutionValid
32} from '../videos' 29} from '../videos'
30import { isVideoChannelDescriptionValid, isVideoChannelNameValid } from '../video-channels'
31import { isVideoAuthorNameValid } from '../video-authors'
33 32
34const ENDPOINT_ACTIONS = REQUEST_ENDPOINT_ACTIONS[REQUEST_ENDPOINTS.VIDEOS] 33const ENDPOINT_ACTIONS = REQUEST_ENDPOINT_ACTIONS[REQUEST_ENDPOINTS.VIDEOS]
35 34
35const checkers: { [ id: string ]: (obj: any) => boolean } = {}
36checkers[ENDPOINT_ACTIONS.ADD_VIDEO] = checkAddVideo
37checkers[ENDPOINT_ACTIONS.UPDATE_VIDEO] = checkUpdateVideo
38checkers[ENDPOINT_ACTIONS.REMOVE_VIDEO] = checkRemoveVideo
39checkers[ENDPOINT_ACTIONS.REPORT_ABUSE] = checkReportVideo
40checkers[ENDPOINT_ACTIONS.ADD_CHANNEL] = checkAddVideoChannel
41checkers[ENDPOINT_ACTIONS.UPDATE_CHANNEL] = checkUpdateVideoChannel
42checkers[ENDPOINT_ACTIONS.REMOVE_CHANNEL] = checkRemoveVideoChannel
43checkers[ENDPOINT_ACTIONS.ADD_AUTHOR] = checkAddAuthor
44checkers[ENDPOINT_ACTIONS.REMOVE_AUTHOR] = checkRemoveAuthor
45
36function isEachRemoteRequestVideosValid (requests: any[]) { 46function isEachRemoteRequestVideosValid (requests: any[]) {
37 return isArray(requests) && 47 return isArray(requests) &&
38 requests.every(request => { 48 requests.every(request => {
@@ -40,26 +50,11 @@ function isEachRemoteRequestVideosValid (requests: any[]) {
40 50
41 if (!video) return false 51 if (!video) return false
42 52
43 return ( 53 const checker = checkers[request.type]
44 isRequestTypeAddValid(request.type) && 54 // We don't know the request type
45 isCommonVideoAttributesValid(video) && 55 if (checker === undefined) return false
46 isVideoAuthorValid(video.author) && 56
47 isVideoThumbnailDataValid(video.thumbnailData) 57 return checker(video)
48 ) ||
49 (
50 isRequestTypeUpdateValid(request.type) &&
51 isCommonVideoAttributesValid(video)
52 ) ||
53 (
54 isRequestTypeRemoveValid(request.type) &&
55 isVideoUUIDValid(video.uuid)
56 ) ||
57 (
58 isRequestTypeReportAbuseValid(request.type) &&
59 isVideoUUIDValid(request.data.videoUUID) &&
60 isVideoAbuseReasonValid(request.data.reportReason) &&
61 isVideoAbuseReporterUsernameValid(request.data.reporterUsername)
62 )
63 }) 58 })
64} 59}
65 60
@@ -71,7 +66,7 @@ function isEachRemoteRequestVideosQaduValid (requests: any[]) {
71 if (!video) return false 66 if (!video) return false
72 67
73 return ( 68 return (
74 isVideoUUIDValid(video.uuid) && 69 isUUIDValid(video.uuid) &&
75 (has(video, 'views') === false || isVideoViewsValid(video.views)) && 70 (has(video, 'views') === false || isVideoViewsValid(video.views)) &&
76 (has(video, 'likes') === false || isVideoLikesValid(video.likes)) && 71 (has(video, 'likes') === false || isVideoLikesValid(video.likes)) &&
77 (has(video, 'dislikes') === false || isVideoDislikesValid(video.dislikes)) 72 (has(video, 'dislikes') === false || isVideoDislikesValid(video.dislikes))
@@ -87,7 +82,7 @@ function isEachRemoteRequestVideosEventsValid (requests: any[]) {
87 if (!eventData) return false 82 if (!eventData) return false
88 83
89 return ( 84 return (
90 isVideoUUIDValid(eventData.uuid) && 85 isUUIDValid(eventData.uuid) &&
91 values(REQUEST_VIDEO_EVENT_TYPES).indexOf(eventData.eventType) !== -1 && 86 values(REQUEST_VIDEO_EVENT_TYPES).indexOf(eventData.eventType) !== -1 &&
92 isVideoEventCountValid(eventData.count) 87 isVideoEventCountValid(eventData.count)
93 ) 88 )
@@ -105,8 +100,8 @@ export {
105// --------------------------------------------------------------------------- 100// ---------------------------------------------------------------------------
106 101
107function isCommonVideoAttributesValid (video: any) { 102function isCommonVideoAttributesValid (video: any) {
108 return isVideoDateValid(video.createdAt) && 103 return isDateValid(video.createdAt) &&
109 isVideoDateValid(video.updatedAt) && 104 isDateValid(video.updatedAt) &&
110 isVideoCategoryValid(video.category) && 105 isVideoCategoryValid(video.category) &&
111 isVideoLicenceValid(video.licence) && 106 isVideoLicenceValid(video.licence) &&
112 isVideoLanguageValid(video.language) && 107 isVideoLanguageValid(video.language) &&
@@ -115,7 +110,7 @@ function isCommonVideoAttributesValid (video: any) {
115 isVideoDurationValid(video.duration) && 110 isVideoDurationValid(video.duration) &&
116 isVideoNameValid(video.name) && 111 isVideoNameValid(video.name) &&
117 isVideoTagsValid(video.tags) && 112 isVideoTagsValid(video.tags) &&
118 isVideoUUIDValid(video.uuid) && 113 isUUIDValid(video.uuid) &&
119 isVideoViewsValid(video.views) && 114 isVideoViewsValid(video.views) &&
120 isVideoLikesValid(video.likes) && 115 isVideoLikesValid(video.likes) &&
121 isVideoDislikesValid(video.dislikes) && 116 isVideoDislikesValid(video.dislikes) &&
@@ -131,18 +126,53 @@ function isCommonVideoAttributesValid (video: any) {
131 }) 126 })
132} 127}
133 128
134function isRequestTypeAddValid (value: string) { 129function checkAddVideo (video: any) {
135 return value === ENDPOINT_ACTIONS.ADD 130 return isCommonVideoAttributesValid(video) &&
131 isUUIDValid(video.channelUUID) &&
132 isVideoThumbnailDataValid(video.thumbnailData)
133}
134
135function checkUpdateVideo (video: any) {
136 return isCommonVideoAttributesValid(video)
137}
138
139function checkRemoveVideo (video: any) {
140 return isUUIDValid(video.uuid)
141}
142
143function checkReportVideo (abuse: any) {
144 return isUUIDValid(abuse.videoUUID) &&
145 isVideoAbuseReasonValid(abuse.reportReason) &&
146 isVideoAbuseReporterUsernameValid(abuse.reporterUsername)
147}
148
149function checkAddVideoChannel (videoChannel: any) {
150 return isUUIDValid(videoChannel.uuid) &&
151 isVideoChannelNameValid(videoChannel.name) &&
152 isVideoChannelDescriptionValid(videoChannel.description) &&
153 isDateValid(videoChannel.createdAt) &&
154 isDateValid(videoChannel.updatedAt) &&
155 isUUIDValid(videoChannel.ownerUUID)
156}
157
158function checkUpdateVideoChannel (videoChannel: any) {
159 return isUUIDValid(videoChannel.uuid) &&
160 isVideoChannelNameValid(videoChannel.name) &&
161 isVideoChannelDescriptionValid(videoChannel.description) &&
162 isDateValid(videoChannel.createdAt) &&
163 isDateValid(videoChannel.updatedAt) &&
164 isUUIDValid(videoChannel.ownerUUID)
136} 165}
137 166
138function isRequestTypeUpdateValid (value: string) { 167function checkRemoveVideoChannel (videoChannel: any) {
139 return value === ENDPOINT_ACTIONS.UPDATE 168 return isUUIDValid(videoChannel.uuid)
140} 169}
141 170
142function isRequestTypeRemoveValid (value: string) { 171function checkAddAuthor (author: any) {
143 return value === ENDPOINT_ACTIONS.REMOVE 172 return isUUIDValid(author.uuid) &&
173 isVideoAuthorNameValid(author.name)
144} 174}
145 175
146function isRequestTypeReportAbuseValid (value: string) { 176function checkRemoveAuthor (author: any) {
147 return value === ENDPOINT_ACTIONS.REPORT_ABUSE 177 return isUUIDValid(author.uuid)
148} 178}