]>
Commit | Line | Data |
---|---|---|
fdbda9e3 | 1 | import 'express-validator' |
65fcc311 C |
2 | import { has, values } from 'lodash' |
3 | ||
4 | import { | |
5 | REQUEST_ENDPOINTS, | |
6 | REQUEST_ENDPOINT_ACTIONS, | |
7 | REQUEST_VIDEO_EVENT_TYPES | |
8 | } from '../../../initializers' | |
9 | import { isArray } from '../misc' | |
10 | import { | |
11 | isVideoAuthorValid, | |
12 | isVideoThumbnailDataValid, | |
0a6658fd | 13 | isVideoUUIDValid, |
65fcc311 C |
14 | isVideoAbuseReasonValid, |
15 | isVideoAbuseReporterUsernameValid, | |
16 | isVideoViewsValid, | |
17 | isVideoLikesValid, | |
18 | isVideoDislikesValid, | |
19 | isVideoEventCountValid, | |
20 | isVideoDateValid, | |
21 | isVideoCategoryValid, | |
22 | isVideoLicenceValid, | |
23 | isVideoLanguageValid, | |
24 | isVideoNSFWValid, | |
25 | isVideoDescriptionValid, | |
26 | isVideoDurationValid, | |
93e1258c | 27 | isVideoFileInfoHashValid, |
65fcc311 C |
28 | isVideoNameValid, |
29 | isVideoTagsValid, | |
93e1258c C |
30 | isVideoFileExtnameValid, |
31 | isVideoFileResolutionValid | |
65fcc311 C |
32 | } from '../videos' |
33 | ||
34 | const ENDPOINT_ACTIONS = REQUEST_ENDPOINT_ACTIONS[REQUEST_ENDPOINTS.VIDEOS] | |
35 | ||
69818c93 | 36 | function isEachRemoteRequestVideosValid (requests: any[]) { |
65fcc311 | 37 | return isArray(requests) && |
075f16ca | 38 | requests.every(request => { |
65fcc311 C |
39 | const video = request.data |
40 | ||
41 | if (!video) return false | |
42 | ||
43 | return ( | |
44 | isRequestTypeAddValid(request.type) && | |
45 | isCommonVideoAttributesValid(video) && | |
46 | isVideoAuthorValid(video.author) && | |
47 | isVideoThumbnailDataValid(video.thumbnailData) | |
48 | ) || | |
49 | ( | |
50 | isRequestTypeUpdateValid(request.type) && | |
51 | isCommonVideoAttributesValid(video) | |
52 | ) || | |
53 | ( | |
54 | isRequestTypeRemoveValid(request.type) && | |
0a6658fd | 55 | isVideoUUIDValid(video.uuid) |
65fcc311 C |
56 | ) || |
57 | ( | |
58 | isRequestTypeReportAbuseValid(request.type) && | |
0a6658fd | 59 | isVideoUUIDValid(request.data.videoUUID) && |
65fcc311 C |
60 | isVideoAbuseReasonValid(request.data.reportReason) && |
61 | isVideoAbuseReporterUsernameValid(request.data.reporterUsername) | |
62 | ) | |
63 | }) | |
64 | } | |
65 | ||
69818c93 | 66 | function isEachRemoteRequestVideosQaduValid (requests: any[]) { |
65fcc311 | 67 | return isArray(requests) && |
075f16ca | 68 | requests.every(request => { |
65fcc311 C |
69 | const video = request.data |
70 | ||
71 | if (!video) return false | |
72 | ||
73 | return ( | |
0a6658fd | 74 | isVideoUUIDValid(video.uuid) && |
69818c93 C |
75 | (has(video, 'views') === false || isVideoViewsValid(video.views)) && |
76 | (has(video, 'likes') === false || isVideoLikesValid(video.likes)) && | |
77 | (has(video, 'dislikes') === false || isVideoDislikesValid(video.dislikes)) | |
65fcc311 C |
78 | ) |
79 | }) | |
80 | } | |
81 | ||
69818c93 | 82 | function isEachRemoteRequestVideosEventsValid (requests: any[]) { |
65fcc311 | 83 | return isArray(requests) && |
075f16ca | 84 | requests.every(request => { |
65fcc311 C |
85 | const eventData = request.data |
86 | ||
87 | if (!eventData) return false | |
88 | ||
89 | return ( | |
0a6658fd | 90 | isVideoUUIDValid(eventData.uuid) && |
65fcc311 C |
91 | values(REQUEST_VIDEO_EVENT_TYPES).indexOf(eventData.eventType) !== -1 && |
92 | isVideoEventCountValid(eventData.count) | |
93 | ) | |
94 | }) | |
95 | } | |
96 | ||
97 | // --------------------------------------------------------------------------- | |
98 | ||
99 | export { | |
100 | isEachRemoteRequestVideosValid, | |
101 | isEachRemoteRequestVideosQaduValid, | |
102 | isEachRemoteRequestVideosEventsValid | |
103 | } | |
104 | ||
105 | // --------------------------------------------------------------------------- | |
106 | ||
69818c93 | 107 | function isCommonVideoAttributesValid (video: any) { |
65fcc311 C |
108 | return isVideoDateValid(video.createdAt) && |
109 | isVideoDateValid(video.updatedAt) && | |
110 | isVideoCategoryValid(video.category) && | |
111 | isVideoLicenceValid(video.licence) && | |
112 | isVideoLanguageValid(video.language) && | |
113 | isVideoNSFWValid(video.nsfw) && | |
114 | isVideoDescriptionValid(video.description) && | |
115 | isVideoDurationValid(video.duration) && | |
65fcc311 C |
116 | isVideoNameValid(video.name) && |
117 | isVideoTagsValid(video.tags) && | |
0a6658fd | 118 | isVideoUUIDValid(video.uuid) && |
65fcc311 C |
119 | isVideoViewsValid(video.views) && |
120 | isVideoLikesValid(video.likes) && | |
93e1258c C |
121 | isVideoDislikesValid(video.dislikes) && |
122 | isArray(video.files) && | |
123 | video.files.every(videoFile => { | |
124 | if (!videoFile) return false | |
125 | ||
126 | return ( | |
127 | isVideoFileInfoHashValid(videoFile.infoHash) && | |
128 | isVideoFileExtnameValid(videoFile.extname) && | |
129 | isVideoFileResolutionValid(videoFile.resolution) | |
130 | ) | |
131 | }) | |
65fcc311 C |
132 | } |
133 | ||
69818c93 | 134 | function isRequestTypeAddValid (value: string) { |
65fcc311 C |
135 | return value === ENDPOINT_ACTIONS.ADD |
136 | } | |
137 | ||
69818c93 | 138 | function isRequestTypeUpdateValid (value: string) { |
65fcc311 C |
139 | return value === ENDPOINT_ACTIONS.UPDATE |
140 | } | |
141 | ||
69818c93 | 142 | function isRequestTypeRemoveValid (value: string) { |
65fcc311 C |
143 | return value === ENDPOINT_ACTIONS.REMOVE |
144 | } | |
145 | ||
69818c93 | 146 | function isRequestTypeReportAbuseValid (value: string) { |
65fcc311 C |
147 | return value === ENDPOINT_ACTIONS.REPORT_ABUSE |
148 | } |