aboutsummaryrefslogblamecommitdiffhomepage
path: root/server/helpers/customValidators.js
blob: 5a0e70ffc1df1f9c68561f0b6a96cdb31bd5e7c2 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
            
 
                                      
 

                                                      
                          



                                                               
 




                                                   
                                    
                             

                                                        
                                                                           

                                                                            
                                       

    
 




                                                 
 


                             
 
                                                                              
 
                                 
'use strict'

const validator = require('validator')

const constants = require('../initializers/constants')

const customValidators = {
  eachIsRemoteVideosAddValid: eachIsRemoteVideosAddValid,
  eachIsRemoteVideosRemoveValid: eachIsRemoteVideosRemoveValid,
  isArray: isArray
}

function eachIsRemoteVideosAddValid (values) {
  return values.every(function (val) {
    return validator.isLength(val.name, 1, 50) &&
      validator.isLength(val.description, 1, 50) &&
      validator.isLength(val.magnetUri, 10) &&
      validator.isURL(val.podUrl) &&
      !isNaN(val.duration) &&
      val.duration >= 0 &&
      val.duration < constants.MAXIMUM_VIDEO_DURATION &&
      validator.isLength(val.author, 1, constants.MAXIMUM_AUTHOR_LENGTH) &&
      validator.isBase64(val.thumbnailBase64) &&
      validator.isByteLength(val.thumbnailBase64, { min: 0, max: 20000 }) &&
      validator.isDate(val.createdDate)
  })
}

function eachIsRemoteVideosRemoveValid (values) {
  return values.every(function (val) {
    return validator.isLength(val.magnetUri, 10)
  })
}

function isArray (value) {
  return Array.isArray(value)
}

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

module.exports = customValidators