]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/helpers/custom-validators/videos.js
Server: add licence video attribute
[github/Chocobozzz/PeerTube.git] / server / helpers / custom-validators / videos.js
index c5a1f3cb5684d24af5932671497c2e528b9d10ae..8495e9665965d3b9a759c6d2b09f1829a43e38ad 100644 (file)
@@ -1,6 +1,7 @@
 'use strict'
 
 const validator = require('express-validator').validator
+const values = require('lodash/values')
 
 const constants = require('../../initializers/constants')
 const usersValidators = require('./users')
@@ -12,6 +13,8 @@ const VIDEO_EVENTS_CONSTRAINTS_FIELDS = constants.CONSTRAINTS_FIELDS.VIDEO_EVENT
 const videosValidators = {
   isVideoAuthorValid,
   isVideoDateValid,
+  isVideoCategoryValid,
+  isVideoLicenceValid,
   isVideoDescriptionValid,
   isVideoDurationValid,
   isVideoInfoHashValid,
@@ -26,6 +29,7 @@ const videosValidators = {
   isVideoFile,
   isVideoViewsValid,
   isVideoLikesValid,
+  isVideoRatingTypeValid,
   isVideoDislikesValid,
   isVideoEventCountValid
 }
@@ -38,6 +42,14 @@ function isVideoDateValid (value) {
   return validator.isDate(value)
 }
 
+function isVideoCategoryValid (value) {
+  return constants.VIDEO_CATEGORIES[value] !== undefined
+}
+
+function isVideoLicenceValid (value) {
+  return constants.VIDEO_LICENCES[value] !== undefined
+}
+
 function isVideoDescriptionValid (value) {
   return validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.DESCRIPTION)
 }
@@ -62,8 +74,7 @@ function isVideoTagsValid (tags) {
   return miscValidators.isArray(tags) &&
          validator.isInt(tags.length, VIDEOS_CONSTRAINTS_FIELDS.TAGS) &&
          tags.every(function (tag) {
-           return validator.isAlphanumeric(tag) &&
-                  validator.isLength(tag, VIDEOS_CONSTRAINTS_FIELDS.TAG)
+           return validator.isLength(tag, VIDEOS_CONSTRAINTS_FIELDS.TAG)
          })
 }
 
@@ -103,6 +114,10 @@ function isVideoEventCountValid (value) {
   return validator.isInt(value + '', VIDEO_EVENTS_CONSTRAINTS_FIELDS.COUNT)
 }
 
+function isVideoRatingTypeValid (value) {
+  return values(constants.VIDEO_RATE_TYPES).indexOf(value) !== -1
+}
+
 function isVideoFile (value, files) {
   // Should have files
   if (!files) return false