PeerTube/server/helpers/customValidators.js

42 lines
1.2 KiB
JavaScript
Raw Normal View History

'use strict'
2016-03-16 22:29:27 +01:00
const validator = require('validator')
2016-05-16 19:49:10 +02:00
const constants = require('../initializers/constants')
2016-03-16 22:29:27 +01:00
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) &&
2016-05-03 22:41:46 +02:00
validator.isURL(val.podUrl) &&
2016-05-13 20:42:11 +02:00
!isNaN(val.duration) &&
2016-05-16 19:49:10 +02:00
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 }) &&
2016-05-13 20:42:11 +02:00
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)
}
// ---------------------------------------------------------------------------
2016-01-31 11:23:52 +01:00
module.exports = customValidators