PeerTube/server/helpers/custom-validators/pods.js

27 lines
626 B
JavaScript
Raw Normal View History

'use strict'
const validator = require('express-validator').validator
const miscValidators = require('./misc')
const podsValidators = {
2016-12-28 08:49:23 -06:00
isEachUniqueHostValid,
isHostValid
}
function isHostValid (host) {
return validator.isURL(host) && host.split('://').length === 1
}
function isEachUniqueHostValid (hosts) {
return miscValidators.isArray(hosts) &&
hosts.length !== 0 &&
hosts.every(function (host) {
2016-12-28 08:49:23 -06:00
return isHostValid(host) && hosts.indexOf(host) === hosts.lastIndexOf(host)
})
}
// ---------------------------------------------------------------------------
module.exports = podsValidators