]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/lib/friends.js
Server: remote video validators refractoring
[github/Chocobozzz/PeerTube.git] / server / lib / friends.js
index 3d3d0fdeed1da06bb6f0cc37147a5b5f3a32f0a8..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
   }
@@ -54,7 +56,13 @@ function removeVideoToFriends (videoParams) {
 }
 
 function reportAbuseVideoToFriend (reportData, video) {
-  createRequest('report-abuse', constants.REQUEST_ENDPOINTS.VIDEOS, reportData, [ video.Author.podId ])
+  const options = {
+    type: ENDPOINT_ACTIONS.REPORT_ABUSE,
+    endpoint: constants.REQUEST_ENDPOINTS.VIDEOS,
+    data: reportData,
+    toIds: [ video.Author.podId ]
+  }
+  createRequest(options)
 }
 
 function hasFriends (callback) {
@@ -161,7 +169,13 @@ function sendOwnedVideosToPod (podId) {
           return
         }
 
-        createRequest('add', constants.REQUEST_ENDPOINTS.VIDEOS, remoteVideo, [ podId ])
+        const options = {
+          type: 'add',
+          endpoint: constants.REQUEST_ENDPOINTS.VIDEOS,
+          data: remoteVideo,
+          toIds: [ podId ]
+        }
+        createRequest(options)
       })
     })
   })