2016-02-07 04:23:23 -06:00
|
|
|
'use strict'
|
2015-12-04 09:13:32 -06:00
|
|
|
|
2016-03-16 16:29:27 -05:00
|
|
|
const validator = require('validator')
|
2015-12-04 09:13:32 -06:00
|
|
|
|
2016-05-16 12:49:10 -05:00
|
|
|
const constants = require('../initializers/constants')
|
|
|
|
|
2016-03-16 16:29:27 -05:00
|
|
|
const customValidators = {
|
2016-02-07 04:23:23 -06:00
|
|
|
eachIsRemoteVideosAddValid: eachIsRemoteVideosAddValid,
|
|
|
|
eachIsRemoteVideosRemoveValid: eachIsRemoteVideosRemoveValid,
|
|
|
|
isArray: isArray
|
|
|
|
}
|
2015-12-04 09:13:32 -06:00
|
|
|
|
2016-02-07 04:23:23 -06:00
|
|
|
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) &&
|
2016-05-03 15:41:46 -05:00
|
|
|
validator.isURL(val.podUrl) &&
|
2016-05-13 13:42:11 -05:00
|
|
|
!isNaN(val.duration) &&
|
2016-05-16 12:49:10 -05:00
|
|
|
val.duration >= 0 &&
|
|
|
|
val.duration < constants.MAXIMUM_VIDEO_DURATION &&
|
2016-05-16 12:51:07 -05:00
|
|
|
validator.isLength(val.author, 1, constants.MAXIMUM_AUTHOR_LENGTH) &&
|
2016-05-16 12:55:32 -05:00
|
|
|
validator.isBase64(val.thumbnailBase64) &&
|
|
|
|
validator.isByteLength(val.thumbnailBase64, { min: 0, max: 20000 }) &&
|
2016-05-13 13:42:11 -05:00
|
|
|
validator.isDate(val.createdDate)
|
2016-02-07 04:23:23 -06:00
|
|
|
})
|
|
|
|
}
|
2015-12-04 09:13:32 -06:00
|
|
|
|
2016-02-07 04:23:23 -06:00
|
|
|
function eachIsRemoteVideosRemoveValid (values) {
|
|
|
|
return values.every(function (val) {
|
|
|
|
return validator.isLength(val.magnetUri, 10)
|
|
|
|
})
|
|
|
|
}
|
2015-12-04 09:13:32 -06:00
|
|
|
|
2016-02-07 04:23:23 -06:00
|
|
|
function isArray (value) {
|
|
|
|
return Array.isArray(value)
|
|
|
|
}
|
2015-12-04 09:13:32 -06:00
|
|
|
|
2016-02-07 04:23:23 -06:00
|
|
|
// ---------------------------------------------------------------------------
|
2016-01-31 04:23:52 -06:00
|
|
|
|
2016-02-07 04:23:23 -06:00
|
|
|
module.exports = customValidators
|