]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Server: remote video validators refractoring
authorChocobozzz <florian.bigard@gmail.com>
Tue, 17 Jan 2017 19:59:16 +0000 (20:59 +0100)
committerChocobozzz <florian.bigard@gmail.com>
Tue, 17 Jan 2017 19:59:16 +0000 (20:59 +0100)
server/controllers/api/videos.js
server/helpers/custom-validators/remote/videos.js
server/lib/friends.js

index 75a661bccd77eeead99dde093b4efa36ac558984..c936105e794d692c28d2ea35d0df50d8ec519149 100644 (file)
@@ -389,11 +389,7 @@ function reportVideoAbuse (req, res, finalCallback) {
 
   waterfall([
 
-    function startTransaction (callback) {
-      db.sequelize.transaction().asCallback(function (err, t) {
-        return callback(err, t)
-      })
-    },
+    databaseUtils.startSerializableTransaction,
 
     function createAbuse (t, callback) {
       db.VideoAbuse.create(abuse).asCallback(function (err, abuse) {
index 7c27b9dbb9d85bb36acd3cce2e5949f40ef08c5e..ee68ebc10d05b997141036bfa3e33608292ba612 100644 (file)
@@ -1,8 +1,11 @@
 'use strict'
 
+const constants = require('../../../initializers/constants')
 const videosValidators = require('../videos')
 const miscValidators = require('../misc')
 
+const ENDPOINT_ACTIONS = constants.REQUEST_ENDPOINT_ACTIONS[constants.REQUEST_ENDPOINTS.VIDEOS]
+
 const remoteVideosValidators = {
   isEachRemoteRequestVideosValid
 }
@@ -13,29 +16,13 @@ function isEachRemoteRequestVideosValid (requests) {
       const video = request.data
       return (
         isRequestTypeAddValid(request.type) &&
+        isCommonVideoAttrbiutesValid(video) &&
         videosValidators.isVideoAuthorValid(video.author) &&
-        videosValidators.isVideoDateValid(video.createdAt) &&
-        videosValidators.isVideoDateValid(video.updatedAt) &&
-        videosValidators.isVideoDescriptionValid(video.description) &&
-        videosValidators.isVideoDurationValid(video.duration) &&
-        videosValidators.isVideoInfoHashValid(video.infoHash) &&
-        videosValidators.isVideoNameValid(video.name) &&
-        videosValidators.isVideoTagsValid(video.tags) &&
-        videosValidators.isVideoThumbnailDataValid(video.thumbnailData) &&
-        videosValidators.isVideoRemoteIdValid(video.remoteId) &&
-        videosValidators.isVideoExtnameValid(video.extname)
+        videosValidators.isVideoThumbnailDataValid(video.thumbnailData)
       ) ||
       (
         isRequestTypeUpdateValid(request.type) &&
-        videosValidators.isVideoDateValid(video.createdAt) &&
-        videosValidators.isVideoDateValid(video.updatedAt) &&
-        videosValidators.isVideoDescriptionValid(video.description) &&
-        videosValidators.isVideoDurationValid(video.duration) &&
-        videosValidators.isVideoInfoHashValid(video.infoHash) &&
-        videosValidators.isVideoNameValid(video.name) &&
-        videosValidators.isVideoTagsValid(video.tags) &&
-        videosValidators.isVideoRemoteIdValid(video.remoteId) &&
-        videosValidators.isVideoExtnameValid(video.extname)
+        isCommonVideoAttrbiutesValid(video)
       ) ||
       (
         isRequestTypeRemoveValid(request.type) &&
@@ -56,18 +43,30 @@ module.exports = remoteVideosValidators
 
 // ---------------------------------------------------------------------------
 
+function isCommonVideoAttrbiutesValid (video) {
+  return videosValidators.isVideoDateValid(video.createdAt) &&
+         videosValidators.isVideoDateValid(video.updatedAt) &&
+         videosValidators.isVideoDescriptionValid(video.description) &&
+         videosValidators.isVideoDurationValid(video.duration) &&
+         videosValidators.isVideoInfoHashValid(video.infoHash) &&
+         videosValidators.isVideoNameValid(video.name) &&
+         videosValidators.isVideoTagsValid(video.tags) &&
+         videosValidators.isVideoRemoteIdValid(video.remoteId) &&
+         videosValidators.isVideoExtnameValid(video.extname)
+}
+
 function isRequestTypeAddValid (value) {
-  return value === 'add'
+  return value === ENDPOINT_ACTIONS.ADD
 }
 
 function isRequestTypeUpdateValid (value) {
-  return value === 'update'
+  return value === ENDPOINT_ACTIONS.UPDATE
 }
 
 function isRequestTypeRemoveValid (value) {
-  return value === 'remove'
+  return value === ENDPOINT_ACTIONS.REMOVE
 }
 
 function isRequestTypeReportAbuseValid (value) {
-  return value === 'report-abuse'
+  return value === ENDPOINT_ACTIONS.REPORT_ABUSE
 }
index f0575ff2fc0b34d2c433e157e5892099f961f48c..f634aedbb4c0b80150b17733cf75d631554a124f 100644 (file)
@@ -12,6 +12,8 @@ const db = require('../initializers/database')
 const logger = require('../helpers/logger')
 const requests = require('../helpers/requests')
 
+const ENDPOINT_ACTIONS = constants.REQUEST_ENDPOINT_ACTIONS[constants.REQUEST_ENDPOINTS.VIDEOS]
+
 const friends = {
   addVideoToFriends,
   updateVideoToFriends,
@@ -26,7 +28,7 @@ const friends = {
 
 function addVideoToFriends (videoData, transaction, callback) {
   const options = {
-    type: 'add',
+    type: ENDPOINT_ACTIONS.ADD,
     endpoint: constants.REQUEST_ENDPOINTS.VIDEOS,
     data: videoData,
     transaction
@@ -36,7 +38,7 @@ function addVideoToFriends (videoData, transaction, callback) {
 
 function updateVideoToFriends (videoData, transaction, callback) {
   const options = {
-    type: 'update',
+    type: ENDPOINT_ACTIONS.UPDATE,
     endpoint: constants.REQUEST_ENDPOINTS.VIDEOS,
     data: videoData,
     transaction
@@ -46,7 +48,7 @@ function updateVideoToFriends (videoData, transaction, callback) {
 
 function removeVideoToFriends (videoParams) {
   const options = {
-    type: 'remove',
+    type: ENDPOINT_ACTIONS.REMOVE,
     endpoint: constants.REQUEST_ENDPOINTS.VIDEOS,
     data: videoParams
   }
@@ -55,7 +57,7 @@ function removeVideoToFriends (videoParams) {
 
 function reportAbuseVideoToFriend (reportData, video) {
   const options = {
-    type: 'report-abuse',
+    type: ENDPOINT_ACTIONS.REPORT_ABUSE,
     endpoint: constants.REQUEST_ENDPOINTS.VIDEOS,
     data: reportData,
     toIds: [ video.Author.podId ]