aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-10-26 10:40:37 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-10-26 10:40:37 +0200
commit51c443dbe0284c5ec54033be06f554ec37397bce (patch)
tree5312f85f1c8b9c62a77c05c8e440e301e5be3137 /server/helpers
parentfaab3a8453e2af92f95518e55e00293ac140b6e8 (diff)
downloadPeerTube-51c443dbe0284c5ec54033be06f554ec37397bce.tar.gz
PeerTube-51c443dbe0284c5ec54033be06f554ec37397bce.tar.zst
PeerTube-51c443dbe0284c5ec54033be06f554ec37397bce.zip
Be tolerant with remote requests
Just remove videos we don't want
Diffstat (limited to 'server/helpers')
-rw-r--r--server/helpers/custom-validators/remote/videos.ts86
-rw-r--r--server/helpers/custom-validators/videos.ts20
2 files changed, 65 insertions, 41 deletions
diff --git a/server/helpers/custom-validators/remote/videos.ts b/server/helpers/custom-validators/remote/videos.ts
index 057996f1c..a9ca36fe8 100644
--- a/server/helpers/custom-validators/remote/videos.ts
+++ b/server/helpers/custom-validators/remote/videos.ts
@@ -15,9 +15,9 @@ import {
15 isVideoLikesValid, 15 isVideoLikesValid,
16 isVideoDislikesValid, 16 isVideoDislikesValid,
17 isVideoEventCountValid, 17 isVideoEventCountValid,
18 isVideoCategoryValid, 18 isRemoteVideoCategoryValid,
19 isVideoLicenceValid, 19 isRemoteVideoLicenceValid,
20 isVideoLanguageValid, 20 isRemoteVideoLanguageValid,
21 isVideoNSFWValid, 21 isVideoNSFWValid,
22 isVideoDescriptionValid, 22 isVideoDescriptionValid,
23 isVideoDurationValid, 23 isVideoDurationValid,
@@ -43,58 +43,64 @@ checkers[ENDPOINT_ACTIONS.REMOVE_CHANNEL] = checkRemoveVideoChannel
43checkers[ENDPOINT_ACTIONS.ADD_AUTHOR] = checkAddAuthor 43checkers[ENDPOINT_ACTIONS.ADD_AUTHOR] = checkAddAuthor
44checkers[ENDPOINT_ACTIONS.REMOVE_AUTHOR] = checkRemoveAuthor 44checkers[ENDPOINT_ACTIONS.REMOVE_AUTHOR] = checkRemoveAuthor
45 45
46function isEachRemoteRequestVideosValid (requests: any[]) { 46function removeBadRequestVideos (requests: any[]) {
47 return isArray(requests) && 47 for (let i = requests.length - 1; i >= 0 ; i--) {
48 requests.every(request => { 48 const request = requests[i]
49 const video = request.data 49 const video = request.data
50 50
51 if (!video) return false 51 if (
52 52 !video ||
53 const checker = checkers[request.type] 53 checkers[request.type] === undefined ||
54 // We don't know the request type 54 checkers[request.type](video) === false
55 if (checker === undefined) return false 55 ) {
56 56 requests.splice(i, 1)
57 return checker(video) 57 }
58 }) 58 }
59} 59}
60 60
61function isEachRemoteRequestVideosQaduValid (requests: any[]) { 61function removeBadRequestVideosQadu (requests: any[]) {
62 return isArray(requests) && 62 for (let i = requests.length - 1; i >= 0 ; i--) {
63 requests.every(request => { 63 const request = requests[i]
64 const video = request.data 64 const video = request.data
65 65
66 if (!video) return false 66 if (
67 67 !video ||
68 return ( 68 (
69 isUUIDValid(video.uuid) && 69 isUUIDValid(video.uuid) &&
70 (has(video, 'views') === false || isVideoViewsValid(video.views)) && 70 (has(video, 'views') === false || isVideoViewsValid(video.views)) &&
71 (has(video, 'likes') === false || isVideoLikesValid(video.likes)) && 71 (has(video, 'likes') === false || isVideoLikesValid(video.likes)) &&
72 (has(video, 'dislikes') === false || isVideoDislikesValid(video.dislikes)) 72 (has(video, 'dislikes') === false || isVideoDislikesValid(video.dislikes))
73 ) 73 ) === false
74 }) 74 ) {
75 requests.splice(i, 1)
76 }
77 }
75} 78}
76 79
77function isEachRemoteRequestVideosEventsValid (requests: any[]) { 80function removeBadRequestVideosEvents (requests: any[]) {
78 return isArray(requests) && 81 for (let i = requests.length - 1; i >= 0 ; i--) {
79 requests.every(request => { 82 const request = requests[i]
80 const eventData = request.data 83 const eventData = request.data
81
82 if (!eventData) return false
83 84
84 return ( 85 if (
86 !eventData ||
87 (
85 isUUIDValid(eventData.uuid) && 88 isUUIDValid(eventData.uuid) &&
86 values(REQUEST_VIDEO_EVENT_TYPES).indexOf(eventData.eventType) !== -1 && 89 values(REQUEST_VIDEO_EVENT_TYPES).indexOf(eventData.eventType) !== -1 &&
87 isVideoEventCountValid(eventData.count) 90 isVideoEventCountValid(eventData.count)
88 ) 91 ) === false
89 }) 92 ) {
93 requests.splice(i, 1)
94 }
95 }
90} 96}
91 97
92// --------------------------------------------------------------------------- 98// ---------------------------------------------------------------------------
93 99
94export { 100export {
95 isEachRemoteRequestVideosValid, 101 removeBadRequestVideos,
96 isEachRemoteRequestVideosQaduValid, 102 removeBadRequestVideosQadu,
97 isEachRemoteRequestVideosEventsValid 103 removeBadRequestVideosEvents
98} 104}
99 105
100// --------------------------------------------------------------------------- 106// ---------------------------------------------------------------------------
@@ -102,9 +108,9 @@ export {
102function isCommonVideoAttributesValid (video: any) { 108function isCommonVideoAttributesValid (video: any) {
103 return isDateValid(video.createdAt) && 109 return isDateValid(video.createdAt) &&
104 isDateValid(video.updatedAt) && 110 isDateValid(video.updatedAt) &&
105 isVideoCategoryValid(video.category) && 111 isRemoteVideoCategoryValid(video.category) &&
106 isVideoLicenceValid(video.licence) && 112 isRemoteVideoLicenceValid(video.licence) &&
107 isVideoLanguageValid(video.language) && 113 isRemoteVideoLanguageValid(video.language) &&
108 isVideoNSFWValid(video.nsfw) && 114 isVideoNSFWValid(video.nsfw) &&
109 isVideoDescriptionValid(video.description) && 115 isVideoDescriptionValid(video.description) &&
110 isVideoDurationValid(video.duration) && 116 isVideoDurationValid(video.duration) &&
diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts
index 4e441fe5f..11b085b78 100644
--- a/server/helpers/custom-validators/videos.ts
+++ b/server/helpers/custom-validators/videos.ts
@@ -27,14 +27,29 @@ function isVideoCategoryValid (value: number) {
27 return VIDEO_CATEGORIES[value] !== undefined 27 return VIDEO_CATEGORIES[value] !== undefined
28} 28}
29 29
30// Maybe we don't know the remote category, but that doesn't matter
31function isRemoteVideoCategoryValid (value: string) {
32 return validator.isInt('' + value)
33}
34
30function isVideoLicenceValid (value: number) { 35function isVideoLicenceValid (value: number) {
31 return VIDEO_LICENCES[value] !== undefined 36 return VIDEO_LICENCES[value] !== undefined
32} 37}
33 38
39// Maybe we don't know the remote licence, but that doesn't matter
40function isRemoteVideoLicenceValid (value: string) {
41 return validator.isInt('' + value)
42}
43
34function isVideoLanguageValid (value: number) { 44function isVideoLanguageValid (value: number) {
35 return value === null || VIDEO_LANGUAGES[value] !== undefined 45 return value === null || VIDEO_LANGUAGES[value] !== undefined
36} 46}
37 47
48// Maybe we don't know the remote language, but that doesn't matter
49function isRemoteVideoLanguageValid (value: string) {
50 return validator.isInt('' + value)
51}
52
38function isVideoNSFWValid (value: any) { 53function isVideoNSFWValid (value: any) {
39 return typeof value === 'boolean' || (typeof value === 'string' && validator.isBoolean(value)) 54 return typeof value === 'boolean' || (typeof value === 'string' && validator.isBoolean(value))
40} 55}
@@ -176,5 +191,8 @@ export {
176 isVideoEventCountValid, 191 isVideoEventCountValid,
177 isVideoFileSizeValid, 192 isVideoFileSizeValid,
178 isVideoFileResolutionValid, 193 isVideoFileResolutionValid,
179 checkVideoExists 194 checkVideoExists,
195 isRemoteVideoCategoryValid,
196 isRemoteVideoLicenceValid,
197 isRemoteVideoLanguageValid
180} 198}