diff options
Diffstat (limited to 'server/helpers/custom-validators/remote/videos.js')
-rw-r--r-- | server/helpers/custom-validators/remote/videos.js | 118 |
1 files changed, 0 insertions, 118 deletions
diff --git a/server/helpers/custom-validators/remote/videos.js b/server/helpers/custom-validators/remote/videos.js deleted file mode 100644 index 24715b4b3..000000000 --- a/server/helpers/custom-validators/remote/videos.js +++ /dev/null | |||
@@ -1,118 +0,0 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | const has = require('lodash/has') | ||
4 | const values = require('lodash/values') | ||
5 | |||
6 | const constants = require('../../../initializers/constants') | ||
7 | const videosValidators = require('../videos') | ||
8 | const miscValidators = require('../misc') | ||
9 | |||
10 | const ENDPOINT_ACTIONS = constants.REQUEST_ENDPOINT_ACTIONS[constants.REQUEST_ENDPOINTS.VIDEOS] | ||
11 | |||
12 | const remoteVideosValidators = { | ||
13 | isEachRemoteRequestVideosValid, | ||
14 | isEachRemoteRequestVideosQaduValid, | ||
15 | isEachRemoteRequestVideosEventsValid | ||
16 | } | ||
17 | |||
18 | function isEachRemoteRequestVideosValid (requests) { | ||
19 | return miscValidators.isArray(requests) && | ||
20 | requests.every(function (request) { | ||
21 | const video = request.data | ||
22 | |||
23 | if (!video) return false | ||
24 | |||
25 | return ( | ||
26 | isRequestTypeAddValid(request.type) && | ||
27 | isCommonVideoAttributesValid(video) && | ||
28 | videosValidators.isVideoAuthorValid(video.author) && | ||
29 | videosValidators.isVideoThumbnailDataValid(video.thumbnailData) | ||
30 | ) || | ||
31 | ( | ||
32 | isRequestTypeUpdateValid(request.type) && | ||
33 | isCommonVideoAttributesValid(video) | ||
34 | ) || | ||
35 | ( | ||
36 | isRequestTypeRemoveValid(request.type) && | ||
37 | videosValidators.isVideoRemoteIdValid(video.remoteId) | ||
38 | ) || | ||
39 | ( | ||
40 | isRequestTypeReportAbuseValid(request.type) && | ||
41 | videosValidators.isVideoRemoteIdValid(request.data.videoRemoteId) && | ||
42 | videosValidators.isVideoAbuseReasonValid(request.data.reportReason) && | ||
43 | videosValidators.isVideoAbuseReporterUsernameValid(request.data.reporterUsername) | ||
44 | ) | ||
45 | }) | ||
46 | } | ||
47 | |||
48 | function isEachRemoteRequestVideosQaduValid (requests) { | ||
49 | return miscValidators.isArray(requests) && | ||
50 | requests.every(function (request) { | ||
51 | const video = request.data | ||
52 | |||
53 | if (!video) return false | ||
54 | |||
55 | return ( | ||
56 | videosValidators.isVideoRemoteIdValid(video.remoteId) && | ||
57 | (has(video, 'views') === false || videosValidators.isVideoViewsValid) && | ||
58 | (has(video, 'likes') === false || videosValidators.isVideoLikesValid) && | ||
59 | (has(video, 'dislikes') === false || videosValidators.isVideoDislikesValid) | ||
60 | ) | ||
61 | }) | ||
62 | } | ||
63 | |||
64 | function isEachRemoteRequestVideosEventsValid (requests) { | ||
65 | return miscValidators.isArray(requests) && | ||
66 | requests.every(function (request) { | ||
67 | const eventData = request.data | ||
68 | |||
69 | if (!eventData) return false | ||
70 | |||
71 | return ( | ||
72 | videosValidators.isVideoRemoteIdValid(eventData.remoteId) && | ||
73 | values(constants.REQUEST_VIDEO_EVENT_TYPES).indexOf(eventData.eventType) !== -1 && | ||
74 | videosValidators.isVideoEventCountValid(eventData.count) | ||
75 | ) | ||
76 | }) | ||
77 | } | ||
78 | |||
79 | // --------------------------------------------------------------------------- | ||
80 | |||
81 | module.exports = remoteVideosValidators | ||
82 | |||
83 | // --------------------------------------------------------------------------- | ||
84 | |||
85 | function isCommonVideoAttributesValid (video) { | ||
86 | return videosValidators.isVideoDateValid(video.createdAt) && | ||
87 | videosValidators.isVideoDateValid(video.updatedAt) && | ||
88 | videosValidators.isVideoCategoryValid(video.category) && | ||
89 | videosValidators.isVideoLicenceValid(video.licence) && | ||
90 | videosValidators.isVideoLanguageValid(video.language) && | ||
91 | videosValidators.isVideoNSFWValid(video.nsfw) && | ||
92 | videosValidators.isVideoDescriptionValid(video.description) && | ||
93 | videosValidators.isVideoDurationValid(video.duration) && | ||
94 | videosValidators.isVideoInfoHashValid(video.infoHash) && | ||
95 | videosValidators.isVideoNameValid(video.name) && | ||
96 | videosValidators.isVideoTagsValid(video.tags) && | ||
97 | videosValidators.isVideoRemoteIdValid(video.remoteId) && | ||
98 | videosValidators.isVideoExtnameValid(video.extname) && | ||
99 | videosValidators.isVideoViewsValid(video.views) && | ||
100 | videosValidators.isVideoLikesValid(video.likes) && | ||
101 | videosValidators.isVideoDislikesValid(video.dislikes) | ||
102 | } | ||
103 | |||
104 | function isRequestTypeAddValid (value) { | ||
105 | return value === ENDPOINT_ACTIONS.ADD | ||
106 | } | ||
107 | |||
108 | function isRequestTypeUpdateValid (value) { | ||
109 | return value === ENDPOINT_ACTIONS.UPDATE | ||
110 | } | ||
111 | |||
112 | function isRequestTypeRemoveValid (value) { | ||
113 | return value === ENDPOINT_ACTIONS.REMOVE | ||
114 | } | ||
115 | |||
116 | function isRequestTypeReportAbuseValid (value) { | ||
117 | return value === ENDPOINT_ACTIONS.REPORT_ABUSE | ||
118 | } | ||