aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators/remote/videos.js
blob: ee68ebc10d05b997141036bfa3e33608292ba612 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
'use strict'

const constants = require('../../../initializers/constants')
const videosValidators = require('../videos')
const miscValidators = require('../misc')

const ENDPOINT_ACTIONS = constants.REQUEST_ENDPOINT_ACTIONS[constants.REQUEST_ENDPOINTS.VIDEOS]

const remoteVideosValidators = {
  isEachRemoteRequestVideosValid
}

function isEachRemoteRequestVideosValid (requests) {
  return miscValidators.isArray(requests) &&
    requests.every(function (request) {
      const video = request.data
      return (
        isRequestTypeAddValid(request.type) &&
        isCommonVideoAttrbiutesValid(video) &&
        videosValidators.isVideoAuthorValid(video.author) &&
        videosValidators.isVideoThumbnailDataValid(video.thumbnailData)
      ) ||
      (
        isRequestTypeUpdateValid(request.type) &&
        isCommonVideoAttrbiutesValid(video)
      ) ||
      (
        isRequestTypeRemoveValid(request.type) &&
        videosValidators.isVideoRemoteIdValid(video.remoteId)
      ) ||
      (
        isRequestTypeReportAbuseValid(request.type) &&
        videosValidators.isVideoRemoteIdValid(request.data.videoRemoteId) &&
        videosValidators.isVideoAbuseReasonValid(request.data.reportReason) &&
        videosValidators.isVideoAbuseReporterUsernameValid(request.data.reporterUsername)
      )
    })
}

// ---------------------------------------------------------------------------

module.exports = remoteVideosValidators

// ---------------------------------------------------------------------------

function isCommonVideoAttrbiutesValid (video) {
  return videosValidators.isVideoDateValid(video.createdAt) &&
         videosValidators.isVideoDateValid(video.updatedAt) &&
         videosValidators.isVideoDescriptionValid(video.description) &&
         videosValidators.isVideoDurationValid(video.duration) &&
         videosValidators.isVideoInfoHashValid(video.infoHash) &&
         videosValidators.isVideoNameValid(video.name) &&
         videosValidators.isVideoTagsValid(video.tags) &&
         videosValidators.isVideoRemoteIdValid(video.remoteId) &&
         videosValidators.isVideoExtnameValid(video.extname)
}

function isRequestTypeAddValid (value) {
  return value === ENDPOINT_ACTIONS.ADD
}

function isRequestTypeUpdateValid (value) {
  return value === ENDPOINT_ACTIONS.UPDATE
}

function isRequestTypeRemoveValid (value) {
  return value === ENDPOINT_ACTIONS.REMOVE
}

function isRequestTypeReportAbuseValid (value) {
  return value === ENDPOINT_ACTIONS.REPORT_ABUSE
}