mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-04 18:29:27 +02:00
Server: fix makefriends validation and tests
This commit is contained in:
parent
6c1a098b41
commit
d57d6f2605
6 changed files with 145 additions and 115 deletions
|
@ -1,11 +1,13 @@
|
|||
'use strict'
|
||||
|
||||
const miscValidators = require('./misc')
|
||||
const podsValidators = require('./pods')
|
||||
const usersValidators = require('./users')
|
||||
const videosValidators = require('./videos')
|
||||
|
||||
const validators = {
|
||||
misc: miscValidators,
|
||||
pods: podsValidators,
|
||||
users: usersValidators,
|
||||
videos: videosValidators
|
||||
}
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
'use strict'
|
||||
|
||||
const validator = require('express-validator').validator
|
||||
|
||||
const miscValidators = {
|
||||
exists: exists,
|
||||
isArray: isArray,
|
||||
isEachUrl: isEachUrl
|
||||
isArray: isArray
|
||||
}
|
||||
|
||||
function exists (value) {
|
||||
|
@ -16,12 +13,6 @@ function isArray (value) {
|
|||
return Array.isArray(value)
|
||||
}
|
||||
|
||||
function isEachUrl (urls) {
|
||||
return urls.every(function (url) {
|
||||
return validator.isURL(url)
|
||||
})
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
module.exports = miscValidators
|
||||
|
|
21
server/helpers/custom-validators/pods.js
Normal file
21
server/helpers/custom-validators/pods.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
'use strict'
|
||||
|
||||
const validator = require('express-validator').validator
|
||||
|
||||
const miscValidators = require('./misc')
|
||||
|
||||
const podsValidators = {
|
||||
isEachUniqueUrlValid: isEachUniqueUrlValid
|
||||
}
|
||||
|
||||
function isEachUniqueUrlValid (urls) {
|
||||
return miscValidators.isArray(urls) &&
|
||||
urls.length !== 0 &&
|
||||
urls.every(function (url) {
|
||||
return validator.isURL(url) && urls.indexOf(url) === urls.lastIndexOf(url)
|
||||
})
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
module.exports = podsValidators
|
Loading…
Add table
Add a link
Reference in a new issue