]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/helpers/custom-validators/remote/videos.js
Server: remote video validators refractoring
[github/Chocobozzz/PeerTube.git] / server / helpers / custom-validators / remote / videos.js
CommitLineData
55fa55a9
C
1'use strict'
2
da691c46 3const constants = require('../../../initializers/constants')
55fa55a9
C
4const videosValidators = require('../videos')
5const miscValidators = require('../misc')
6
da691c46
C
7const ENDPOINT_ACTIONS = constants.REQUEST_ENDPOINT_ACTIONS[constants.REQUEST_ENDPOINTS.VIDEOS]
8
55fa55a9
C
9const remoteVideosValidators = {
10 isEachRemoteRequestVideosValid
11}
12
13function isEachRemoteRequestVideosValid (requests) {
14 return miscValidators.isArray(requests) &&
15 requests.every(function (request) {
16 const video = request.data
17 return (
18 isRequestTypeAddValid(request.type) &&
da691c46 19 isCommonVideoAttrbiutesValid(video) &&
55fa55a9 20 videosValidators.isVideoAuthorValid(video.author) &&
da691c46 21 videosValidators.isVideoThumbnailDataValid(video.thumbnailData)
55fa55a9
C
22 ) ||
23 (
24 isRequestTypeUpdateValid(request.type) &&
da691c46 25 isCommonVideoAttrbiutesValid(video)
55fa55a9
C
26 ) ||
27 (
28 isRequestTypeRemoveValid(request.type) &&
55fa55a9
C
29 videosValidators.isVideoRemoteIdValid(video.remoteId)
30 ) ||
31 (
32 isRequestTypeReportAbuseValid(request.type) &&
33 videosValidators.isVideoRemoteIdValid(request.data.videoRemoteId) &&
34 videosValidators.isVideoAbuseReasonValid(request.data.reportReason) &&
35 videosValidators.isVideoAbuseReporterUsernameValid(request.data.reporterUsername)
36 )
37 })
38}
39
40// ---------------------------------------------------------------------------
41
42module.exports = remoteVideosValidators
43
44// ---------------------------------------------------------------------------
45
da691c46
C
46function isCommonVideoAttrbiutesValid (video) {
47 return videosValidators.isVideoDateValid(video.createdAt) &&
48 videosValidators.isVideoDateValid(video.updatedAt) &&
49 videosValidators.isVideoDescriptionValid(video.description) &&
50 videosValidators.isVideoDurationValid(video.duration) &&
51 videosValidators.isVideoInfoHashValid(video.infoHash) &&
52 videosValidators.isVideoNameValid(video.name) &&
53 videosValidators.isVideoTagsValid(video.tags) &&
54 videosValidators.isVideoRemoteIdValid(video.remoteId) &&
55 videosValidators.isVideoExtnameValid(video.extname)
56}
57
55fa55a9 58function isRequestTypeAddValid (value) {
da691c46 59 return value === ENDPOINT_ACTIONS.ADD
55fa55a9
C
60}
61
62function isRequestTypeUpdateValid (value) {
da691c46 63 return value === ENDPOINT_ACTIONS.UPDATE
55fa55a9
C
64}
65
66function isRequestTypeRemoveValid (value) {
da691c46 67 return value === ENDPOINT_ACTIONS.REMOVE
55fa55a9
C
68}
69
70function isRequestTypeReportAbuseValid (value) {
da691c46 71 return value === ENDPOINT_ACTIONS.REPORT_ABUSE
55fa55a9 72}