aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators
diff options
context:
space:
mode:
Diffstat (limited to 'server/helpers/custom-validators')
-rw-r--r--server/helpers/custom-validators/remote/videos.ts12
-rw-r--r--server/helpers/custom-validators/videos.ts14
2 files changed, 16 insertions, 10 deletions
diff --git a/server/helpers/custom-validators/remote/videos.ts b/server/helpers/custom-validators/remote/videos.ts
index 1df7316aa..e14673cb3 100644
--- a/server/helpers/custom-validators/remote/videos.ts
+++ b/server/helpers/custom-validators/remote/videos.ts
@@ -9,7 +9,7 @@ import { isArray } from '../misc'
9import { 9import {
10 isVideoAuthorValid, 10 isVideoAuthorValid,
11 isVideoThumbnailDataValid, 11 isVideoThumbnailDataValid,
12 isVideoRemoteIdValid, 12 isVideoUUIDValid,
13 isVideoAbuseReasonValid, 13 isVideoAbuseReasonValid,
14 isVideoAbuseReporterUsernameValid, 14 isVideoAbuseReporterUsernameValid,
15 isVideoViewsValid, 15 isVideoViewsValid,
@@ -50,11 +50,11 @@ function isEachRemoteRequestVideosValid (requests: any[]) {
50 ) || 50 ) ||
51 ( 51 (
52 isRequestTypeRemoveValid(request.type) && 52 isRequestTypeRemoveValid(request.type) &&
53 isVideoRemoteIdValid(video.remoteId) 53 isVideoUUIDValid(video.uuid)
54 ) || 54 ) ||
55 ( 55 (
56 isRequestTypeReportAbuseValid(request.type) && 56 isRequestTypeReportAbuseValid(request.type) &&
57 isVideoRemoteIdValid(request.data.videoRemoteId) && 57 isVideoUUIDValid(request.data.videoUUID) &&
58 isVideoAbuseReasonValid(request.data.reportReason) && 58 isVideoAbuseReasonValid(request.data.reportReason) &&
59 isVideoAbuseReporterUsernameValid(request.data.reporterUsername) 59 isVideoAbuseReporterUsernameValid(request.data.reporterUsername)
60 ) 60 )
@@ -69,7 +69,7 @@ function isEachRemoteRequestVideosQaduValid (requests: any[]) {
69 if (!video) return false 69 if (!video) return false
70 70
71 return ( 71 return (
72 isVideoRemoteIdValid(video.remoteId) && 72 isVideoUUIDValid(video.uuid) &&
73 (has(video, 'views') === false || isVideoViewsValid(video.views)) && 73 (has(video, 'views') === false || isVideoViewsValid(video.views)) &&
74 (has(video, 'likes') === false || isVideoLikesValid(video.likes)) && 74 (has(video, 'likes') === false || isVideoLikesValid(video.likes)) &&
75 (has(video, 'dislikes') === false || isVideoDislikesValid(video.dislikes)) 75 (has(video, 'dislikes') === false || isVideoDislikesValid(video.dislikes))
@@ -85,7 +85,7 @@ function isEachRemoteRequestVideosEventsValid (requests: any[]) {
85 if (!eventData) return false 85 if (!eventData) return false
86 86
87 return ( 87 return (
88 isVideoRemoteIdValid(eventData.remoteId) && 88 isVideoUUIDValid(eventData.uuid) &&
89 values(REQUEST_VIDEO_EVENT_TYPES).indexOf(eventData.eventType) !== -1 && 89 values(REQUEST_VIDEO_EVENT_TYPES).indexOf(eventData.eventType) !== -1 &&
90 isVideoEventCountValid(eventData.count) 90 isVideoEventCountValid(eventData.count)
91 ) 91 )
@@ -124,7 +124,7 @@ function isCommonVideoAttributesValid (video: any) {
124 isVideoInfoHashValid(video.infoHash) && 124 isVideoInfoHashValid(video.infoHash) &&
125 isVideoNameValid(video.name) && 125 isVideoNameValid(video.name) &&
126 isVideoTagsValid(video.tags) && 126 isVideoTagsValid(video.tags) &&
127 isVideoRemoteIdValid(video.remoteId) && 127 isVideoUUIDValid(video.uuid) &&
128 isVideoExtnameValid(video.extname) && 128 isVideoExtnameValid(video.extname) &&
129 isVideoViewsValid(video.views) && 129 isVideoViewsValid(video.views) &&
130 isVideoLikesValid(video.likes) && 130 isVideoLikesValid(video.likes) &&
diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts
index 72d226e81..e335b09d1 100644
--- a/server/helpers/custom-validators/videos.ts
+++ b/server/helpers/custom-validators/videos.ts
@@ -17,6 +17,10 @@ const VIDEOS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEOS
17const VIDEO_ABUSES_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_ABUSES 17const VIDEO_ABUSES_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_ABUSES
18const VIDEO_EVENTS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_EVENTS 18const VIDEO_EVENTS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.VIDEO_EVENTS
19 19
20function isVideoIdOrUUIDValid (value: string) {
21 return validator.isInt(value) || isVideoUUIDValid(value)
22}
23
20function isVideoAuthorValid (value: string) { 24function isVideoAuthorValid (value: string) {
21 return isUserUsernameValid(value) 25 return isUserUsernameValid(value)
22} 26}
@@ -77,8 +81,8 @@ function isVideoThumbnailDataValid (value: string) {
77 return exists(value) && validator.isByteLength(value, VIDEOS_CONSTRAINTS_FIELDS.THUMBNAIL_DATA) 81 return exists(value) && validator.isByteLength(value, VIDEOS_CONSTRAINTS_FIELDS.THUMBNAIL_DATA)
78} 82}
79 83
80function isVideoRemoteIdValid (value: string) { 84function isVideoUUIDValid (value: string) {
81 return exists(value) && validator.isUUID(value, 4) 85 return exists(value) && validator.isUUID('' + value, 4)
82} 86}
83 87
84function isVideoAbuseReasonValid (value: string) { 88function isVideoAbuseReasonValid (value: string) {
@@ -127,6 +131,7 @@ function isVideoFile (value: string, files: { [ fieldname: string ]: Express.Mul
127// --------------------------------------------------------------------------- 131// ---------------------------------------------------------------------------
128 132
129export { 133export {
134 isVideoIdOrUUIDValid,
130 isVideoAuthorValid, 135 isVideoAuthorValid,
131 isVideoDateValid, 136 isVideoDateValid,
132 isVideoCategoryValid, 137 isVideoCategoryValid,
@@ -141,7 +146,7 @@ export {
141 isVideoThumbnailValid, 146 isVideoThumbnailValid,
142 isVideoThumbnailDataValid, 147 isVideoThumbnailDataValid,
143 isVideoExtnameValid, 148 isVideoExtnameValid,
144 isVideoRemoteIdValid, 149 isVideoUUIDValid,
145 isVideoAbuseReasonValid, 150 isVideoAbuseReasonValid,
146 isVideoAbuseReporterUsernameValid, 151 isVideoAbuseReporterUsernameValid,
147 isVideoFile, 152 isVideoFile,
@@ -155,6 +160,7 @@ export {
155declare global { 160declare global {
156 namespace ExpressValidator { 161 namespace ExpressValidator {
157 export interface Validator { 162 export interface Validator {
163 isVideoIdOrUUIDValid,
158 isVideoAuthorValid, 164 isVideoAuthorValid,
159 isVideoDateValid, 165 isVideoDateValid,
160 isVideoCategoryValid, 166 isVideoCategoryValid,
@@ -169,7 +175,7 @@ declare global {
169 isVideoThumbnailValid, 175 isVideoThumbnailValid,
170 isVideoThumbnailDataValid, 176 isVideoThumbnailDataValid,
171 isVideoExtnameValid, 177 isVideoExtnameValid,
172 isVideoRemoteIdValid, 178 isVideoUUIDValid,
173 isVideoAbuseReasonValid, 179 isVideoAbuseReasonValid,
174 isVideoAbuseReporterUsernameValid, 180 isVideoAbuseReporterUsernameValid,
175 isVideoFile, 181 isVideoFile,