aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators/remote
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-11-09 17:51:58 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-11-27 19:40:51 +0100
commite4f97babf701481b55cc10fb3448feab5f97c867 (patch)
treeaf37402a594dc5ff09f71ecb0687e8cfe4cdb471 /server/helpers/custom-validators/remote
parent343ad675f2a26c15b86150a9a3552e619d5d44f4 (diff)
downloadPeerTube-e4f97babf701481b55cc10fb3448feab5f97c867.tar.gz
PeerTube-e4f97babf701481b55cc10fb3448feab5f97c867.tar.zst
PeerTube-e4f97babf701481b55cc10fb3448feab5f97c867.zip
Begin activitypub
Diffstat (limited to 'server/helpers/custom-validators/remote')
-rw-r--r--server/helpers/custom-validators/remote/index.ts1
-rw-r--r--server/helpers/custom-validators/remote/videos.ts184
2 files changed, 0 insertions, 185 deletions
diff --git a/server/helpers/custom-validators/remote/index.ts b/server/helpers/custom-validators/remote/index.ts
deleted file mode 100644
index e29a9b767..000000000
--- a/server/helpers/custom-validators/remote/index.ts
+++ /dev/null
@@ -1 +0,0 @@
1export * from './videos'
diff --git a/server/helpers/custom-validators/remote/videos.ts b/server/helpers/custom-validators/remote/videos.ts
deleted file mode 100644
index e0ffba679..000000000
--- a/server/helpers/custom-validators/remote/videos.ts
+++ /dev/null
@@ -1,184 +0,0 @@
1import 'express-validator'
2import { has, values } from 'lodash'
3
4import {
5 REQUEST_ENDPOINTS,
6 REQUEST_ENDPOINT_ACTIONS,
7 REQUEST_VIDEO_EVENT_TYPES
8} from '../../../initializers'
9import { isArray, isDateValid, isUUIDValid } from '../misc'
10import {
11 isVideoThumbnailDataValid,
12 isVideoAbuseReasonValid,
13 isVideoAbuseReporterUsernameValid,
14 isVideoViewsValid,
15 isVideoLikesValid,
16 isVideoDislikesValid,
17 isVideoEventCountValid,
18 isRemoteVideoCategoryValid,
19 isRemoteVideoLicenceValid,
20 isRemoteVideoLanguageValid,
21 isVideoNSFWValid,
22 isVideoTruncatedDescriptionValid,
23 isVideoDurationValid,
24 isVideoFileInfoHashValid,
25 isVideoNameValid,
26 isVideoTagsValid,
27 isVideoFileExtnameValid,
28 isVideoFileResolutionValid
29} from '../videos'
30import { isVideoChannelDescriptionValid, isVideoChannelNameValid } from '../video-channels'
31import { isVideoAuthorNameValid } from '../video-authors'
32
33const ENDPOINT_ACTIONS = REQUEST_ENDPOINT_ACTIONS[REQUEST_ENDPOINTS.VIDEOS]
34
35const checkers: { [ id: string ]: (obj: any) => boolean } = {}
36checkers[ENDPOINT_ACTIONS.ADD_VIDEO] = checkAddVideo
37checkers[ENDPOINT_ACTIONS.UPDATE_VIDEO] = checkUpdateVideo
38checkers[ENDPOINT_ACTIONS.REMOVE_VIDEO] = checkRemoveVideo
39checkers[ENDPOINT_ACTIONS.REPORT_ABUSE] = checkReportVideo
40checkers[ENDPOINT_ACTIONS.ADD_CHANNEL] = checkAddVideoChannel
41checkers[ENDPOINT_ACTIONS.UPDATE_CHANNEL] = checkUpdateVideoChannel
42checkers[ENDPOINT_ACTIONS.REMOVE_CHANNEL] = checkRemoveVideoChannel
43checkers[ENDPOINT_ACTIONS.ADD_AUTHOR] = checkAddAuthor
44checkers[ENDPOINT_ACTIONS.REMOVE_AUTHOR] = checkRemoveAuthor
45
46function removeBadRequestVideos (requests: any[]) {
47 for (let i = requests.length - 1; i >= 0 ; i--) {
48 const request = requests[i]
49 const video = request.data
50
51 if (
52 !video ||
53 checkers[request.type] === undefined ||
54 checkers[request.type](video) === false
55 ) {
56 requests.splice(i, 1)
57 }
58 }
59}
60
61function removeBadRequestVideosQadu (requests: any[]) {
62 for (let i = requests.length - 1; i >= 0 ; i--) {
63 const request = requests[i]
64 const video = request.data
65
66 if (
67 !video ||
68 (
69 isUUIDValid(video.uuid) &&
70 (has(video, 'views') === false || isVideoViewsValid(video.views)) &&
71 (has(video, 'likes') === false || isVideoLikesValid(video.likes)) &&
72 (has(video, 'dislikes') === false || isVideoDislikesValid(video.dislikes))
73 ) === false
74 ) {
75 requests.splice(i, 1)
76 }
77 }
78}
79
80function removeBadRequestVideosEvents (requests: any[]) {
81 for (let i = requests.length - 1; i >= 0 ; i--) {
82 const request = requests[i]
83 const eventData = request.data
84
85 if (
86 !eventData ||
87 (
88 isUUIDValid(eventData.uuid) &&
89 values(REQUEST_VIDEO_EVENT_TYPES).indexOf(eventData.eventType) !== -1 &&
90 isVideoEventCountValid(eventData.count)
91 ) === false
92 ) {
93 requests.splice(i, 1)
94 }
95 }
96}
97
98// ---------------------------------------------------------------------------
99
100export {
101 removeBadRequestVideos,
102 removeBadRequestVideosQadu,
103 removeBadRequestVideosEvents
104}
105
106// ---------------------------------------------------------------------------
107
108function isCommonVideoAttributesValid (video: any) {
109 return isDateValid(video.createdAt) &&
110 isDateValid(video.updatedAt) &&
111 isRemoteVideoCategoryValid(video.category) &&
112 isRemoteVideoLicenceValid(video.licence) &&
113 isRemoteVideoLanguageValid(video.language) &&
114 isVideoNSFWValid(video.nsfw) &&
115 isVideoTruncatedDescriptionValid(video.truncatedDescription) &&
116 isVideoDurationValid(video.duration) &&
117 isVideoNameValid(video.name) &&
118 isVideoTagsValid(video.tags) &&
119 isUUIDValid(video.uuid) &&
120 isVideoViewsValid(video.views) &&
121 isVideoLikesValid(video.likes) &&
122 isVideoDislikesValid(video.dislikes) &&
123 isArray(video.files) &&
124 video.files.every(videoFile => {
125 if (!videoFile) return false
126
127 return (
128 isVideoFileInfoHashValid(videoFile.infoHash) &&
129 isVideoFileExtnameValid(videoFile.extname) &&
130 isVideoFileResolutionValid(videoFile.resolution)
131 )
132 })
133}
134
135function checkAddVideo (video: any) {
136 return isCommonVideoAttributesValid(video) &&
137 isUUIDValid(video.channelUUID) &&
138 isVideoThumbnailDataValid(video.thumbnailData)
139}
140
141function checkUpdateVideo (video: any) {
142 return isCommonVideoAttributesValid(video)
143}
144
145function checkRemoveVideo (video: any) {
146 return isUUIDValid(video.uuid)
147}
148
149function checkReportVideo (abuse: any) {
150 return isUUIDValid(abuse.videoUUID) &&
151 isVideoAbuseReasonValid(abuse.reportReason) &&
152 isVideoAbuseReporterUsernameValid(abuse.reporterUsername)
153}
154
155function checkAddVideoChannel (videoChannel: any) {
156 return isUUIDValid(videoChannel.uuid) &&
157 isVideoChannelNameValid(videoChannel.name) &&
158 isVideoChannelDescriptionValid(videoChannel.description) &&
159 isDateValid(videoChannel.createdAt) &&
160 isDateValid(videoChannel.updatedAt) &&
161 isUUIDValid(videoChannel.ownerUUID)
162}
163
164function checkUpdateVideoChannel (videoChannel: any) {
165 return isUUIDValid(videoChannel.uuid) &&
166 isVideoChannelNameValid(videoChannel.name) &&
167 isVideoChannelDescriptionValid(videoChannel.description) &&
168 isDateValid(videoChannel.createdAt) &&
169 isDateValid(videoChannel.updatedAt) &&
170 isUUIDValid(videoChannel.ownerUUID)
171}
172
173function checkRemoveVideoChannel (videoChannel: any) {
174 return isUUIDValid(videoChannel.uuid)
175}
176
177function checkAddAuthor (author: any) {
178 return isUUIDValid(author.uuid) &&
179 isVideoAuthorNameValid(author.name)
180}
181
182function checkRemoveAuthor (author: any) {
183 return isUUIDValid(author.uuid)
184}