Add check for the author username length
[oweals/peertube.git] / server / helpers / customValidators.js
1 'use strict'
2
3 const validator = require('validator')
4
5 const constants = require('../initializers/constants')
6
7 const customValidators = {
8   eachIsRemoteVideosAddValid: eachIsRemoteVideosAddValid,
9   eachIsRemoteVideosRemoveValid: eachIsRemoteVideosRemoveValid,
10   isArray: isArray
11 }
12
13 function eachIsRemoteVideosAddValid (values) {
14   return values.every(function (val) {
15     return validator.isLength(val.name, 1, 50) &&
16       validator.isLength(val.description, 1, 50) &&
17       validator.isLength(val.magnetUri, 10) &&
18       validator.isURL(val.podUrl) &&
19       !isNaN(val.duration) &&
20       val.duration >= 0 &&
21       val.duration < constants.MAXIMUM_VIDEO_DURATION &&
22       validator.isLength(val.author, 1, constants.MAXIMUM_AUTHOR_LENGTH) &&
23       validator.isDate(val.createdDate)
24   })
25 }
26
27 function eachIsRemoteVideosRemoveValid (values) {
28   return values.every(function (val) {
29     return validator.isLength(val.magnetUri, 10)
30   })
31 }
32
33 function isArray (value) {
34   return Array.isArray(value)
35 }
36
37 // ---------------------------------------------------------------------------
38
39 module.exports = customValidators