aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators/remote
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/custom-validators/remote
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/custom-validators/remote')
-rw-r--r--server/helpers/custom-validators/remote/videos.ts86
1 files changed, 46 insertions, 40 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) &&