diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-10-24 19:41:09 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-10-26 09:11:38 +0200 |
commit | 72c7248b6fdcdb2175e726ff51b42e7555f2bd84 (patch) | |
tree | 1bfdee99dbe2392cc997edba8e314e2a8a401c72 /server/helpers/custom-validators/remote | |
parent | 8113a93a0d9f31aa9e23702bbc31b8a76275ae22 (diff) | |
download | PeerTube-72c7248b6fdcdb2175e726ff51b42e7555f2bd84.tar.gz PeerTube-72c7248b6fdcdb2175e726ff51b42e7555f2bd84.tar.zst PeerTube-72c7248b6fdcdb2175e726ff51b42e7555f2bd84.zip |
Add video channels
Diffstat (limited to 'server/helpers/custom-validators/remote')
-rw-r--r-- | server/helpers/custom-validators/remote/videos.ts | 104 |
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' |
9 | import { isArray } from '../misc' | 9 | import { isArray, isDateValid, isUUIDValid } from '../misc' |
10 | import { | 10 | import { |
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' |
30 | import { isVideoChannelDescriptionValid, isVideoChannelNameValid } from '../video-channels' | ||
31 | import { isVideoAuthorNameValid } from '../video-authors' | ||
33 | 32 | ||
34 | const ENDPOINT_ACTIONS = REQUEST_ENDPOINT_ACTIONS[REQUEST_ENDPOINTS.VIDEOS] | 33 | const ENDPOINT_ACTIONS = REQUEST_ENDPOINT_ACTIONS[REQUEST_ENDPOINTS.VIDEOS] |
35 | 34 | ||
35 | const checkers: { [ id: string ]: (obj: any) => boolean } = {} | ||
36 | checkers[ENDPOINT_ACTIONS.ADD_VIDEO] = checkAddVideo | ||
37 | checkers[ENDPOINT_ACTIONS.UPDATE_VIDEO] = checkUpdateVideo | ||
38 | checkers[ENDPOINT_ACTIONS.REMOVE_VIDEO] = checkRemoveVideo | ||
39 | checkers[ENDPOINT_ACTIONS.REPORT_ABUSE] = checkReportVideo | ||
40 | checkers[ENDPOINT_ACTIONS.ADD_CHANNEL] = checkAddVideoChannel | ||
41 | checkers[ENDPOINT_ACTIONS.UPDATE_CHANNEL] = checkUpdateVideoChannel | ||
42 | checkers[ENDPOINT_ACTIONS.REMOVE_CHANNEL] = checkRemoveVideoChannel | ||
43 | checkers[ENDPOINT_ACTIONS.ADD_AUTHOR] = checkAddAuthor | ||
44 | checkers[ENDPOINT_ACTIONS.REMOVE_AUTHOR] = checkRemoveAuthor | ||
45 | |||
36 | function isEachRemoteRequestVideosValid (requests: any[]) { | 46 | function 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 | ||
107 | function isCommonVideoAttributesValid (video: any) { | 102 | function 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 | ||
134 | function isRequestTypeAddValid (value: string) { | 129 | function checkAddVideo (video: any) { |
135 | return value === ENDPOINT_ACTIONS.ADD | 130 | return isCommonVideoAttributesValid(video) && |
131 | isUUIDValid(video.channelUUID) && | ||
132 | isVideoThumbnailDataValid(video.thumbnailData) | ||
133 | } | ||
134 | |||
135 | function checkUpdateVideo (video: any) { | ||
136 | return isCommonVideoAttributesValid(video) | ||
137 | } | ||
138 | |||
139 | function checkRemoveVideo (video: any) { | ||
140 | return isUUIDValid(video.uuid) | ||
141 | } | ||
142 | |||
143 | function checkReportVideo (abuse: any) { | ||
144 | return isUUIDValid(abuse.videoUUID) && | ||
145 | isVideoAbuseReasonValid(abuse.reportReason) && | ||
146 | isVideoAbuseReporterUsernameValid(abuse.reporterUsername) | ||
147 | } | ||
148 | |||
149 | function 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 | |||
158 | function 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 | ||
138 | function isRequestTypeUpdateValid (value: string) { | 167 | function checkRemoveVideoChannel (videoChannel: any) { |
139 | return value === ENDPOINT_ACTIONS.UPDATE | 168 | return isUUIDValid(videoChannel.uuid) |
140 | } | 169 | } |
141 | 170 | ||
142 | function isRequestTypeRemoveValid (value: string) { | 171 | function checkAddAuthor (author: any) { |
143 | return value === ENDPOINT_ACTIONS.REMOVE | 172 | return isUUIDValid(author.uuid) && |
173 | isVideoAuthorNameValid(author.name) | ||
144 | } | 174 | } |
145 | 175 | ||
146 | function isRequestTypeReportAbuseValid (value: string) { | 176 | function checkRemoveAuthor (author: any) { |
147 | return value === ENDPOINT_ACTIONS.REPORT_ABUSE | 177 | return isUUIDValid(author.uuid) |
148 | } | 178 | } |