]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/video.js
Server: reorganize express validators
[github/Chocobozzz/PeerTube.git] / server / models / video.js
index a8a70ba89ff41168065e541c743d90e0b4e68953..acb8353c2891b411e2b2e3fb64a32ec7bd1a033b 100644 (file)
@@ -1,14 +1,15 @@
 'use strict'
 
-const async = require('async')
 const config = require('config')
+const eachLimit = require('async/eachLimit')
 const ffmpeg = require('fluent-ffmpeg')
 const fs = require('fs')
+const parallel = require('async/parallel')
 const pathUtils = require('path')
 const mongoose = require('mongoose')
 
 const constants = require('../initializers/constants')
-const customValidators = require('../helpers/customValidators')
+const customVideosValidators = require('../helpers/custom-validators').videos
 const logger = require('../helpers/logger')
 const utils = require('../helpers/utils')
 const webtorrent = require('../lib/webtorrent')
@@ -38,18 +39,18 @@ const VideoSchema = mongoose.Schema({
   }
 })
 
-VideoSchema.path('name').validate(customValidators.isVideoNameValid)
-VideoSchema.path('description').validate(customValidators.isVideoDescriptionValid)
-VideoSchema.path('magnetUri').validate(customValidators.isVideoMagnetUriValid)
-VideoSchema.path('podUrl').validate(customValidators.isVideoPodUrlValid)
-VideoSchema.path('author').validate(customValidators.isVideoAuthorValid)
-VideoSchema.path('duration').validate(customValidators.isVideoDurationValid)
+VideoSchema.path('name').validate(customVideosValidators.isVideoNameValid)
+VideoSchema.path('description').validate(customVideosValidators.isVideoDescriptionValid)
+VideoSchema.path('magnetUri').validate(customVideosValidators.isVideoMagnetUriValid)
+VideoSchema.path('podUrl').validate(customVideosValidators.isVideoPodUrlValid)
+VideoSchema.path('author').validate(customVideosValidators.isVideoAuthorValid)
+VideoSchema.path('duration').validate(customVideosValidators.isVideoDurationValid)
 // The tumbnail can be the path or the data in base 64
 // The pre save hook will convert the base 64 data in a file on disk and replace the thumbnail key by the filename
 VideoSchema.path('thumbnail').validate(function (value) {
-  return customValidators.isVideoThumbnailValid(value) || customValidators.isVideoThumbnail64Valid(value)
+  return customVideosValidators.isVideoThumbnailValid(value) || customVideosValidators.isVideoThumbnail64Valid(value)
 })
-VideoSchema.path('tags').validate(customValidators.isVideoTagsValid)
+VideoSchema.path('tags').validate(customVideosValidators.isVideoTagsValid)
 
 VideoSchema.methods = {
   isOwned: isOwned,
@@ -90,7 +91,7 @@ VideoSchema.pre('remove', function (next) {
     )
   }
 
-  async.parallel(tasks, next)
+  parallel(tasks, next)
 })
 
 VideoSchema.pre('save', function (next) {
@@ -110,7 +111,7 @@ VideoSchema.pre('save', function (next) {
       }
     )
 
-    async.parallel(tasks, function (err, results) {
+    parallel(tasks, function (err, results) {
       if (err) return next(err)
 
       video.magnetUri = results[0].magnetURI
@@ -234,7 +235,7 @@ function seedAllExisting (callback) {
   listOwned.call(this, function (err, videos) {
     if (err) return callback(err)
 
-    async.each(videos, function (video, callbackEach) {
+    eachLimit(videos, constants.SEEDS_IN_PARALLEL, function (video, callbackEach) {
       const videoPath = pathUtils.join(uploadsDir, video.filename)
       seed(videoPath, callbackEach)
     }, callback)
@@ -246,9 +247,9 @@ function seedAllExisting (callback) {
 function findWithCount (query, start, count, sort, callback) {
   const self = this
 
-  async.parallel([
+  parallel([
     function (asyncCallback) {
-      self.find(query).skip(start).limit(start + count).sort(sort).exec(asyncCallback)
+      self.find(query).skip(start).limit(count).sort(sort).exec(asyncCallback)
     },
     function (asyncCallback) {
       self.count(query, asyncCallback)